├── .DS_Store ├── LSYReader ├── .DS_Store ├── LSYReader.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ ├── Labanotation.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── LiSiYuan.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── Labanotation.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ ├── LSYReader.xcscheme │ │ │ └── xcschememanagement.plist │ │ └── LiSiYuan.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── LSYReader.xcscheme │ │ └── xcschememanagement.plist ├── LSYReader │ ├── .DS_Store │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── LSYReader-Prefix.pch │ ├── Reader │ │ ├── .DS_Store │ │ ├── CatalogVC │ │ │ ├── LSYChapterVC.h │ │ │ ├── LSYChapterVC.m │ │ │ ├── LSYMarkVC.h │ │ │ ├── LSYMarkVC.m │ │ │ ├── LSYNoteVC.h │ │ │ └── LSYNoteVC.m │ │ ├── Core │ │ │ ├── .DS_Store │ │ │ ├── LSYReadConfig.h │ │ │ ├── LSYReadConfig.m │ │ │ ├── LSYReadParser.h │ │ │ ├── LSYReadParser.m │ │ │ ├── LSYReadUtilites.h │ │ │ └── LSYReadUtilites.m │ │ ├── LSYCatalogViewController.h │ │ ├── LSYCatalogViewController.m │ │ ├── LSYReadPageViewController.h │ │ ├── LSYReadPageViewController.m │ │ ├── LSYReadView.h │ │ ├── LSYReadView.m │ │ ├── LSYReadViewController.h │ │ ├── LSYReadViewController.m │ │ ├── Model │ │ │ ├── LSYChapterModel.h │ │ │ ├── LSYChapterModel.mm │ │ │ ├── LSYMarkModel.h │ │ │ ├── LSYMarkModel.m │ │ │ ├── LSYNoteModel.h │ │ │ ├── LSYNoteModel.m │ │ │ ├── LSYReadModel.h │ │ │ ├── LSYReadModel.m │ │ │ ├── LSYRecordModel.h │ │ │ └── LSYRecordModel.m │ │ ├── Resource │ │ │ ├── bg_back_white.png │ │ │ ├── bg_back_white@2x.png │ │ │ ├── ic_add.png │ │ │ ├── r_drag-dot@2x.png │ │ │ ├── reader_cover@2x.png │ │ │ ├── reader_more@2x.png │ │ │ ├── sale_discount_yellow.png │ │ │ └── 细说明朝.epub │ │ ├── Third │ │ │ ├── GTMDefines.h │ │ │ ├── GTMNSString+HTML.h │ │ │ ├── GTMNSString+HTML.m │ │ │ ├── LSYViewPagerVC.h │ │ │ ├── LSYViewPagerVC.m │ │ │ ├── NSString+HTML.h │ │ │ ├── NSString+HTML.m │ │ │ ├── TouchXML │ │ │ │ └── Source │ │ │ │ │ ├── CXHTMLDocument.h │ │ │ │ │ ├── CXHTMLDocument.m │ │ │ │ │ ├── CXMLDocument.h │ │ │ │ │ ├── CXMLDocument.m │ │ │ │ │ ├── CXMLDocument_PrivateExtensions.h │ │ │ │ │ ├── CXMLDocument_PrivateExtensions.m │ │ │ │ │ ├── CXMLElement.h │ │ │ │ │ ├── CXMLElement.m │ │ │ │ │ ├── CXMLElement_CreationExtensions.h │ │ │ │ │ ├── CXMLElement_CreationExtensions.m │ │ │ │ │ ├── CXMLElement_ElementTreeExtensions.h │ │ │ │ │ ├── CXMLElement_ElementTreeExtensions.m │ │ │ │ │ ├── CXMLNamespaceNode.h │ │ │ │ │ ├── CXMLNamespaceNode.m │ │ │ │ │ ├── CXMLNode.h │ │ │ │ │ ├── CXMLNode.m │ │ │ │ │ ├── CXMLNode_PrivateExtensions.h │ │ │ │ │ ├── CXMLNode_PrivateExtensions.m │ │ │ │ │ ├── CXMLNode_XPathExtensions.h │ │ │ │ │ ├── CXMLNode_XPathExtensions.m │ │ │ │ │ ├── CXMLUnsupportedNode.h │ │ │ │ │ ├── CXMLUnsupportedNode.m │ │ │ │ │ ├── Creation │ │ │ │ │ ├── CXMLDocument_CreationExtensions.h │ │ │ │ │ ├── CXMLDocument_CreationExtensions.m │ │ │ │ │ ├── CXMLNode_CreationExtensions.h │ │ │ │ │ └── CXMLNode_CreationExtensions.m │ │ │ │ │ ├── Tidy │ │ │ │ │ ├── CTidy.h │ │ │ │ │ └── CTidy.m │ │ │ │ │ └── TouchXML.h │ │ │ ├── UIImage+ImageEffects.h │ │ │ ├── UIImage+ImageEffects.m │ │ │ └── ZipArchive │ │ │ │ ├── ZipArchive.h │ │ │ │ ├── ZipArchive.mm │ │ │ │ └── minizip │ │ │ │ ├── crypt.h │ │ │ │ ├── ioapi.c │ │ │ │ ├── ioapi.h │ │ │ │ ├── mztools.c │ │ │ │ ├── mztools.h │ │ │ │ ├── unzip.c │ │ │ │ ├── unzip.h │ │ │ │ ├── zip.c │ │ │ │ └── zip.h │ │ └── View │ │ │ ├── LSYBottomMenuView.h │ │ │ ├── LSYBottomMenuView.m │ │ │ ├── LSYMagnifierView.h │ │ │ ├── LSYMagnifierView.m │ │ │ ├── LSYMenuView.h │ │ │ ├── LSYMenuView.m │ │ │ ├── LSYTopMenuView.h │ │ │ ├── LSYTopMenuView.m │ │ │ └── bt_tjcp_no@2x.png │ ├── ViewController.h │ ├── ViewController.m │ ├── main.m │ └── mdjyml.txt └── demo.gif └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/.DS_Store -------------------------------------------------------------------------------- /LSYReader/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/.DS_Store -------------------------------------------------------------------------------- /LSYReader/LSYReader.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LSYReader/LSYReader.xcodeproj/project.xcworkspace/xcuserdata/Labanotation.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader.xcodeproj/project.xcworkspace/xcuserdata/Labanotation.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LSYReader/LSYReader.xcodeproj/project.xcworkspace/xcuserdata/LiSiYuan.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader.xcodeproj/project.xcworkspace/xcuserdata/LiSiYuan.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LSYReader/LSYReader.xcodeproj/xcuserdata/Labanotation.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 40 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /LSYReader/LSYReader.xcodeproj/xcuserdata/Labanotation.xcuserdatad/xcschemes/LSYReader.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /LSYReader/LSYReader.xcodeproj/xcuserdata/Labanotation.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LSYReader.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | AB9A96B61CFC2EE70066030C 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LSYReader/LSYReader.xcodeproj/xcuserdata/LiSiYuan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /LSYReader/LSYReader.xcodeproj/xcuserdata/LiSiYuan.xcuserdatad/xcschemes/LSYReader.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /LSYReader/LSYReader.xcodeproj/xcuserdata/LiSiYuan.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LSYReader.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | AB9A96B61CFC2EE70066030C 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/.DS_Store -------------------------------------------------------------------------------- /LSYReader/LSYReader/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /LSYReader/LSYReader/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeRight 37 | UIInterfaceOrientationLandscapeLeft 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/LSYReader-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReader-Prefix.pch 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #ifndef LSYReader_Prefix_pch 10 | #define LSYReader_Prefix_pch 11 | 12 | // Include any system framework and library headers here that should be included in all compilation units. 13 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file. 14 | 15 | #endif /* LSYReader_Prefix_pch */ 16 | 17 | #ifdef __OBJC__ 18 | 19 | #import 20 | #import 21 | #import 22 | #define RGB(R, G, B) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1.0] 23 | #define TopSpacing 40.0f 24 | #define BottomSpacing 40.0f 25 | #define LeftSpacing 20.0f 26 | #define RightSpacing 20.0f 27 | #define DELAYEXECUTE(delayTime,func) (dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{func;})) 28 | #define DistanceFromTopGuiden(view) (view.frame.origin.y + view.frame.size.height) 29 | #define DistanceFromLeftGuiden(view) (view.frame.origin.x + view.frame.size.width) 30 | #define ViewOrigin(view) (view.frame.origin) 31 | #define ViewSize(view) (view.frame.size) 32 | #define ScreenSize [UIScreen mainScreen].bounds.size 33 | #import "LSYReadUtilites.h" 34 | #import "LSYReadModel.h" 35 | #import "LSYReadParser.h" 36 | 37 | #define LSYNoteNotification @"LSYNoteNotification" 38 | #define LSYThemeNotification @"LSYThemeNotification" 39 | #define LSYEditingNotification @"LSYEditingNotification" 40 | #define LSYEndEditNotification @"LSYEndEditNotification" 41 | 42 | #define MinFontSize 11.0f 43 | #define MaxFontSize 20.0f 44 | 45 | #endif 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/.DS_Store -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/CatalogVC/LSYChapterVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYChapterVC.h 3 | // LSYReader 4 | // 5 | // Created by okwei on 16/6/2. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LSYReadModel.h" 11 | @protocol LSYCatalogViewControllerDelegate; 12 | @interface LSYChapterVC : UIViewController 13 | @property (nonatomic,strong) LSYReadModel *readModel; 14 | @property (nonatomic,weak) iddelegate; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/CatalogVC/LSYChapterVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYChapterVC.m 3 | // LSYReader 4 | // 5 | // Created by okwei on 16/6/2. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYChapterVC.h" 10 | #import "LSYCatalogViewController.h" 11 | static NSString *chapterCell = @"chapterCell"; 12 | @interface LSYChapterVC () 13 | @property (nonatomic,strong) UITableView *tabView; 14 | @property (nonatomic) NSUInteger readChapter; 15 | @end 16 | 17 | @implementation LSYChapterVC 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | [self.view setBackgroundColor:[UIColor whiteColor]]; 22 | 23 | [self.view addSubview:self.tabView]; 24 | [self addObserver:self forKeyPath:@"readModel.record.chapter" options:NSKeyValueObservingOptionNew context:NULL]; 25 | } 26 | -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 27 | { 28 | [_tabView reloadData]; 29 | 30 | } 31 | -(UITableView *)tabView 32 | { 33 | if (!_tabView) { 34 | _tabView = [[UITableView alloc] init]; 35 | _tabView.delegate = self; 36 | _tabView.dataSource = self; 37 | _tabView.separatorStyle = UITableViewCellSeparatorStyleNone; 38 | } 39 | return _tabView; 40 | } 41 | #pragma mark - UITableView Delagete DataSource 42 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 43 | { 44 | return _readModel.chapters.count; 45 | } 46 | -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 47 | { 48 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:chapterCell]; 49 | if (!cell) { 50 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:chapterCell]; 51 | } 52 | cell.textLabel.text = _readModel.chapters[indexPath.row].title; 53 | if (indexPath.row == _readModel.record.chapter) { 54 | [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 55 | } 56 | return cell; 57 | } 58 | -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 59 | { 60 | return 44.0f; 61 | } 62 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 63 | { 64 | if ([self.delegate respondsToSelector:@selector(catalog:didSelectChapter:page:)]) { 65 | [self.delegate catalog:nil didSelectChapter:indexPath.row page:0]; 66 | } 67 | } 68 | -(void)dealloc 69 | { 70 | [self removeObserver:self forKeyPath:@"readModel.record.chapter"]; 71 | } 72 | -(void)viewDidLayoutSubviews 73 | { 74 | [super viewDidLayoutSubviews]; 75 | _tabView.frame = CGRectMake(0, 0, ViewSize(self.view).width, ViewSize(self.view).height); 76 | } 77 | 78 | /* 79 | #pragma mark - Navigation 80 | 81 | // In a storyboard-based application, you will often want to do a little preparation before navigation 82 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 83 | // Get the new view controller using [segue destinationViewController]. 84 | // Pass the selected object to the new view controller. 85 | } 86 | */ 87 | 88 | @end 89 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/CatalogVC/LSYMarkVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYMarkVC.h 3 | // LSYReader 4 | // 5 | // Created by okwei on 16/6/2. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LSYReadModel.h" 11 | @protocol LSYCatalogViewControllerDelegate; 12 | @interface LSYMarkVC : UIViewController 13 | @property (nonatomic,strong) LSYReadModel *readModel; 14 | @property (nonatomic,weak) iddelegate; 15 | @end 16 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/CatalogVC/LSYMarkVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYMarkVC.m 3 | // LSYReader 4 | // 5 | // Created by okwei on 16/6/2. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYMarkVC.h" 10 | #import "LSYCatalogViewController.h" 11 | static NSString *markCell = @"markCell"; 12 | @interface LSYMarkVC () 13 | @property (nonatomic,strong) UITableView *tabView; 14 | @end 15 | 16 | @implementation LSYMarkVC 17 | - (instancetype)init 18 | { 19 | self = [super init]; 20 | if (self) { 21 | [self addObserver:self forKeyPath:@"readModel.marks" options:NSKeyValueObservingOptionNew context:NULL]; 22 | } 23 | return self; 24 | } 25 | -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 26 | { 27 | [_tabView reloadData]; 28 | [LSYReadModel updateLocalModel:_readModel url:_readModel.resource]; //本地保存 29 | } 30 | - (void)viewDidLoad { 31 | [super viewDidLoad]; 32 | [self.view setBackgroundColor:[UIColor whiteColor]]; 33 | [self.view addSubview:self.tabView]; 34 | } 35 | 36 | -(UITableView *)tabView 37 | { 38 | if (!_tabView) { 39 | _tabView = [[UITableView alloc] init]; 40 | _tabView.delegate = self; 41 | _tabView.dataSource = self; 42 | _tabView.separatorStyle = UITableViewCellSeparatorStyleNone; 43 | } 44 | return _tabView; 45 | } 46 | #pragma mark - UITableView Delagete DataSource 47 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 48 | { 49 | return _readModel.marks.count; 50 | } 51 | -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 52 | { 53 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:markCell]; 54 | if (!cell) { 55 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:markCell]; 56 | } 57 | cell.textLabel.text = [_readModel.marks[indexPath.row].recordModel.chapterModel stringOfPage:_readModel.marks[indexPath.row].recordModel.page]; 58 | cell.detailTextLabel.text = _readModel.marks[indexPath.row].recordModel.chapterModel.title; 59 | return cell; 60 | } 61 | -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 62 | { 63 | return 44.0f; 64 | } 65 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 66 | { 67 | [tableView deselectRowAtIndexPath:indexPath animated:NO]; 68 | if ([self.delegate respondsToSelector:@selector(catalog:didSelectChapter:page:)]) { 69 | 70 | LSYMarkModel *selectedMarkModel = _readModel.marks[indexPath.row]; 71 | NSInteger chapter = selectedMarkModel.chapter; 72 | NSInteger page = [_readModel getPageIndexByOffset:selectedMarkModel.location Chapter:chapter]; 73 | 74 | [self.delegate catalog:nil didSelectChapter:chapter page:page]; 75 | } 76 | } 77 | -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 78 | { 79 | return YES; 80 | } 81 | -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 82 | { 83 | return UITableViewCellEditingStyleDelete; 84 | } 85 | -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 86 | { 87 | [_readModel.marks removeObjectAtIndex:indexPath.row]; 88 | [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight]; 89 | } 90 | -(void)dealloc 91 | { 92 | [self removeObserver:self forKeyPath:@"readModel.marks"]; 93 | } 94 | -(void)viewDidLayoutSubviews 95 | { 96 | [super viewDidLayoutSubviews]; 97 | _tabView.frame = CGRectMake(0, 0, ViewSize(self.view).width, ViewSize(self.view).height); 98 | } 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/CatalogVC/LSYNoteVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYNoteVC.h 3 | // LSYReader 4 | // 5 | // Created by okwei on 16/6/2. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LSYReadModel.h" 11 | @protocol LSYCatalogViewControllerDelegate; 12 | @interface LSYNoteVC : UIViewController 13 | @property (nonatomic,strong) LSYReadModel *readModel; 14 | @property (nonatomic,weak) iddelegate; 15 | @end 16 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/CatalogVC/LSYNoteVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYNoteVC.m 3 | // LSYReader 4 | // 5 | // Created by okwei on 16/6/2. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYNoteVC.h" 10 | #import "LSYCatalogViewController.h" 11 | static NSString *noteCell = @"noteCell"; 12 | @interface LSYNoteVC () 13 | @property (nonatomic,strong) UITableView *tabView; 14 | @end 15 | 16 | @implementation LSYNoteVC 17 | - (instancetype)init 18 | { 19 | self = [super init]; 20 | if (self) { 21 | [self addObserver:self forKeyPath:@"readModel.notes" options:NSKeyValueObservingOptionNew context:NULL]; 22 | } 23 | return self; 24 | } 25 | - (void)viewDidLoad { 26 | [super viewDidLoad]; 27 | [self.view setBackgroundColor:[UIColor whiteColor]]; 28 | [self.view addSubview:self.tabView]; 29 | 30 | } 31 | -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 32 | { 33 | [_tabView reloadData]; 34 | [LSYReadModel updateLocalModel:_readModel url:_readModel.resource]; //本地保存 35 | } 36 | -(UITableView *)tabView 37 | { 38 | if (!_tabView) { 39 | _tabView = [[UITableView alloc] init]; 40 | _tabView.delegate = self; 41 | _tabView.dataSource = self; 42 | _tabView.separatorStyle = UITableViewCellSeparatorStyleNone; 43 | } 44 | return _tabView; 45 | } 46 | #pragma mark - UITableView Delagete DataSource 47 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 48 | { 49 | return _readModel.notes.count; 50 | } 51 | -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 52 | { 53 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:noteCell]; 54 | if (!cell) { 55 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:noteCell]; 56 | } 57 | cell.textLabel.text = _readModel.notes[indexPath.row].content; 58 | cell.detailTextLabel.text = _readModel.notes[indexPath.row].note; 59 | 60 | return cell; 61 | } 62 | -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 63 | { 64 | return 44.0f; 65 | } 66 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 67 | { 68 | [tableView deselectRowAtIndexPath:indexPath animated:NO]; 69 | if ([self.delegate respondsToSelector:@selector(catalog:didSelectChapter:page:)]) { 70 | LSYNoteModel *selectedNoteModel = _readModel.notes[indexPath.row]; 71 | 72 | NSInteger chapter = selectedNoteModel.chapter; 73 | NSInteger page = [_readModel getPageIndexByOffset:selectedNoteModel.location Chapter:chapter]; 74 | 75 | [self.delegate catalog:nil didSelectChapter:chapter page:page]; 76 | } 77 | } 78 | -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 79 | { 80 | return YES; 81 | } 82 | -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 83 | { 84 | return UITableViewCellEditingStyleDelete; 85 | } 86 | -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 87 | { 88 | [_readModel.notes removeObjectAtIndex:indexPath.row]; 89 | [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight]; 90 | } 91 | -(void)dealloc 92 | { 93 | [self removeObserver:self forKeyPath:@"readModel.notes"]; 94 | } 95 | -(void)viewDidLayoutSubviews 96 | { 97 | [super viewDidLayoutSubviews]; 98 | _tabView.frame = CGRectMake(0, 0, ViewSize(self.view).width, ViewSize(self.view).height); 99 | } 100 | @end 101 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Core/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/Core/.DS_Store -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Core/LSYReadConfig.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadConfig.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LSYReadConfig : NSObject 12 | +(instancetype)shareInstance; 13 | @property (nonatomic) CGFloat fontSize; 14 | @property (nonatomic) CGFloat lineSpace; 15 | @property (nonatomic,strong) UIColor *fontColor; 16 | @property (nonatomic,strong) UIColor *theme; 17 | @end 18 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Core/LSYReadConfig.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadConfig.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYReadConfig.h" 10 | 11 | @implementation LSYReadConfig 12 | +(instancetype)shareInstance 13 | { 14 | static LSYReadConfig *readConfig = nil; 15 | static dispatch_once_t onceToken; 16 | dispatch_once(&onceToken, ^{ 17 | readConfig = [[self alloc] init]; 18 | 19 | }); 20 | return readConfig; 21 | } 22 | - (instancetype)init 23 | { 24 | self = [super init]; 25 | if (self) { 26 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"ReadConfig"]; 27 | if (data) { 28 | NSKeyedUnarchiver *unarchive = [[NSKeyedUnarchiver alloc]initForReadingWithData:data]; 29 | LSYReadConfig *config = [unarchive decodeObjectForKey:@"ReadConfig"]; 30 | [config addObserver:config forKeyPath:@"fontSize" options:NSKeyValueObservingOptionNew context:NULL]; 31 | [config addObserver:config forKeyPath:@"lineSpace" options:NSKeyValueObservingOptionNew context:NULL]; 32 | [config addObserver:config forKeyPath:@"fontColor" options:NSKeyValueObservingOptionNew context:NULL]; 33 | [config addObserver:config forKeyPath:@"theme" options:NSKeyValueObservingOptionNew context:NULL]; 34 | return config; 35 | } 36 | _lineSpace = 10.0f; 37 | _fontSize = 14.0f; 38 | _fontColor = [UIColor blackColor]; 39 | _theme = [UIColor whiteColor]; 40 | [self addObserver:self forKeyPath:@"fontSize" options:NSKeyValueObservingOptionNew context:NULL]; 41 | [self addObserver:self forKeyPath:@"lineSpace" options:NSKeyValueObservingOptionNew context:NULL]; 42 | [self addObserver:self forKeyPath:@"fontColor" options:NSKeyValueObservingOptionNew context:NULL]; 43 | [self addObserver:self forKeyPath:@"theme" options:NSKeyValueObservingOptionNew context:NULL]; 44 | [LSYReadConfig updateLocalConfig:self]; 45 | 46 | } 47 | return self; 48 | } 49 | 50 | -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 51 | { 52 | [LSYReadConfig updateLocalConfig:self]; 53 | } 54 | +(void)updateLocalConfig:(LSYReadConfig *)config 55 | { 56 | NSMutableData *data=[[NSMutableData alloc]init]; 57 | NSKeyedArchiver *archiver=[[NSKeyedArchiver alloc]initForWritingWithMutableData:data]; 58 | [archiver encodeObject:config forKey:@"ReadConfig"]; 59 | [archiver finishEncoding]; 60 | [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"ReadConfig"]; 61 | } 62 | -(void)encodeWithCoder:(NSCoder *)aCoder 63 | { 64 | [aCoder encodeDouble:self.fontSize forKey:@"fontSize"]; 65 | [aCoder encodeDouble:self.lineSpace forKey:@"lineSpace"]; 66 | [aCoder encodeObject:self.fontColor forKey:@"fontColor"]; 67 | [aCoder encodeObject:self.theme forKey:@"theme"]; 68 | } 69 | -(id)initWithCoder:(NSCoder *)aDecoder 70 | { 71 | self = [super init]; 72 | if (self) { 73 | self.fontSize = [aDecoder decodeDoubleForKey:@"fontSize"]; 74 | self.lineSpace = [aDecoder decodeDoubleForKey:@"lineSpace"]; 75 | self.fontColor = [aDecoder decodeObjectForKey:@"fontColor"]; 76 | self.theme = [aDecoder decodeObjectForKey:@"theme"]; 77 | } 78 | return self; 79 | } 80 | @end 81 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Core/LSYReadParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadParser.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LSYReadConfig.h" 11 | @interface LSYReadParser : NSObject 12 | +(CTFrameRef)parserContent:(NSString *)content config:(LSYReadConfig *)parser bouds:(CGRect)bounds; 13 | +(NSDictionary *)parserAttribute:(LSYReadConfig *)config; 14 | //根据触碰点获取当前文字的索引 15 | +(CFIndex)parserIndexWithPoint:(CGPoint)point frameRef:(CTFrameRef)frameRef; 16 | /** 17 | * 根据触碰点获取默认选中区域 18 | * @range 选中范围 19 | * @return 选中区域 20 | */ 21 | +(CGRect)parserRectWithPoint:(CGPoint)point range:(NSRange *)selectRange frameRef:(CTFrameRef)frameRef; 22 | /** 23 | * 根据触碰点获取默认选中区域 24 | * @range 选中范围 25 | * @return 选中区域的集合 26 | */ 27 | +(NSArray *)parserRectsWithPoint:(CGPoint)point range:(NSRange *)selectRange frameRef:(CTFrameRef)frameRef paths:(NSArray *)paths; 28 | /** 29 | * 根据触碰点获取默认选中区域 30 | * @range 选中范围 31 | * @return 选中区域的集合 32 | * @direction 滑动方向 (0 -- 从左侧滑动 1-- 从右侧滑动) 33 | */ 34 | +(NSArray *)parserRectsWithPoint:(CGPoint)point range:(NSRange *)selectRange frameRef:(CTFrameRef)frameRef paths:(NSArray *)paths direction:(BOOL) direction; 35 | @end 36 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Core/LSYReadUtilites.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadUtilites.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface LSYReadUtilites : NSObject 12 | +(void)separateChapter:(NSMutableArray **)chapters content:(NSString *)content; 13 | +(NSString *)encodeWithURL:(NSURL *)url; 14 | +(UIButton *)commonButtonSEL:(SEL)sel target:(id)target; 15 | +(UIViewController *)getCurrentVC; 16 | +(void)showAlertTitle:(NSString *)title content:(NSString *)string; 17 | /** 18 | * ePub格式处理 19 | * 返回章节信息数组 20 | */ 21 | +(NSMutableArray *)ePubFileHandle:(NSString *)path; 22 | @end 23 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Core/LSYReadUtilites.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadUtilites.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYReadUtilites.h" 10 | #import "LSYChapterModel.h" 11 | #import "ZipArchive.h" 12 | #import "TouchXML.h" 13 | @implementation LSYReadUtilites 14 | +(void)separateChapter:(NSMutableArray **)chapters content:(NSString *)content 15 | { 16 | [*chapters removeAllObjects]; 17 | NSString *parten = @"第[0-9一二三四五六七八九十百千]*[章回].*"; 18 | NSError* error = NULL; 19 | NSRegularExpression *reg = [NSRegularExpression regularExpressionWithPattern:parten options:NSRegularExpressionCaseInsensitive error:&error]; 20 | 21 | NSArray* match = [reg matchesInString:content options:NSMatchingReportCompletion range:NSMakeRange(0, [content length])]; 22 | 23 | if (match.count != 0) 24 | { 25 | __block NSRange lastRange = NSMakeRange(0, 0); 26 | [match enumerateObjectsUsingBlock:^(NSTextCheckingResult * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 27 | NSRange range = [obj range]; 28 | NSInteger local = range.location; 29 | if (idx == 0) { 30 | LSYChapterModel *model = [[LSYChapterModel alloc] init]; 31 | model.title = @"开始"; 32 | NSUInteger len = local; 33 | model.content = [content substringWithRange:NSMakeRange(0, len)]; 34 | [*chapters addObject:model]; 35 | 36 | } 37 | if (idx > 0 ) { 38 | LSYChapterModel *model = [[LSYChapterModel alloc] init]; 39 | model.title = [content substringWithRange:lastRange]; 40 | NSUInteger len = local-lastRange.location; 41 | model.content = [content substringWithRange:NSMakeRange(lastRange.location, len)]; 42 | [*chapters addObject:model]; 43 | 44 | } 45 | if (idx == match.count-1) { 46 | LSYChapterModel *model = [[LSYChapterModel alloc] init]; 47 | model.title = [content substringWithRange:range]; 48 | model.content = [content substringWithRange:NSMakeRange(local, content.length-local)]; 49 | [*chapters addObject:model]; 50 | } 51 | lastRange = range; 52 | }]; 53 | } 54 | else{ 55 | LSYChapterModel *model = [[LSYChapterModel alloc] init]; 56 | model.content = content; 57 | [*chapters addObject:model]; 58 | } 59 | 60 | } 61 | +(NSString *)encodeWithURL:(NSURL *)url 62 | { 63 | if (!url) { 64 | return @""; 65 | } 66 | NSString *content = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; 67 | if (!content) { 68 | content = [NSString stringWithContentsOfURL:url encoding:0x80000632 error:nil]; 69 | } 70 | if (!content) { 71 | content = [NSString stringWithContentsOfURL:url encoding:0x80000631 error:nil]; 72 | } 73 | if (!content) { 74 | return @""; 75 | } 76 | return content; 77 | 78 | } 79 | +(UIButton *)commonButtonSEL:(SEL)sel target:(id)target 80 | { 81 | UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; 82 | [button.titleLabel setFont:[UIFont systemFontOfSize:12]]; 83 | [button setTintColor:[UIColor whiteColor]]; 84 | [button addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside]; 85 | return button; 86 | } 87 | +(UIViewController *)getCurrentVC 88 | { 89 | UIViewController *result = nil; 90 | 91 | 92 | UIWindow * window = [[UIApplication sharedApplication] keyWindow]; 93 | if (window.windowLevel != UIWindowLevelNormal) 94 | { 95 | NSArray *windows = [[UIApplication sharedApplication] windows]; 96 | for(UIWindow * tmpWin in windows) 97 | { 98 | if (tmpWin.windowLevel == UIWindowLevelNormal) 99 | { 100 | window = tmpWin; 101 | break; 102 | } 103 | } 104 | } 105 | 106 | 107 | UIView *frontView = [[window subviews] objectAtIndex:0]; 108 | id nextResponder = [frontView nextResponder]; 109 | 110 | 111 | if ([nextResponder isKindOfClass:[UIViewController class]]) 112 | result = nextResponder; 113 | else 114 | result = window.rootViewController; 115 | 116 | return result; 117 | } 118 | +(void)showAlertTitle:(NSString *)title content:(NSString *)string 119 | { 120 | #pragma clang diagnostic push 121 | #pragma clang diagnostic ignored"-Wdeprecated-declarations" 122 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:string delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 123 | [alert show]; 124 | #pragma clang diagnostic pop 125 | 126 | } 127 | #pragma mark - ePub处理 128 | +(NSMutableArray *)ePubFileHandle:(NSString *)path; 129 | { 130 | NSString *ePubPath = [self unZip:path]; 131 | if (!ePubPath) { 132 | return nil; 133 | } 134 | NSString *OPFPath = [self OPFPath:ePubPath]; 135 | return [self parseOPF:OPFPath]; 136 | 137 | } 138 | #pragma mark - 解压文件路径 139 | +(NSString *)unZip:(NSString *)path 140 | { 141 | ZipArchive *zip = [[ZipArchive alloc] init]; 142 | NSString *zipFile = [[path stringByDeletingPathExtension] lastPathComponent]; 143 | if ([zip UnzipOpenFile:path]) { 144 | NSString *zipPath = [NSString stringWithFormat:@"%@/%@",NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject,zipFile]; 145 | NSFileManager *filemanager=[[NSFileManager alloc] init]; 146 | if ([filemanager fileExistsAtPath:zipPath]) { 147 | NSError *error; 148 | [filemanager removeItemAtPath:zipPath error:&error]; 149 | } 150 | if ([zip UnzipFileTo:[NSString stringWithFormat:@"%@/",zipPath] overWrite:YES]) { 151 | return zipPath; 152 | } 153 | } 154 | return nil; 155 | } 156 | #pragma mark - OPF文件路径 157 | +(NSString *)OPFPath:(NSString *)epubPath 158 | { 159 | NSString *containerPath = [NSString stringWithFormat:@"%@/META-INF/container.xml",epubPath]; 160 | //container.xml文件路径 通过container.xml获取到opf文件的路径 161 | NSFileManager *fileManager = [[NSFileManager alloc] init]; 162 | if ([fileManager fileExistsAtPath:containerPath]) { 163 | CXMLDocument* document = [[CXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:containerPath] options:0 error:nil]; 164 | CXMLNode* opfPath = [document nodeForXPath:@"//@full-path" error:nil]; 165 | // xml文件中获取full-path属性的节点 full-path的属性值就是opf文件的绝对路径 166 | return [NSString stringWithFormat:@"%@/%@",epubPath,[opfPath stringValue]]; 167 | } else { 168 | NSLog(@"ERROR: ePub not Valid"); 169 | return nil; 170 | } 171 | 172 | } 173 | #pragma mark - 解析OPF文件 174 | +(NSMutableArray *)parseOPF:(NSString *)opfPath 175 | { 176 | CXMLDocument* document = [[CXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:opfPath] options:0 error:nil]; 177 | NSArray* itemsArray = [document nodesForXPath:@"//opf:item" namespaceMappings:[NSDictionary dictionaryWithObject:@"http://www.idpf.org/2007/opf" forKey:@"opf"] error:nil]; 178 | //opf文件的命名空间 xmlns="http://www.idpf.org/2007/opf" 需要取到某个节点设置命名空间的键为opf 用opf:节点来获取节点 179 | NSString *ncxFile; 180 | NSMutableDictionary* itemDictionary = [[NSMutableDictionary alloc] init]; 181 | for (CXMLElement* element in itemsArray){ 182 | [itemDictionary setValue:[[element attributeForName:@"href"] stringValue] forKey:[[element attributeForName:@"id"] stringValue]]; 183 | if([[[element attributeForName:@"media-type"] stringValue] isEqualToString:@"application/x-dtbncx+xml"]){ 184 | ncxFile = [[element attributeForName:@"href"] stringValue]; //获取ncx文件名称 根据ncx获取书的目录 185 | 186 | } 187 | } 188 | 189 | NSString *absolutePath = [opfPath stringByDeletingLastPathComponent]; 190 | CXMLDocument *ncxDoc = [[CXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", absolutePath,ncxFile]] options:0 error:nil]; 191 | NSMutableDictionary* titleDictionary = [[NSMutableDictionary alloc] init]; 192 | for (CXMLElement* element in itemsArray) { 193 | NSString* href = [[element attributeForName:@"href"] stringValue]; 194 | NSString* xpath = [NSString stringWithFormat:@"//ncx:content[@src='%@']/../ncx:navLabel/ncx:text", href]; 195 | //根据opf文件的href获取到ncx文件中的中对应的目录名称 196 | NSArray* navPoints = [ncxDoc nodesForXPath:xpath namespaceMappings:[NSDictionary dictionaryWithObject:@"http://www.daisy.org/z3986/2005/ncx/" forKey:@"ncx"] error:nil]; 197 | if([navPoints count]!=0){ 198 | CXMLElement* titleElement = navPoints.firstObject; 199 | [titleDictionary setValue:[titleElement stringValue] forKey:href]; 200 | } 201 | } 202 | NSArray* itemRefsArray = [document nodesForXPath:@"//opf:itemref" namespaceMappings:[NSDictionary dictionaryWithObject:@"http://www.idpf.org/2007/opf" forKey:@"opf"] error:nil]; 203 | NSMutableArray *chapters = [NSMutableArray array]; 204 | for (CXMLElement* element in itemRefsArray){ 205 | NSString* chapHref = [itemDictionary valueForKey:[[element attributeForName:@"idref"] stringValue]]; 206 | LSYChapterModel *model = [LSYChapterModel chapterWithEpub:[NSString stringWithFormat:@"%@/%@",absolutePath,chapHref] title:[titleDictionary valueForKey:chapHref]]; 207 | [chapters addObject:model]; 208 | 209 | } 210 | return chapters; 211 | } 212 | @end 213 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/LSYCatalogViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYCatalogViewController.h 3 | // LSYReader 4 | // 5 | // Created by okwei on 16/6/2. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYViewPagerVC.h" 10 | @class LSYCatalogViewController; 11 | @protocol LSYCatalogViewControllerDelegate 12 | @optional 13 | -(void)catalog:(LSYCatalogViewController *)catalog didSelectChapter:(NSUInteger)chapter page:(NSUInteger)page; 14 | @end 15 | @interface LSYCatalogViewController : LSYViewPagerVC 16 | @property (nonatomic,strong) LSYReadModel *readModel; 17 | @property (nonatomic,weak) idcatalogDelegate; 18 | @end 19 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/LSYCatalogViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYCatalogViewController.m 3 | // LSYReader 4 | // 5 | // Created by okwei on 16/6/2. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYCatalogViewController.h" 10 | #import "LSYChapterVC.h" 11 | #import "LSYNoteVC.h" 12 | #import "LSYMarkVC.h" 13 | @interface LSYCatalogViewController () 14 | @property (nonatomic,copy) NSArray *titleArray; 15 | @property (nonatomic,copy) NSArray *VCArray; 16 | @end 17 | 18 | @implementation LSYCatalogViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | _titleArray = @[@"目录",@"笔记",@"书签"]; 23 | _VCArray = @[({ 24 | LSYChapterVC *chapterVC = [[LSYChapterVC alloc]init]; 25 | chapterVC.readModel = _readModel; 26 | chapterVC.delegate = self; 27 | chapterVC; 28 | }),({ 29 | LSYNoteVC *noteVC = [[LSYNoteVC alloc] init]; 30 | noteVC.readModel = _readModel; 31 | noteVC.delegate = self; 32 | noteVC; 33 | }),({ 34 | LSYMarkVC *markVC =[[LSYMarkVC alloc] init]; 35 | markVC.readModel = _readModel; 36 | markVC.delegate = self; 37 | markVC; 38 | })]; 39 | self.forbidGesture = YES; 40 | self.delegate = self; 41 | self.dataSource = self; 42 | } 43 | 44 | -(NSInteger)numberOfViewControllersInViewPager:(LSYViewPagerVC *)viewPager 45 | { 46 | return _titleArray.count; 47 | } 48 | -(UIViewController *)viewPager:(LSYViewPagerVC *)viewPager indexOfViewControllers:(NSInteger)index 49 | { 50 | return _VCArray[index]; 51 | } 52 | -(NSString *)viewPager:(LSYViewPagerVC *)viewPager titleWithIndexOfViewControllers:(NSInteger)index 53 | { 54 | return _titleArray[index]; 55 | } 56 | -(CGFloat)heightForTitleOfViewPager:(LSYViewPagerVC *)viewPager 57 | { 58 | return 40.0f; 59 | } 60 | -(void)catalog:(LSYCatalogViewController *)catalog didSelectChapter:(NSUInteger)chapter page:(NSUInteger)page 61 | { 62 | if ([self.catalogDelegate respondsToSelector:@selector(catalog:didSelectChapter:page:)]) { 63 | [self.catalogDelegate catalog:self didSelectChapter:chapter page:page]; 64 | } 65 | } 66 | /* 67 | #pragma mark - Navigation 68 | 69 | // In a storyboard-based application, you will often want to do a little preparation before navigation 70 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 71 | // Get the new view controller using [segue destinationViewController]. 72 | // Pass the selected object to the new view controller. 73 | } 74 | */ 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/LSYReadPageViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadPageViewController.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LSYReadModel.h" 11 | @interface LSYReadPageViewController : UIViewController 12 | @property (nonatomic,strong) NSURL *resourceURL; 13 | @property (nonatomic,strong) LSYReadModel *model; 14 | //+(void)loadURL:(NSURL *)url; 15 | @end 16 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/LSYReadView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadView.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | @protocol LSYReadViewControllerDelegate; 11 | @interface LSYReadView : UIView 12 | @property (nonatomic,assign) CTFrameRef frameRef; 13 | @property (nonatomic,strong) NSString *content; 14 | @property (nonatomic,strong) iddelegate; 15 | -(void)cancelSelected; 16 | @end 17 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/LSYReadViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadViewController.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LSYRecordModel.h" 11 | #import "LSYReadView.h" 12 | @class LSYReadViewController; 13 | @protocol LSYReadViewControllerDelegate 14 | -(void)readViewEditeding:(LSYReadViewController *)readView; 15 | -(void)readViewEndEdit:(LSYReadViewController *)readView; 16 | @end 17 | @interface LSYReadViewController : UIViewController 18 | @property (nonatomic,strong) NSString *content; //显示的内容 19 | @property (nonatomic,strong) LSYRecordModel *recordModel; //阅读进度 20 | @property (nonatomic,strong) LSYReadView *readView; 21 | @property (nonatomic,weak) iddelegate; 22 | @end 23 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/LSYReadViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadViewController.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYReadViewController.h" 10 | 11 | #import "LSYReadParser.h" 12 | #import "LSYReadConfig.h" 13 | 14 | 15 | @interface LSYReadViewController () 16 | 17 | @end 18 | 19 | @implementation LSYReadViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | [self prefersStatusBarHidden]; 24 | [self.view setBackgroundColor:[LSYReadConfig shareInstance].theme]; 25 | [self.view addSubview:self.readView]; 26 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheme:) name:LSYThemeNotification object:nil]; 27 | } 28 | -(void)changeTheme:(NSNotification *)no 29 | { 30 | [LSYReadConfig shareInstance].theme = no.object; 31 | [self.view setBackgroundColor:[LSYReadConfig shareInstance].theme]; 32 | } 33 | -(LSYReadView *)readView 34 | { 35 | if (!_readView) { 36 | _readView = [[LSYReadView alloc] initWithFrame:CGRectMake(LeftSpacing,TopSpacing, self.view.frame.size.width-LeftSpacing-RightSpacing, self.view.frame.size.height-TopSpacing-BottomSpacing)]; 37 | LSYReadConfig *config = [LSYReadConfig shareInstance]; 38 | _readView.frameRef = [LSYReadParser parserContent:_content config:config bouds:CGRectMake(0,0, _readView.frame.size.width, _readView.frame.size.height)]; 39 | _readView.content = _content; 40 | _readView.delegate = self; 41 | } 42 | return _readView; 43 | } 44 | -(void)readViewEditeding:(LSYReadViewController *)readView 45 | { 46 | if ([self.delegate respondsToSelector:@selector(readViewEditeding:)]) { 47 | [self.delegate readViewEditeding:self]; 48 | } 49 | } 50 | -(void)readViewEndEdit:(LSYReadViewController *)readView 51 | { 52 | if ([self.delegate respondsToSelector:@selector(readViewEndEdit:)]) { 53 | [self.delegate readViewEndEdit:self]; 54 | } 55 | } 56 | 57 | -(void)dealloc 58 | { 59 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 60 | } 61 | -(void)viewDidLayoutSubviews 62 | { 63 | [super viewDidLayoutSubviews]; 64 | } 65 | 66 | /* 67 | #pragma mark - Navigation 68 | 69 | // In a storyboard-based application, you will often want to do a little preparation before navigation 70 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 71 | // Get the new view controller using [segue destinationViewController]. 72 | // Pass the selected object to the new view controller. 73 | } 74 | */ 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Model/LSYChapterModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYChapterModel.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface LSYChapterModel : NSObject 13 | @property (nonatomic,strong) NSMutableArray *pageArray; 14 | @property (nonatomic,strong) NSString *content; 15 | @property (nonatomic,strong) NSString *title; 16 | @property (nonatomic,assign) NSUInteger chapterIndex; 17 | @property (nonatomic) NSUInteger pageCount; 18 | -(NSString *)stringOfPage:(NSUInteger)index; 19 | -(void)updateFont; 20 | +(id)chapterWithEpub:(NSString *)chapterpath title:(NSString *)title; 21 | @end 22 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Model/LSYChapterModel.mm: -------------------------------------------------------------------------------- 1 | // 2 | // LSYChapterModel.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYChapterModel.h" 10 | #import "LSYReadConfig.h" 11 | #import "LSYReadParser.h" 12 | #import "NSString+HTML.h" 13 | #include 14 | @interface LSYChapterModel () 15 | 16 | @end 17 | 18 | @implementation LSYChapterModel 19 | - (instancetype)init 20 | { 21 | self = [super init]; 22 | if (self) { 23 | _pageArray = [NSMutableArray array]; 24 | } 25 | return self; 26 | } 27 | +(id)chapterWithEpub:(NSString *)chapterpath title:(NSString *)title 28 | { 29 | LSYChapterModel *model = [[LSYChapterModel alloc] init]; 30 | model.title = title; 31 | NSString* html = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:chapterpath]] encoding:NSUTF8StringEncoding]; 32 | model.content = [html stringByConvertingHTMLToPlainText]; 33 | return model; 34 | } 35 | -(id)copyWithZone:(NSZone *)zone 36 | { 37 | LSYChapterModel *model = [[LSYChapterModel allocWithZone:zone] init]; 38 | model.content = self.content; 39 | model.title = self.title; 40 | model.pageCount = self.pageCount; 41 | return model; 42 | 43 | } 44 | -(void)setContent:(NSString *)content 45 | { 46 | _content = content; 47 | [self paginateWithBounds:CGRectMake(LeftSpacing, TopSpacing, [UIScreen mainScreen].bounds.size.width-LeftSpacing-RightSpacing, [UIScreen mainScreen].bounds.size.height-TopSpacing-BottomSpacing)]; 48 | } 49 | -(void)updateFont 50 | { 51 | [self paginateWithBounds:CGRectMake(LeftSpacing, TopSpacing, [UIScreen mainScreen].bounds.size.width-LeftSpacing-RightSpacing, [UIScreen mainScreen].bounds.size.height-TopSpacing-BottomSpacing)]; 52 | } 53 | -(void)paginateWithBounds:(CGRect)bounds 54 | { 55 | // _pages.clear(); 56 | [_pageArray removeAllObjects]; 57 | NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:self.content]; 58 | NSDictionary *attribute = [LSYReadParser parserAttribute:[LSYReadConfig shareInstance]]; 59 | [attrString setAttributes:attribute range:NSMakeRange(0, attrString.length)]; 60 | 61 | CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef) attrString); 62 | CGPathRef path = CGPathCreateWithRect(bounds, NULL); 63 | int currentOffset = 0; 64 | int currentInnerOffset = 0; 65 | BOOL hasMorePages = YES; 66 | // 防止死循环,如果在同一个位置获取CTFrame超过2次,则跳出循环 67 | int preventDeadLoopSign = currentOffset; 68 | int samePlaceRepeatCount = 0; 69 | 70 | while (hasMorePages) { 71 | if (preventDeadLoopSign == currentOffset) { 72 | 73 | ++samePlaceRepeatCount; 74 | 75 | } else { 76 | 77 | samePlaceRepeatCount = 0; 78 | } 79 | 80 | if (samePlaceRepeatCount > 1) { 81 | // 退出循环前检查一下最后一页是否已经加上 82 | // if (_pages.size() == 0) { 83 | // 84 | // _pages.push_back(currentOffset); 85 | // 86 | // } 87 | if (_pageArray.count == 0) { 88 | [_pageArray addObject:@(currentOffset)]; 89 | } 90 | else { 91 | 92 | // NSUInteger lastOffset = _pages.back(); 93 | NSUInteger lastOffset = [[_pageArray lastObject] integerValue]; 94 | 95 | if (lastOffset != currentOffset) { 96 | 97 | // _pages.push_back(currentOffset); 98 | [_pageArray addObject:@(currentOffset)]; 99 | } 100 | } 101 | break; 102 | } 103 | 104 | // _pages.push_back(currentOffset); 105 | [_pageArray addObject:@(currentOffset)]; 106 | 107 | CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(currentInnerOffset, 0), path, NULL); 108 | CFRange range = CTFrameGetVisibleStringRange(frame); 109 | 110 | if ((range.location + range.length) != attrString.length) { 111 | 112 | currentOffset += range.length; 113 | currentInnerOffset += range.length; 114 | 115 | } else { 116 | // 已经分完,提示跳出循环 117 | hasMorePages = NO; 118 | } 119 | if (frame) CFRelease(frame); 120 | } 121 | 122 | CGPathRelease(path); 123 | CFRelease(frameSetter); 124 | // _pageCount = _pages.size(); 125 | _pageCount = _pageArray.count; 126 | } 127 | -(NSString *)stringOfPage:(NSUInteger)index 128 | { 129 | // NSUInteger local = _pages[index]; 130 | NSUInteger local = [_pageArray[index] integerValue]; 131 | NSUInteger length; 132 | if (index 10 | #import "LSYRecordModel.h" 11 | @interface LSYMarkModel : NSObject 12 | @property (nonatomic,strong) NSDate *date; 13 | @property (nonatomic,assign) NSUInteger location; 14 | @property (nonatomic,assign) NSUInteger length; 15 | @property (nonatomic,assign) NSUInteger chapter; 16 | @property (nonatomic,strong) LSYRecordModel *recordModel; 17 | @end 18 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Model/LSYMarkModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYMarkModel.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYMarkModel.h" 10 | 11 | @implementation LSYMarkModel 12 | /*** 13 | 14 | @property (nonatomic,strong) NSDate *date; 15 | @property (nonatomic,strong) LSYRecordModel *recordModel; 16 | */ 17 | -(void)encodeWithCoder:(NSCoder *)aCoder{ 18 | [aCoder encodeObject:self.date forKey:@"date"]; 19 | [aCoder encodeObject:@(self.location) forKey:@"location"]; 20 | [aCoder encodeObject:@(self.length) forKey:@"length"]; 21 | [aCoder encodeObject:@(self.chapter) forKey:@"chapter"]; 22 | [aCoder encodeObject:self.recordModel forKey:@"recordModel"]; 23 | } 24 | -(id)initWithCoder:(NSCoder *)aDecoder{ 25 | self = [super init]; 26 | if (self) { 27 | self.date = [aDecoder decodeObjectForKey:@"date"]; 28 | self.location = [[aDecoder decodeObjectForKey:@"location"] integerValue]; 29 | self.length = [[aDecoder decodeObjectForKey:@"length"] integerValue]; 30 | self.chapter = [[aDecoder decodeObjectForKey:@"chapter"] integerValue]; 31 | self.recordModel = [aDecoder decodeObjectForKey:@"recordModel"]; 32 | } 33 | return self; 34 | } 35 | @end 36 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Model/LSYNoteModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYNoteModel.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LSYRecordModel.h" 11 | @interface LSYNoteModel : NSObject 12 | @property (nonatomic,strong) NSDate *date; 13 | @property (nonatomic,copy) NSString *note; 14 | @property (nonatomic,copy) NSString *content; 15 | @property (nonatomic,assign) NSUInteger location; 16 | @property (nonatomic,assign) NSUInteger length; 17 | @property (nonatomic,assign) NSUInteger chapter; 18 | @property (nonatomic,strong) LSYRecordModel *recordModel; 19 | @end 20 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Model/LSYNoteModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYNoteModel.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYNoteModel.h" 10 | 11 | @implementation LSYNoteModel 12 | -(void)encodeWithCoder:(NSCoder *)aCoder{ 13 | [aCoder encodeObject:self.date forKey:@"date"]; 14 | [aCoder encodeObject:self.note forKey:@"note"]; 15 | [aCoder encodeObject:self.content forKey:@"content"]; 16 | [aCoder encodeObject:@(self.location) forKey:@"location"]; 17 | [aCoder encodeObject:@(self.length) forKey:@"length"]; 18 | [aCoder encodeObject:@(self.chapter) forKey:@"chapter"]; 19 | [aCoder encodeObject:self.recordModel forKey:@"recordModel"]; 20 | } 21 | 22 | -(id)initWithCoder:(NSCoder *)aDecoder{ 23 | self = [super init]; 24 | if (self) { 25 | self.date = [aDecoder decodeObjectForKey:@"date"]; 26 | self.note = [aDecoder decodeObjectForKey:@"note"]; 27 | self.content = [aDecoder decodeObjectForKey:@"content"]; 28 | self.location = [[aDecoder decodeObjectForKey:@"location"] integerValue]; 29 | self.length = [[aDecoder decodeObjectForKey:@"length"] integerValue]; 30 | self.chapter = [[aDecoder decodeObjectForKey:@"chapter"] integerValue]; 31 | self.recordModel = [aDecoder decodeObjectForKey:@"recordModel"]; 32 | } 33 | return self; 34 | } 35 | @end 36 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Model/LSYReadModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadModel.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LSYMarkModel.h" 11 | #import "LSYNoteModel.h" 12 | #import "LSYChapterModel.h" 13 | #import "LSYRecordModel.h" 14 | @interface LSYReadModel : NSObject 15 | @property (nonatomic,strong) NSURL *resource; 16 | @property (nonatomic,copy) NSString *content; 17 | @property (nonatomic,strong) NSMutableArray *marks; 18 | @property (nonatomic,strong) NSMutableArray *notes; 19 | @property (nonatomic,strong) NSMutableArray *chapters; 20 | @property (nonatomic,strong) NSMutableDictionary *marksRecord; 21 | @property (nonatomic,strong) LSYRecordModel *record; 22 | @property (nonatomic,strong) NSNumber *font; 23 | -(instancetype)initWithContent:(NSString *)content; 24 | -(instancetype)initWithePub:(NSString *)ePubPath; 25 | -(NSUInteger)getPageIndexByOffset:(NSUInteger)offset Chapter:(NSUInteger)chapterIndex; 26 | +(void)updateLocalModel:(LSYReadModel *)readModel url:(NSURL *)url; 27 | +(id)getLocalModelWithURL:(NSURL *)url; 28 | @end 29 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Model/LSYReadModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYReadModel.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYReadModel.h" 10 | #import "LSYReadConfig.h" 11 | 12 | @implementation LSYReadModel 13 | -(instancetype)initWithContent:(NSString *)content 14 | { 15 | self = [super init]; 16 | if (self) { 17 | _content = content; 18 | NSMutableArray *charpter = [NSMutableArray array]; 19 | [LSYReadUtilites separateChapter:&charpter content:content]; 20 | _chapters = charpter; 21 | _notes = [NSMutableArray array]; 22 | _marks = [NSMutableArray array]; 23 | _record = [[LSYRecordModel alloc] init]; 24 | _record.chapterModel = charpter.firstObject; 25 | _record.chapterCount = _chapters.count; 26 | _marksRecord = [NSMutableDictionary dictionary]; 27 | _font = [NSNumber numberWithFloat:[LSYReadConfig shareInstance].fontSize]; 28 | } 29 | return self; 30 | } 31 | -(instancetype)initWithePub:(NSString *)ePubPath; 32 | { 33 | self = [super init]; 34 | if (self) { 35 | _chapters = [LSYReadUtilites ePubFileHandle:ePubPath];; 36 | _notes = [NSMutableArray array]; 37 | _marks = [NSMutableArray array]; 38 | _record = [[LSYRecordModel alloc] init]; 39 | _record.chapterModel = _chapters.firstObject; 40 | _record.chapterCount = _chapters.count; 41 | _marksRecord = [NSMutableDictionary dictionary]; 42 | _font = [NSNumber numberWithFloat:[LSYReadConfig shareInstance].fontSize]; 43 | } 44 | return self; 45 | } 46 | -(void)encodeWithCoder:(NSCoder *)aCoder{ 47 | [aCoder encodeObject:self.content forKey:@"content"]; 48 | [aCoder encodeObject:self.marks forKey:@"marks"]; 49 | [aCoder encodeObject:self.notes forKey:@"notes"]; 50 | [aCoder encodeObject:self.chapters forKey:@"chapters"]; 51 | [aCoder encodeObject:self.record forKey:@"record"]; 52 | [aCoder encodeObject:self.resource forKey:@"resource"]; 53 | [aCoder encodeObject:self.marksRecord forKey:@"marksRecord"]; 54 | [aCoder encodeObject:self.font forKey:@"font"]; 55 | } 56 | -(id)initWithCoder:(NSCoder *)aDecoder{ 57 | self = [super init]; 58 | if (self) { 59 | self.content = [aDecoder decodeObjectForKey:@"content"]; 60 | self.marks = [aDecoder decodeObjectForKey:@"marks"]; 61 | self.notes = [aDecoder decodeObjectForKey:@"notes"]; 62 | self.chapters = [aDecoder decodeObjectForKey:@"chapters"]; 63 | self.record = [aDecoder decodeObjectForKey:@"record"]; 64 | self.resource = [aDecoder decodeObjectForKey:@"resource"]; 65 | self.marksRecord = [aDecoder decodeObjectForKey:@"marksRecord"]; 66 | self.font = [aDecoder decodeObjectForKey:@"font"]; 67 | } 68 | return self; 69 | } 70 | +(void)updateLocalModel:(LSYReadModel *)readModel url:(NSURL *)url 71 | { 72 | 73 | NSString *key = [url.path lastPathComponent]; 74 | NSMutableData *data=[[NSMutableData alloc]init]; 75 | NSKeyedArchiver *archiver=[[NSKeyedArchiver alloc]initForWritingWithMutableData:data]; 76 | [archiver encodeObject:readModel forKey:key]; 77 | [archiver finishEncoding]; 78 | [[NSUserDefaults standardUserDefaults] setObject:data forKey:key]; 79 | } 80 | +(id)getLocalModelWithURL:(NSURL *)url 81 | { 82 | NSString *key = [url.path lastPathComponent]; 83 | NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:key]; 84 | if (!data) { 85 | if ([[key pathExtension] isEqualToString:@"txt"]) { 86 | LSYReadModel *model = [[LSYReadModel alloc] initWithContent:[LSYReadUtilites encodeWithURL:url]]; 87 | model.resource = url; 88 | [LSYReadModel updateLocalModel:model url:url]; 89 | return model; 90 | } 91 | else if ([[key pathExtension] isEqualToString:@"epub"]){ 92 | NSLog(@"this is epub"); 93 | LSYReadModel *model = [[LSYReadModel alloc] initWithePub:url.path]; 94 | model.resource = url; 95 | [LSYReadModel updateLocalModel:model url:url]; 96 | return model; 97 | } 98 | else{ 99 | @throw [NSException exceptionWithName:@"FileException" reason:@"文件格式错误" userInfo:nil]; 100 | } 101 | 102 | } 103 | NSKeyedUnarchiver *unarchive = [[NSKeyedUnarchiver alloc]initForReadingWithData:data]; 104 | LSYReadModel *model = [unarchive decodeObjectForKey:key]; 105 | 106 | if ([model.font floatValue] != [LSYReadConfig shareInstance].fontSize) { 107 | if ([[key pathExtension] isEqualToString:@"txt"]) { 108 | LSYReadModel *model = [[LSYReadModel alloc] initWithContent:[LSYReadUtilites encodeWithURL:url]]; 109 | model.resource = url; 110 | [LSYReadModel updateLocalModel:model url:url]; 111 | return model; 112 | } 113 | } 114 | 115 | return model; 116 | } 117 | - (NSUInteger)getPageIndexByOffset:(NSUInteger)offset Chapter:(NSUInteger)chapterIndex { 118 | LSYChapterModel *chapterModel = _chapters[chapterIndex]; 119 | NSArray *pageArray = chapterModel.pageArray; 120 | 121 | for (int i = 0; i < pageArray.count - 1; i++) { 122 | if (offset >= [pageArray[i] integerValue] && offset < [pageArray[i + 1] integerValue]) { 123 | return i; 124 | } 125 | } 126 | 127 | if (offset >= [pageArray[pageArray.count - 1] integerValue]) { 128 | return pageArray.count - 1; 129 | } else { 130 | return 0; 131 | } 132 | } 133 | @end 134 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Model/LSYRecordModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYRecordModel.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LSYChapterModel.h" 11 | @interface LSYRecordModel : NSObject 12 | @property (nonatomic,strong) LSYChapterModel *chapterModel; //阅读的章节 13 | @property (nonatomic) NSUInteger page; //阅读的页数 14 | @property (nonatomic) NSUInteger chapter; //阅读的章节数 15 | @property (nonatomic) NSUInteger chapterCount; //总章节数 16 | @end 17 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Model/LSYRecordModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYRecordModel.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/31. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYRecordModel.h" 10 | 11 | @implementation LSYRecordModel 12 | -(id)copyWithZone:(NSZone *)zone 13 | { 14 | LSYRecordModel *recordModel = [[LSYRecordModel allocWithZone:zone]init]; 15 | recordModel.chapterModel = [self.chapterModel copy]; 16 | recordModel.page = self.page; 17 | recordModel.chapter = self.chapter; 18 | return recordModel; 19 | } 20 | 21 | -(void)encodeWithCoder:(NSCoder *)aCoder{ 22 | [aCoder encodeObject:self.chapterModel forKey:@"chapterModel"]; 23 | [aCoder encodeInteger:self.page forKey:@"page"]; 24 | [aCoder encodeInteger:self.chapter forKey:@"chapter"]; 25 | [aCoder encodeInteger:self.chapterCount forKey:@"chapterCount"]; 26 | } 27 | -(id)initWithCoder:(NSCoder *)aDecoder{ 28 | self = [super init]; 29 | if (self) { 30 | self.chapterModel = [aDecoder decodeObjectForKey:@"chapterModel"]; 31 | self.page = [aDecoder decodeIntegerForKey:@"page"]; 32 | self.chapter = [aDecoder decodeIntegerForKey:@"chapter"]; 33 | self.chapterCount = [aDecoder decodeIntegerForKey:@"chapterCount"]; 34 | } 35 | return self; 36 | } 37 | @end 38 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Resource/bg_back_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/Resource/bg_back_white.png -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Resource/bg_back_white@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/Resource/bg_back_white@2x.png -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Resource/ic_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/Resource/ic_add.png -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Resource/r_drag-dot@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/Resource/r_drag-dot@2x.png -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Resource/reader_cover@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/Resource/reader_cover@2x.png -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Resource/reader_more@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/Resource/reader_more@2x.png -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Resource/sale_discount_yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/Resource/sale_discount_yellow.png -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Resource/细说明朝.epub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/Resource/细说明朝.epub -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/GTMNSString+HTML.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTMNSString+HTML.h 3 | // Dealing with NSStrings that contain HTML 4 | // 5 | // Copyright 2006-2008 Google Inc. 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 8 | // use this file except in compliance with the License. You may obtain a copy 9 | // of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 16 | // License for the specific language governing permissions and limitations under 17 | // the License. 18 | // 19 | 20 | #import 21 | 22 | /// Utilities for NSStrings containing HTML 23 | @interface NSString (GTMNSStringHTMLAdditions) 24 | 25 | /// Get a string where internal characters that need escaping for HTML are escaped 26 | // 27 | /// For example, '&' become '&'. This will only cover characters from table 28 | /// A.2.2 of http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters 29 | /// which is what you want for a unicode encoded webpage. If you have a ascii 30 | /// or non-encoded webpage, please use stringByEscapingAsciiHTML which will 31 | /// encode all characters. 32 | /// 33 | /// For obvious reasons this call is only safe once. 34 | // 35 | // Returns: 36 | // Autoreleased NSString 37 | // 38 | - (NSString *)gtm_stringByEscapingForHTML; 39 | 40 | /// Get a string where internal characters that need escaping for HTML are escaped 41 | // 42 | /// For example, '&' become '&' 43 | /// All non-mapped characters (unicode that don't have a &keyword; mapping) 44 | /// will be converted to the appropriate &#xxx; value. If your webpage is 45 | /// unicode encoded (UTF16 or UTF8) use stringByEscapingHTML instead as it is 46 | /// faster, and produces less bloated and more readable HTML (as long as you 47 | /// are using a unicode compliant HTML reader). 48 | /// 49 | /// For obvious reasons this call is only safe once. 50 | // 51 | // Returns: 52 | // Autoreleased NSString 53 | // 54 | - (NSString *)gtm_stringByEscapingForAsciiHTML; 55 | 56 | /// Get a string where internal characters that are escaped for HTML are unescaped 57 | // 58 | /// For example, '&' becomes '&' 59 | /// Handles and 2 cases as well 60 | /// 61 | // Returns: 62 | // Autoreleased NSString 63 | // 64 | - (NSString *)gtm_stringByUnescapingFromHTML; 65 | 66 | @end -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/LSYViewPagerVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYViewPagerVC.h 3 | // LSYViewPagerVC 4 | // github:https://github.com/GGGHub/ViewPager 5 | // Created by okwei on 15/10/9. 6 | // Copyright © 2015年 okwei. All rights reserved. 7 | // 8 | 9 | #import 10 | @class LSYViewPagerVC; 11 | #pragma mark View Pager Delegate 12 | @protocol LSYViewPagerVCDelegate 13 | @optional 14 | /** 15 | 控制器结束滑动时调用该方法,返回当前显示的视图控制器 16 | */ 17 | -(void)viewPagerViewController:(LSYViewPagerVC *)viewPager didFinishScrollWithCurrentViewController:(UIViewController *)viewController; 18 | /** 19 | 控制器将要开始滑动时调用该方法,返回当前将要滑动的视图控制器 20 | */ 21 | -(void)viewPagerViewController:(LSYViewPagerVC *)viewPager willScrollerWithCurrentViewController:(UIViewController *)ViewController; 22 | 23 | @end 24 | 25 | #pragma mark View Pager DataSource 26 | @protocol LSYViewPagerVCDataSource 27 | 28 | @required 29 | /** 30 | 设置返回需要滑动的控制器数量 31 | */ 32 | -(NSInteger)numberOfViewControllersInViewPager:(LSYViewPagerVC *)viewPager; 33 | /** 34 | 用来设置当前索引下返回的控制器 35 | */ 36 | -(UIViewController *)viewPager:(LSYViewPagerVC *)viewPager indexOfViewControllers:(NSInteger)index; 37 | /** 38 | 给每一个控制器设置一个标题 39 | */ 40 | -(NSString *)viewPager:(LSYViewPagerVC *)viewPager titleWithIndexOfViewControllers:(NSInteger)index; 41 | 42 | @optional 43 | /** 44 | 设置控制器标题按钮的样式,如果不设置将使用默认的样式,选择为红色,不选中为黑色带有选中下划线 45 | */ 46 | -(UIButton *)viewPager:(LSYViewPagerVC *)viewPager titleButtonStyle:(NSInteger)index; 47 | /** 48 | 设置控制器上面标题的高度 49 | */ 50 | -(CGFloat)heightForTitleOfViewPager:(LSYViewPagerVC *)viewPager; 51 | /** 52 | 如果有需要还要在控制器标题顶上添加视图。用来设置控制器标题上面的头部视图 53 | */ 54 | -(UIView *)headerViewForInViewPager:(LSYViewPagerVC *)viewPager; 55 | /** 56 | 设置头部视图的高度 57 | */ 58 | -(CGFloat)heightForHeaderOfViewPager:(LSYViewPagerVC *)viewPager; 59 | @end 60 | 61 | @interface LSYViewPagerVC : UIViewController 62 | @property (nonatomic,weak) iddataSource; 63 | @property (nonatomic,weak) iddelegate; 64 | @property (nonatomic) BOOL forbidGesture; 65 | /** 66 | 用来刷新ViewPager 67 | */ 68 | -(void)reload; 69 | @end 70 | 71 | 72 | #pragma mark View Controller Title Button 73 | 74 | @interface LSYViewPagerTitleButton : UIButton 75 | 76 | @end -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/NSString+HTML.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+HTML.h 3 | // MWFeedParser 4 | // 5 | // Copyright (c) 2010 Michael Waterfall 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // 1. The above copyright notice and this permission notice shall be included 15 | // in all copies or substantial portions of the Software. 16 | // 17 | // 2. This Software cannot be used to archive or collect data such as (but not 18 | // limited to) that of events, news, experiences and activities, for the 19 | // purpose of any concept relating to diary/journal keeping. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | // THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | // Dependant upon GTMNSString+HTML 33 | 34 | @interface NSString (HTML) 35 | 36 | // Instance Methods 37 | - (NSString *)stringByConvertingHTMLToPlainText; 38 | - (NSString *)stringByDecodingHTMLEntities; 39 | - (NSString *)stringByEncodingHTMLEntities; 40 | - (NSString *)stringWithNewLinesAsBRs; 41 | - (NSString *)stringByRemovingNewLinesAndWhitespace; 42 | 43 | // DEPRECIATED - Please use NSString stringByConvertingHTMLToPlainText 44 | - (NSString *)stringByStrippingTags; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXHTMLDocument.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXHTMLDocument.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument.h" 33 | 34 | 35 | @interface CXHTMLDocument : CXMLDocument { 36 | 37 | } 38 | 39 | - (id)initWithXHTMLData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError; 40 | - (id)initWithXHTMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXHTMLDocument.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXHTMLDocument.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | // This is an experiment to see if we can utilize the HTMLParser functionality 33 | // of libXML to serve as a XHTML parser, I question if this is a good idea or not 34 | // need to test some of the following 35 | // [-] How are xml namespaces handled 36 | // [-] Can we support DTD 37 | // [-] 38 | 39 | #import "CXHTMLDocument.h" 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #import "CXMLNode_PrivateExtensions.h" 47 | #import "CXMLElement.h" 48 | 49 | #if TOUCHXMLUSETIDY 50 | #import "CTidy.h" 51 | #endif /* TOUCHXMLUSETIDY */ 52 | 53 | @implementation CXHTMLDocument 54 | 55 | 56 | // Differs from initWithXMLString by using libXML's HTML parser, which automatically decodes XHTML/HTML entities found within the document 57 | // which eliminates the need to resanitize strings extracted from the document 58 | // libXML treats a htmlDocPtr the same as xmlDocPtr 59 | - (id)initWithXHTMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError 60 | { 61 | #pragma unused (inOptions) 62 | if ((self = [super init]) != NULL) 63 | { 64 | NSError *theError = NULL; 65 | 66 | htmlDocPtr theDoc = htmlParseDoc(BAD_CAST[inString UTF8String], xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF8)); 67 | if (theDoc != NULL) 68 | { 69 | // TODO: change code to not depend on XPATH, should be a task simple enough to do 70 | // alternatively see if we can prevent the HTML parser from adding implied tags 71 | 72 | xmlXPathContextPtr xpathContext = xmlXPathNewContext (theDoc); 73 | 74 | xmlXPathObjectPtr xpathObject = NULL; 75 | if (xpathContext) 76 | xpathObject = xmlXPathEvalExpression (BAD_CAST("/html/body"), xpathContext); 77 | 78 | xmlNodePtr bodyNode = NULL; 79 | if (xpathObject && xpathObject->nodesetval->nodeMax) 80 | bodyNode = xpathObject->nodesetval->nodeTab[0]; 81 | 82 | // TODO: Determine if this is sufficient to handle memory in libXML, is the old root removed / deleted, etc 83 | if (bodyNode) 84 | xmlDocSetRootElement(theDoc, bodyNode->children); 85 | 86 | _node = (xmlNodePtr)theDoc; 87 | NSAssert(_node->_private == NULL, @"TODO"); 88 | _node->_private = (__bridge void *)self; // Note. NOT retained (TODO think more about _private usage) 89 | 90 | if (xpathObject) 91 | xmlXPathFreeObject (xpathObject); 92 | 93 | if (xpathContext) 94 | xmlXPathFreeContext (xpathContext); 95 | } 96 | else 97 | { 98 | xmlErrorPtr theLastErrorPtr = xmlGetLastError(); 99 | NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys: 100 | theLastErrorPtr ? [NSString stringWithUTF8String:theLastErrorPtr->message] : @"unknown", NSLocalizedDescriptionKey, 101 | NULL]; 102 | 103 | theError = [NSError errorWithDomain:@"CXMLErrorDomain" code:1 userInfo:theUserInfo]; 104 | 105 | xmlResetLastError(); 106 | } 107 | 108 | if (outError) 109 | { 110 | *outError = theError; 111 | } 112 | 113 | if (theError != NULL) 114 | { 115 | self = NULL; 116 | } 117 | } 118 | return(self); 119 | } 120 | 121 | - (id)initWithXHTMLData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError 122 | { 123 | #pragma unused (inOptions) 124 | if ((self = [super init]) != NULL) 125 | { 126 | NSError *theError = NULL; 127 | 128 | if (theError == NULL) 129 | { 130 | xmlDocPtr theDoc = NULL; 131 | if (inData && inData.length > 0) 132 | { 133 | CFStringEncoding cfenc = CFStringConvertNSStringEncodingToEncoding(encoding); 134 | CFStringRef cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc); 135 | const char *enc = CFStringGetCStringPtr(cfencstr, 0); 136 | theDoc = htmlReadMemory([inData bytes], (int)[inData length], NULL, enc, HTML_PARSE_NONET | HTML_PARSE_NOBLANKS | HTML_PARSE_NOWARNING); 137 | } 138 | 139 | if (theDoc != NULL) 140 | { 141 | _node = (xmlNodePtr)theDoc; 142 | _node->_private = (__bridge void *)self; // Note. NOT retained (TODO think more about _private usage) 143 | } 144 | else 145 | { 146 | theError = [NSError errorWithDomain:@"CXMLErrorDomain" code:-1 userInfo:NULL]; 147 | } 148 | } 149 | 150 | if (outError) 151 | { 152 | *outError = theError; 153 | } 154 | 155 | if (theError != NULL) 156 | { 157 | self = NULL; 158 | } 159 | } 160 | return(self); 161 | } 162 | 163 | @end 164 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLDocument.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | /* 35 | Tidy is disabled by default. In order to enable it correctly you need to: 36 | 1) set preprocessor macros TOUCHXMLUSETIDY=1 37 | 2) download and build libtidy into your app (you cannot link against system provided build, because you would use Apple private APIs) 38 | */ 39 | enum { 40 | CXMLDocumentTidyHTML = 1 << 9, // Based on NSXMLDocumentTidyHTML 41 | CXMLDocumentTidyXML = 1 << 10, // Based on NSXMLDocumentTidyXML 42 | }; 43 | 44 | @class CXMLElement; 45 | 46 | @interface CXMLDocument : CXMLNode { 47 | NSMutableSet *nodePool; 48 | } 49 | 50 | /* 51 | Please note that, if you use tidy to repair your HTML/XML source, your node 52 | graph may change. 53 | 54 | For example CTidy adds XHTML namespace to your HTML by default: 55 | 56 | An HTML source like this: 57 | 58 | 59 | My Title 60 | ... 61 | 62 | becomes: 63 | 65 | 66 | 67 | 69 | My Title 70 | ... 71 | 72 | This affects the way you will query this document with XPath, because you will 73 | need to pass namespace mappings dictionary and to add "xmlns" to your queries 74 | (e.g: "//xmlns:title" to reach "" element). 75 | */ 76 | - (id)initWithData:(NSData *)inData options:(NSUInteger)inOptions error:(NSError **)outError; 77 | - (id)initWithData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError; 78 | - (id)initWithXMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError; 79 | - (id)initWithContentsOfURL:(NSURL *)inURL options:(NSUInteger)inOptions error:(NSError **)outError; 80 | - (id)initWithContentsOfURL:(NSURL *)inURL encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError; 81 | 82 | //- (NSString *)characterEncoding; 83 | //- (NSString *)version; 84 | //- (BOOL)isStandalone; 85 | //- (CXMLDocumentContentKind)documentContentKind; 86 | //- (NSString *)MIMEType; 87 | //- (CXMLDTD *)DTD; 88 | 89 | - (CXMLElement *)rootElement; 90 | 91 | - (NSData *)XMLData; 92 | - (NSData *)XMLDataWithOptions:(NSUInteger)options; 93 | 94 | //- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; 95 | //- (id)objectByApplyingXSLTString:(NSString *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; 96 | //- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL arguments:(NSDictionary *)argument error:(NSError **)error; 97 | 98 | - (id)XMLStringWithOptions:(NSUInteger)options; 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLDocument_PrivateExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument_PrivateExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument.h" 33 | 34 | #include <libxml/parser.h> 35 | 36 | @interface CXMLDocument (CXMLDocument_PrivateExtensions) 37 | 38 | //- (id)initWithLibXmlParserContext:(xmlParserCtxtPtr)inContext options:(NSUInteger)inOptions error:(NSError **)outError; 39 | 40 | - (NSMutableSet *)nodePool; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLDocument_PrivateExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument_PrivateExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument_PrivateExtensions.h" 33 | 34 | @implementation CXMLDocument (CXMLDocument_PrivateExtensions) 35 | 36 | /* 37 | - (id)initWithLibXmlParserContext:(xmlParserCtxtPtr)inContext options:(NSUInteger)inOptions error:(NSError **)outError 38 | { 39 | 40 | xmlParseDocument(inContext); 41 | 42 | } 43 | */ 44 | 45 | - (NSMutableSet *)nodePool 46 | { 47 | if (nodePool == NULL) 48 | { 49 | nodePool = [[NSMutableSet alloc] init]; 50 | } 51 | return(nodePool); 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLElement.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | // NSXMLElement 35 | @interface CXMLElement : CXMLNode { 36 | 37 | } 38 | 39 | - (NSArray *)elementsForName:(NSString *)name; 40 | - (NSArray *)elementsForLocalName:(NSString *)localName URI:(NSString *)URI; 41 | 42 | - (NSArray *)attributes; 43 | - (CXMLNode *)attributeForName:(NSString *)name; 44 | - (CXMLNode *)attributeForLocalName:(NSString *)localName URI:(NSString *)URI; 45 | 46 | - (NSArray *)namespaces; 47 | - (CXMLNode *)namespaceForPrefix:(NSString *)name; 48 | - (CXMLNode *)resolveNamespaceForName:(NSString *)name; 49 | - (NSString *)resolvePrefixForNamespaceURI:(NSString *)namespaceURI; 50 | 51 | //- (NSString*)_XMLStringWithOptions:(NSUInteger)options appendingToString:(NSMutableString*)str; 52 | @end 53 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLElement_CreationExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement_CreationExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLElement.h" 33 | 34 | @interface CXMLElement (CXMLElement_CreationExtensions) 35 | 36 | - (void)addChild:(CXMLNode *)inNode; 37 | 38 | - (void)addNamespace:(CXMLNode *)inNamespace; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLElement_CreationExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement_CreationExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLElement_CreationExtensions.h" 33 | 34 | @implementation CXMLElement (CXMLElement_CreationExtensions) 35 | 36 | - (void)addChild:(CXMLNode *)inNode 37 | { 38 | NSAssert(inNode->_node->doc == NULL, @"Cannot addChild with a node that already is part of a document. Copy it first!"); 39 | NSAssert(self->_node != NULL, @"_node should not be null"); 40 | NSAssert(inNode->_node != NULL, @"_node should not be null"); 41 | xmlAddChild(self->_node, inNode->_node); 42 | // now XML element is tracked by document, do not release on dealloc 43 | inNode->_freeNodeOnRelease = NO; 44 | } 45 | 46 | - (void)addNamespace:(CXMLNode *)inNamespace 47 | { 48 | xmlSetNs(self->_node, (xmlNsPtr)inNamespace->_node); 49 | } 50 | 51 | - (void)setStringValue:(NSString *)inStringValue 52 | { 53 | NSAssert(inStringValue != NULL, @"CXMLElement setStringValue should not be null"); 54 | xmlNodePtr theContentNode = xmlNewText((const xmlChar *)[inStringValue UTF8String]); 55 | NSAssert(self->_node != NULL, @"_node should not be null"); 56 | xmlAddChild(self->_node, theContentNode); 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLElement_ElementTreeExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement_ElementTreeExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 11/14/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLElement.h" 33 | 34 | 35 | @interface CXMLElement (CXMLElement_ElementTreeExtensions) 36 | 37 | - (CXMLElement *)subelement:(NSString *)inName; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLElement_ElementTreeExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement_ElementTreeExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 11/14/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLElement_ElementTreeExtensions.h" 33 | 34 | #import "CXMLElement_CreationExtensions.h" 35 | #import "CXMLNode_CreationExtensions.h" 36 | 37 | @implementation CXMLElement (CXMLElement_ElementTreeExtensions) 38 | 39 | - (CXMLElement *)subelement:(NSString *)inName; 40 | { 41 | CXMLElement *theSubelement = [CXMLNode elementWithName:inName]; 42 | [self addChild:theSubelement]; 43 | return(theSubelement); 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLNamespaceNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNamespaceNode.h 3 | // TouchXML 4 | // 5 | // Created by Jonathan Wight on 1/1/2000. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import <Foundation/Foundation.h> 33 | #import "CXMLNode.h" 34 | #import "CXMLElement.h" 35 | 36 | @interface CXMLNamespaceNode : CXMLNode { 37 | 38 | NSString *_prefix; 39 | NSString *_uri; 40 | CXMLElement *_parent; 41 | } 42 | 43 | - (id) initWithPrefix:(NSString *)prefix URI:(NSString *)uri parentElement:(CXMLElement *)parent; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLNamespaceNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNamespaceNode.m 3 | // TouchXML 4 | // 5 | // Created by Jonathan Wight on 1/1/2000. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNamespaceNode.h" 33 | 34 | @implementation CXMLNamespaceNode 35 | 36 | #pragma mark - 37 | #pragma mark Init and dealloc 38 | 39 | - (id) initWithPrefix:(NSString *)prefix URI:(NSString *)uri parentElement:(CXMLElement *)parent 40 | { 41 | if ((self = [super init]) != NULL) 42 | { 43 | _prefix = [prefix copy]; 44 | _uri = [uri copy]; 45 | _parent = parent; // Don't retain parent 46 | } 47 | 48 | return self; 49 | } 50 | 51 | - (void) dealloc 52 | { 53 | _prefix = nil; 54 | _uri = nil; 55 | _parent = nil; // Parent not retained 56 | 57 | } 58 | 59 | #pragma mark - 60 | #pragma mark Overidden methods 61 | 62 | // NB: We need to override every method that relies on _node as namespaces in libXML don't have a xmlNode 63 | 64 | - (CXMLNodeKind)kind 65 | { 66 | return CXMLNamespaceKind; 67 | } 68 | 69 | - (NSString *)name 70 | { 71 | return _prefix ? [_prefix copy] : @""; 72 | } 73 | 74 | - (NSString *)stringValue 75 | { 76 | return _uri ? [_uri copy] : @""; 77 | } 78 | 79 | - (NSUInteger)index 80 | { 81 | return 0; // TODO: Write tets, Fix 82 | } 83 | 84 | - (NSUInteger)level 85 | { 86 | return _parent ? [_parent level] + 1 : 2; 87 | } 88 | 89 | - (CXMLDocument *)rootDocument 90 | { 91 | return [_parent rootDocument]; 92 | } 93 | 94 | - (CXMLNode *)parent 95 | { 96 | return _parent; 97 | } 98 | 99 | - (NSUInteger)childCount 100 | { 101 | return 0; 102 | } 103 | 104 | - (NSArray *)children 105 | { 106 | return nil; 107 | } 108 | 109 | - (CXMLNode *)childAtIndex:(NSUInteger)index 110 | { 111 | return nil; 112 | } 113 | 114 | - (CXMLNode *)previousSibling 115 | { 116 | return nil; // TODO: Write tets, Fix 117 | } 118 | 119 | - (CXMLNode *)nextSibling 120 | { 121 | return nil; // TODO: Write tets, Fix 122 | } 123 | 124 | //- (CXMLNode *)previousNode; 125 | //- (CXMLNode *)nextNode; 126 | //- (NSString *)XPath; 127 | 128 | - (NSString *)localName 129 | { 130 | return [self name]; 131 | } 132 | 133 | - (NSString *)prefix 134 | { 135 | return @""; 136 | } 137 | 138 | - (NSString *)URI 139 | { 140 | return nil; 141 | } 142 | 143 | //+ (NSString *)localNameForName:(NSString *)name; 144 | //+ (NSString *)prefixForName:(NSString *)name; 145 | //+ (CXMLNode *)predefinedNamespaceForPrefix:(NSString *)name; 146 | 147 | - (NSString *)description 148 | { 149 | if (_prefix && [_prefix length] > 0) 150 | return [NSString stringWithFormat:@"xmlns:%@=\"%@\"", _prefix, _uri]; 151 | 152 | return [NSString stringWithFormat:@"xmlns=\"%@\"", _uri]; 153 | } 154 | 155 | - (NSString *)XMLString 156 | { 157 | return [self description]; 158 | } 159 | 160 | - (NSString *)XMLStringWithOptions:(NSUInteger)options 161 | { 162 | return [self description]; 163 | } 164 | 165 | //- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments; 166 | 167 | - (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error 168 | { 169 | return nil; 170 | } 171 | 172 | @end 173 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import <Foundation/Foundation.h> 33 | 34 | #include <libxml/tree.h> 35 | 36 | typedef enum { 37 | CXMLInvalidKind = 0, 38 | CXMLElementKind = XML_ELEMENT_NODE, 39 | CXMLAttributeKind = XML_ATTRIBUTE_NODE, 40 | CXMLTextKind = XML_TEXT_NODE, 41 | CXMLProcessingInstructionKind = XML_PI_NODE, 42 | CXMLCommentKind = XML_COMMENT_NODE, 43 | CXMLNotationDeclarationKind = XML_NOTATION_NODE, 44 | CXMLDTDKind = XML_DTD_NODE, 45 | CXMLElementDeclarationKind = XML_ELEMENT_DECL, 46 | CXMLAttributeDeclarationKind = XML_ATTRIBUTE_DECL, 47 | CXMLEntityDeclarationKind = XML_ENTITY_DECL, 48 | CXMLNamespaceKind = XML_NAMESPACE_DECL, 49 | CXMLEntityReferenceKind = XML_ENTITY_REF_NODE 50 | } CXMLNodeKind; 51 | 52 | @class CXMLDocument; 53 | 54 | // NSXMLNode 55 | @interface CXMLNode : NSObject <NSCopying> { 56 | xmlNodePtr _node; 57 | BOOL _freeNodeOnRelease; 58 | } 59 | 60 | - (CXMLNodeKind)kind; 61 | - (NSString *)name; 62 | - (NSString *)stringValue; 63 | - (NSUInteger)index; 64 | - (NSUInteger)level; 65 | - (CXMLDocument *)rootDocument; 66 | - (CXMLNode *)parent; 67 | - (NSUInteger)childCount; 68 | - (NSArray *)children; 69 | - (CXMLNode *)childAtIndex:(NSUInteger)index; 70 | - (CXMLNode *)previousSibling; 71 | - (CXMLNode *)nextSibling; 72 | //- (CXMLNode *)previousNode; 73 | //- (CXMLNode *)nextNode; 74 | //- (NSString *)XPath; 75 | - (NSString *)localName; 76 | - (NSString *)prefix; 77 | - (NSString *)URI; 78 | + (NSString *)localNameForName:(NSString *)name; 79 | + (NSString *)prefixForName:(NSString *)name; 80 | + (CXMLNode *)predefinedNamespaceForPrefix:(NSString *)name; 81 | - (NSString *)description; 82 | - (NSString *)XMLString; 83 | - (NSString *)XMLStringWithOptions:(NSUInteger)options; 84 | //- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments; 85 | - (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error; 86 | @end 87 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLNode_PrivateExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_PrivateExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | @interface CXMLNode (CXMLNode_PrivateExtensions) 35 | 36 | @property (readonly, nonatomic, assign) xmlNodePtr node; 37 | 38 | - (id)initWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc; 39 | 40 | + (id)nodeWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc; 41 | 42 | + (Class)nodeClassForLibXMLNode:(xmlNodePtr)inLibXMLNode; 43 | 44 | - (void)invalidate; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLNode_PrivateExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_PrivateExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode_PrivateExtensions.h" 33 | 34 | #import "CXMLElement.h" 35 | #import "CXMLDocument_PrivateExtensions.h" 36 | #import "CXMLUnsupportedNode.h" 37 | 38 | @implementation CXMLNode (CXMLNode_PrivateExtensions) 39 | 40 | - (id)initWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc 41 | { 42 | if (inLibXMLNode == NULL) 43 | return nil; 44 | 45 | if ((self = [super init]) != NULL) 46 | { 47 | _node = inLibXMLNode; 48 | _freeNodeOnRelease = infreeOnDealloc; 49 | } 50 | return(self); 51 | } 52 | 53 | + (id)nodeWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc 54 | { 55 | // TODO more checking. 56 | if (inLibXMLNode == NULL) 57 | return nil; 58 | 59 | if (inLibXMLNode->_private) 60 | return((__bridge id)inLibXMLNode->_private); 61 | 62 | Class theClass = [self nodeClassForLibXMLNode:inLibXMLNode]; 63 | 64 | CXMLNode *theNode = [[theClass alloc] initWithLibXMLNode:inLibXMLNode freeOnDealloc:infreeOnDealloc]; 65 | 66 | 67 | if (inLibXMLNode->doc != NULL) { 68 | CXMLDocument *theXMLDocument = (__bridge CXMLDocument *)inLibXMLNode->doc->_private; 69 | if (theXMLDocument != NULL) { 70 | NSAssert([theXMLDocument isKindOfClass:[CXMLDocument class]] == YES, @"TODO"); 71 | 72 | [[theXMLDocument nodePool] addObject:theNode]; 73 | 74 | theNode->_node->_private = (__bridge void *)theNode; 75 | } 76 | } 77 | return(theNode); 78 | } 79 | 80 | + (Class)nodeClassForLibXMLNode:(xmlNodePtr)inLibXMLNode { 81 | Class theClass; 82 | 83 | switch (inLibXMLNode->type) 84 | { 85 | case XML_ELEMENT_NODE: 86 | theClass = [CXMLElement class]; 87 | break; 88 | case XML_DOCUMENT_NODE: 89 | theClass = [CXMLDocument class]; 90 | break; 91 | case XML_ATTRIBUTE_NODE: 92 | case XML_TEXT_NODE: 93 | case XML_CDATA_SECTION_NODE: 94 | case XML_COMMENT_NODE: 95 | theClass = [CXMLNode class]; 96 | break; 97 | default: 98 | theClass = [CXMLUnsupportedNode class]; 99 | } 100 | 101 | return theClass; 102 | } 103 | 104 | - (xmlNodePtr)node 105 | { 106 | return(_node); 107 | } 108 | 109 | - (void)invalidate; 110 | { 111 | if (_node) 112 | { 113 | if (_node->_private == (__bridge void *)self) 114 | _node->_private = NULL; 115 | 116 | if (_freeNodeOnRelease) 117 | { 118 | xmlUnlinkNode(_node); 119 | xmlFreeNode(_node); 120 | } 121 | 122 | _node = NULL; 123 | } 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLNode_XPathExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_XPathExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | @interface CXMLNode (CXMLNode_XPathExtensions) 35 | 36 | - (NSArray *)nodesForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error; 37 | - (CXMLNode *)nodeForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error; 38 | - (CXMLNode *)nodeForXPath:(NSString *)xpath error:(NSError **)outError; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLNode_XPathExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_XPathExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode_XPathExtensions.h" 33 | 34 | #import "CXMLDocument.h" 35 | #import "CXMLNode_PrivateExtensions.h" 36 | 37 | #include <libxml/xpath.h> 38 | #include <libxml/xpathInternals.h> 39 | 40 | @implementation CXMLNode (CXMLNode_XPathExtensions) 41 | 42 | - (NSArray *)nodesForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error; 43 | { 44 | #pragma unused (error) 45 | 46 | NSAssert(_node != NULL, @"TODO"); 47 | 48 | NSArray *theResult = NULL; 49 | 50 | xmlXPathContextPtr theXPathContext = xmlXPathNewContext(_node->doc); 51 | theXPathContext->node = _node; 52 | 53 | for (NSString *thePrefix in inNamespaceMappings) 54 | { 55 | xmlXPathRegisterNs(theXPathContext, (xmlChar *)[thePrefix UTF8String], (xmlChar *)[[inNamespaceMappings objectForKey:thePrefix] UTF8String]); 56 | } 57 | 58 | // TODO considering putting xmlChar <-> UTF8 into a NSString category 59 | xmlXPathObjectPtr theXPathObject = xmlXPathEvalExpression((const xmlChar *)[xpath UTF8String], theXPathContext); 60 | if (xmlXPathNodeSetIsEmpty(theXPathObject->nodesetval)) 61 | theResult = [NSArray array]; // TODO better to return NULL? 62 | else 63 | { 64 | NSMutableArray *theArray = [NSMutableArray array]; 65 | int N; 66 | for (N = 0; N < theXPathObject->nodesetval->nodeNr; N++) 67 | { 68 | xmlNodePtr theNode = theXPathObject->nodesetval->nodeTab[N]; 69 | [theArray addObject:[CXMLNode nodeWithLibXMLNode:theNode freeOnDealloc:NO]]; 70 | } 71 | 72 | theResult = theArray; 73 | } 74 | 75 | xmlXPathFreeObject(theXPathObject); 76 | 77 | xmlXPathFreeContext(theXPathContext); 78 | return(theResult); 79 | } 80 | 81 | - (CXMLNode *)nodeForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error 82 | { 83 | return [[self nodesForXPath:xpath namespaceMappings:inNamespaceMappings error:error] lastObject]; 84 | } 85 | 86 | - (CXMLNode *)nodeForXPath:(NSString *)xpath error:(NSError **)outError 87 | { 88 | return([[self nodesForXPath:xpath error:outError] lastObject]); 89 | } 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLUnsupportedNode.h: -------------------------------------------------------------------------------- 1 | /** 2 | This is a "special" class which marks nodes types not supported by TouchXML. 3 | They could work... or not... becareful when you encounter them. 4 | */ 5 | 6 | #import "CXMLNode.h" 7 | 8 | @interface CXMLUnsupportedNode : CXMLNode 9 | 10 | @end 11 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/CXMLUnsupportedNode.m: -------------------------------------------------------------------------------- 1 | #import "CXMLUnsupportedNode.h" 2 | 3 | @implementation CXMLUnsupportedNode 4 | 5 | @end 6 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/Creation/CXMLDocument_CreationExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument_CreationExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 11/11/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument.h" 33 | 34 | @interface CXMLDocument (CXMLDocument_CreationExtensions) 35 | 36 | //- (void)setVersion:(NSString *)version; //primitive 37 | //- (void)setStandalone:(BOOL)standalone; //primitive 38 | //- (void)setDocumentContentKind:(CXMLDocumentContentKind)kind; //primitive 39 | //- (void)setMIMEType:(NSString *)MIMEType; //primitive 40 | //- (void)setDTD:(CXMLDTD *)documentTypeDeclaration; //primitive 41 | //- (void)setRootElement:(CXMLNode *)root; 42 | - (void)insertChild:(CXMLNode *)child atIndex:(NSUInteger)index; 43 | //- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; 44 | //- (void)removeChildAtIndex:(NSUInteger)index; //primitive 45 | //- (void)setChildren:(NSArray *)children; //primitive 46 | - (void)addChild:(CXMLNode *)child; 47 | //- (void)replaceChildAtIndex:(NSUInteger)index withNode:(CXMLNode *)node; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/Creation/CXMLDocument_CreationExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument_CreationExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 11/11/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument_CreationExtensions.h" 33 | 34 | #import "CXMLElement.h" 35 | #import "CXMLNode_PrivateExtensions.h" 36 | #import "CXMLDocument_PrivateExtensions.h" 37 | 38 | @implementation CXMLDocument (CXMLDocument_CreationExtensions) 39 | 40 | - (void)insertChild:(CXMLNode *)child atIndex:(NSUInteger)index 41 | { 42 | [self.nodePool addObject:child]; 43 | 44 | CXMLNode *theCurrentNode = [self.children objectAtIndex:index]; 45 | xmlAddPrevSibling(theCurrentNode->_node, child->_node); 46 | } 47 | 48 | - (void)addChild:(CXMLNode *)child 49 | { 50 | [self.nodePool addObject:child]; 51 | 52 | xmlAddChild(self->_node, child->_node); 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/Creation/CXMLNode_CreationExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_CreationExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | @class CXMLElement; 35 | 36 | @interface CXMLNode (CXMLNode_CreationExtensions) 37 | 38 | //- (id)initWithKind:(NSXMLNodeKind)kind; 39 | //- (id)initWithKind:(NSXMLNodeKind)kind options:(NSUInteger)options; //primitive 40 | + (id)document; 41 | + (id)documentWithRootElement:(CXMLElement *)element; 42 | + (id)elementWithName:(NSString *)name; 43 | + (id)elementWithName:(NSString *)name URI:(NSString *)URI; 44 | + (id)elementWithName:(NSString *)name stringValue:(NSString *)string; 45 | //+ (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes; 46 | //+ (id)attributeWithName:(NSString *)name stringValue:(NSString *)stringValue; 47 | //+ (id)attributeWithName:(NSString *)name URI:(NSString *)URI stringValue:(NSString *)stringValue; 48 | + (id)namespaceWithName:(NSString *)name stringValue:(NSString *)stringValue; 49 | + (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)stringValue; 50 | //+ (id)commentWithStringValue:(NSString *)stringValue; 51 | //+ (id)textWithStringValue:(NSString *)stringValue; 52 | //+ (id)DTDNodeWithXMLString:(NSString *)string; 53 | 54 | - (void)setStringValue:(NSString *)inStringValue; 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/Creation/CXMLNode_CreationExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_CreationExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode_CreationExtensions.h" 33 | 34 | #import "CXMLDocument.h" 35 | #import "CXMLElement.h" 36 | #import "CXMLNode_PrivateExtensions.h" 37 | #import "CXMLDocument_PrivateExtensions.h" 38 | #import "CXMLNamespaceNode.h" 39 | 40 | @implementation CXMLNode (CXMLNode_CreationExtensions) 41 | 42 | + (id)document; 43 | { 44 | xmlDocPtr theDocumentNode = xmlNewDoc((const xmlChar *)"1.0"); 45 | NSAssert(theDocumentNode != NULL, @"xmlNewDoc failed"); 46 | CXMLDocument *theDocument = [[CXMLDocument alloc] initWithLibXMLNode:(xmlNodePtr)theDocumentNode freeOnDealloc:NO]; 47 | return(theDocument); 48 | } 49 | 50 | + (id)documentWithRootElement:(CXMLElement *)element; 51 | { 52 | xmlDocPtr theDocumentNode = xmlNewDoc((const xmlChar *)"1.0"); 53 | NSAssert(theDocumentNode != NULL, @"xmlNewDoc failed"); 54 | xmlDocSetRootElement(theDocumentNode, element.node); 55 | CXMLDocument *theDocument = [[CXMLDocument alloc] initWithLibXMLNode:(xmlNodePtr)theDocumentNode freeOnDealloc:NO]; 56 | [theDocument.nodePool addObject:element]; 57 | return(theDocument); 58 | } 59 | 60 | + (id)elementWithName:(NSString *)name 61 | { 62 | xmlNodePtr theElementNode = xmlNewNode(NULL, (const xmlChar *)[name UTF8String]); 63 | CXMLElement *theElement = [[CXMLElement alloc] initWithLibXMLNode:(xmlNodePtr)theElementNode freeOnDealloc:NO]; 64 | return(theElement); 65 | } 66 | 67 | + (id)elementWithName:(NSString *)name URI:(NSString *)URI 68 | { 69 | xmlNodePtr theElementNode = xmlNewNode(NULL, (const xmlChar *)[name UTF8String]); 70 | xmlNsPtr theNSNode = xmlNewNs(theElementNode, (const xmlChar *)[URI UTF8String], NULL); 71 | theElementNode->ns = theNSNode; 72 | 73 | CXMLElement *theElement = [[CXMLElement alloc] initWithLibXMLNode:(xmlNodePtr)theElementNode freeOnDealloc:NO]; 74 | return(theElement); 75 | } 76 | 77 | + (id)elementWithName:(NSString *)name stringValue:(NSString *)string 78 | { 79 | xmlNodePtr theElementNode = xmlNewNode(NULL, (const xmlChar *)[name UTF8String]); 80 | CXMLElement *theElement = [[CXMLElement alloc] initWithLibXMLNode:(xmlNodePtr)theElementNode freeOnDealloc:NO]; 81 | theElement.stringValue = string; 82 | return(theElement); 83 | } 84 | 85 | + (id)namespaceWithName:(NSString *)name stringValue:(NSString *)stringValue 86 | { 87 | return [[CXMLNamespaceNode alloc] initWithPrefix:name URI:stringValue parentElement:nil]; 88 | } 89 | 90 | + (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)stringValue; 91 | { 92 | xmlNodePtr theNode = xmlNewPI((const xmlChar *)[name UTF8String], (const xmlChar *)[stringValue UTF8String]); 93 | NSAssert(theNode != NULL, @"xmlNewPI failed"); 94 | CXMLNode *theNodeObject = [[CXMLNode alloc] initWithLibXMLNode:theNode freeOnDealloc:NO]; 95 | return(theNodeObject); 96 | } 97 | 98 | - (void)setStringValue:(NSString *)inStringValue 99 | { 100 | NSAssert(_node->type == XML_TEXT_NODE, @"CNode setStringValue only implemented for text nodes"); 101 | xmlNodeSetContent(_node, (const xmlChar *)[inStringValue UTF8String]); 102 | } 103 | 104 | @end 105 | 106 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/Tidy/CTidy.h: -------------------------------------------------------------------------------- 1 | // 2 | // CTidy.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #ifdef TOUCHXMLUSETIDY 33 | 34 | #import <Foundation/Foundation.h> 35 | 36 | #include "tidy.h" 37 | #include "buffio.h" 38 | 39 | typedef enum { 40 | TidyFormat_HTML, 41 | TidyFormat_XML, 42 | TidyFormat_XHTML, 43 | } CTidyFormat; 44 | 45 | @interface CTidy : NSObject 46 | + (NSString *)tidyEncodingFromStringEncoding:(NSStringEncoding)encoding; 47 | 48 | - (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char *)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError; 49 | 50 | - (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char *)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError; 51 | @end 52 | 53 | #endif /* TOUCHXMLUSETIDY */ 54 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/TouchXML/Source/TouchXML.h: -------------------------------------------------------------------------------- 1 | // 2 | // TouchXML.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 07/11/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument.h" 33 | #import "CXMLDocument_CreationExtensions.h" 34 | #import "CXMLElement.h" 35 | #import "CXMLElement_CreationExtensions.h" 36 | #import "CXMLElement_ElementTreeExtensions.h" 37 | #import "CXMLNode.h" 38 | #import "CXMLNode_CreationExtensions.h" 39 | #import "CXMLNode_XPathExtensions.h" 40 | #import "CXMLUnsupportedNode.h" 41 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/UIImage+ImageEffects.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: UIImage+ImageEffects.h 3 | Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur. 4 | Version: 1.0 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2013 Apple Inc. All Rights Reserved. 45 | 46 | 47 | Copyright © 2013 Apple Inc. All rights reserved. 48 | WWDC 2013 License 49 | 50 | NOTE: This Apple Software was supplied by Apple as part of a WWDC 2013 51 | Session. Please refer to the applicable WWDC 2013 Session for further 52 | information. 53 | 54 | IMPORTANT: This Apple software is supplied to you by Apple Inc. 55 | ("Apple") in consideration of your agreement to the following terms, and 56 | your use, installation, modification or redistribution of this Apple 57 | software constitutes acceptance of these terms. If you do not agree with 58 | these terms, please do not use, install, modify or redistribute this 59 | Apple software. 60 | 61 | In consideration of your agreement to abide by the following terms, and 62 | subject to these terms, Apple grants you a non-exclusive license, under 63 | Apple's copyrights in this original Apple software (the "Apple 64 | Software"), to use, reproduce, modify and redistribute the Apple 65 | Software, with or without modifications, in source and/or binary forms; 66 | provided that if you redistribute the Apple Software in its entirety and 67 | without modifications, you must retain this notice and the following 68 | text and disclaimers in all such redistributions of the Apple Software. 69 | Neither the name, trademarks, service marks or logos of Apple Inc. may 70 | be used to endorse or promote products derived from the Apple Software 71 | without specific prior written permission from Apple. Except as 72 | expressly stated in this notice, no other rights or licenses, express or 73 | implied, are granted by Apple herein, including but not limited to any 74 | patent rights that may be infringed by your derivative works or by other 75 | works in which the Apple Software may be incorporated. 76 | 77 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES 78 | NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE 79 | IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR 80 | A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 81 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 82 | 83 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 84 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 85 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 86 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 87 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 88 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 89 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 90 | POSSIBILITY OF SUCH DAMAGE. 91 | 92 | EA1002 93 | 5/3/2013 94 | */ 95 | 96 | @import UIKit; 97 | 98 | @interface UIImage (ImageEffects) 99 | 100 | - (UIImage *)applyLightEffect; 101 | - (UIImage *)applyExtraLightEffect; 102 | - (UIImage *)applyDarkEffect; 103 | - (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor; 104 | 105 | - (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage; 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/ZipArchive/ZipArchive.h: -------------------------------------------------------------------------------- 1 | /** 2 | // @header ZipArchive.h 3 | // 4 | // An objective C wrapper for minizip and libz for creating and exanding ZIP files. 5 | // 6 | // @author Created by aish on 08-9-11. 7 | // acsolu@gmail.com 8 | // @copyright Copyright 2008 Inc. All rights reserved. 9 | // 10 | */ 11 | 12 | #import <Foundation/Foundation.h> 13 | #import <UIKit/UIKit.h> 14 | typedef NS_ENUM(NSInteger, ZipArchiveCompression) { 15 | ZipArchiveCompressionDefault = -1, 16 | ZipArchiveCompressionNone = 0, 17 | ZipArchiveCompressionSpeed = 1, 18 | ZipArchiveCompressionBest = 9, 19 | }; 20 | 21 | 22 | /** 23 | a block that is called from UnzipFileTo:overwrite:withProgressBlock: where the percentage of 24 | files processed (as an integer from 0 to 100), the number of files processed so far and the 25 | total number of files in the archive is called after each file is processed. 26 | */ 27 | typedef void(^ZipArchiveProgressUpdateBlock)(int percentage, int filesProcessed, unsigned long numFiles); 28 | 29 | /** 30 | @protocol 31 | @discussion methods for a delegate to receive error notifications and control overwriting of files 32 | */ 33 | 34 | @protocol ZipArchiveDelegate <NSObject> 35 | @optional 36 | 37 | /** 38 | @brief Delegate method to be notified of errors 39 | 40 | ZipArchive calls this selector on the delegate when errors are encountered. 41 | 42 | @param msg a string describing the error. 43 | @result void 44 | */ 45 | 46 | -(void) ErrorMessage:(NSString*) msg; 47 | 48 | /** 49 | @brief Delegate method to determine if a file should be replaced 50 | 51 | When an zip file is being expanded and a file is about to be replaced, this selector 52 | is called on the delegate to notify that file is about to be replaced. The delegate method 53 | should return YES to overwrite the file, or NO to skip it. 54 | 55 | @param file - path to the file to be overwritten. 56 | @result a BOOL - YES to replace, NO to skip 57 | */ 58 | 59 | -(BOOL) OverWriteOperation:(NSString*) file; 60 | 61 | @end 62 | 63 | /** 64 | @class 65 | @brief An object that can create zip files and expand existing ones. 66 | This class provides methods to create a zip file (optionally with a password) and 67 | add files to that zip archive. 68 | 69 | It also provides methods to expand an existing archive file (optionally with a password), 70 | and extract the files. 71 | */ 72 | 73 | @interface ZipArchive : NSObject { 74 | @private 75 | void* _zipFile; 76 | void* _unzFile; 77 | 78 | unsigned long _numFiles; 79 | NSString* _password; 80 | id _delegate; 81 | ZipArchiveProgressUpdateBlock _progressBlock; 82 | 83 | NSArray* _unzippedFiles; 84 | 85 | NSFileManager* _fileManager; 86 | NSStringEncoding _stringEncoding; 87 | } 88 | 89 | /** a delegate object conforming to ZipArchiveDelegate protocol */ 90 | @property (nonatomic, retain) id<ZipArchiveDelegate> delegate; 91 | @property (nonatomic, readonly) unsigned long numFiles; 92 | @property (nonatomic, copy) ZipArchiveProgressUpdateBlock progressBlock; 93 | 94 | @property (nonatomic, assign) ZipArchiveCompression compression; 95 | 96 | /** 97 | @brief String encoding to be used when interpreting file names in the zip file. 98 | */ 99 | @property (nonatomic, assign) NSStringEncoding stringEncoding; 100 | 101 | /** an array of files that were successfully expanded. Available after calling UnzipFileTo:overWrite: */ 102 | @property (nonatomic, readonly) NSArray* unzippedFiles; 103 | 104 | -(id) initWithFileManager:(NSFileManager*) fileManager; 105 | 106 | -(BOOL) CreateZipFile2:(NSString*) zipFile; 107 | -(BOOL) CreateZipFile2:(NSString*) zipFile append:(BOOL)isAppend; 108 | -(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password; 109 | -(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password append:(BOOL)isAppend; 110 | -(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname; 111 | -(BOOL) addDataToZip:(NSData*) data fileAttributes:(NSDictionary *)attr newname:(NSString*) newname; 112 | -(BOOL) CloseZipFile2; 113 | 114 | -(BOOL) UnzipOpenFile:(NSString*) zipFile; 115 | -(BOOL) UnzipOpenFile:(NSString*) zipFile Password:(NSString*) password; 116 | -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite; 117 | -(NSDictionary *)UnzipFileToMemory;//To avoid memory issue, only use this method for small zip files. 118 | -(BOOL) UnzipCloseFile; 119 | 120 | // List the contents of the zip archive. must be called after UnzipOpenFile. 121 | // If zip file was appended with `CreateZipFile2:append:` or ``CreateZipFile2:Password:append:`, 122 | // `getZipFileContents` result won't be updated until re-unzip-open after close write handle (`CloseZipFile2` then `UnzipCloseFile` then (`UnzipOpenFile:` or `UnzipOpenFile:Password`) get called). 123 | -(NSArray*) getZipFileContents; 124 | 125 | @end 126 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/ZipArchive/minizip/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile 2 | 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | 8 | This code is a modified version of crypting code in Infozip distribution 9 | 10 | The encryption/decryption parts of this source code (as opposed to the 11 | non-echoing password parts) were originally written in Europe. The 12 | whole source package can be freely distributed, including from the USA. 13 | (Prior to January 2000, re-export from the US was a violation of US law.) 14 | 15 | This encryption code is a direct transcription of the algorithm from 16 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 17 | file (appnote.txt) is distributed with the PKZIP program (even in the 18 | version without encryption capabilities). 19 | 20 | If you don't need crypting in your application, just define symbols 21 | NOCRYPT and NOUNCRYPT. 22 | 23 | This code support the "Traditional PKWARE Encryption". 24 | 25 | The new AES encryption added on Zip format by Winzip (see the page 26 | http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong 27 | Encryption is not supported. 28 | */ 29 | 30 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 31 | 32 | /*********************************************************************** 33 | * Return the next byte in the pseudo-random sequence 34 | */ 35 | static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 36 | { 37 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 38 | * unpredictable manner on 16-bit systems; not a problem 39 | * with any known compiler so far, though */ 40 | 41 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 42 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 43 | } 44 | 45 | /*********************************************************************** 46 | * Update the encryption keys with the next byte of plain text 47 | */ 48 | static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 49 | { 50 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 51 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 52 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 53 | { 54 | register int keyshift = (int)((*(pkeys+1)) >> 24); 55 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 56 | } 57 | return c; 58 | } 59 | 60 | 61 | /*********************************************************************** 62 | * Initialize the encryption keys and the random header according to 63 | * the given password. 64 | */ 65 | static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 66 | { 67 | *(pkeys+0) = 305419896L; 68 | *(pkeys+1) = 591751049L; 69 | *(pkeys+2) = 878082192L; 70 | while (*passwd != '\0') { 71 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 72 | passwd++; 73 | } 74 | } 75 | 76 | #define zdecode(pkeys,pcrc_32_tab,c) \ 77 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 78 | 79 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 80 | (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 81 | 82 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 83 | 84 | #define RAND_HEAD_LEN 12 85 | /* "last resort" source for second part of crypt seed pattern */ 86 | # ifndef ZCR_SEED2 87 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 88 | # endif 89 | 90 | static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) 91 | const char *passwd; /* password string */ 92 | unsigned char *buf; /* where to write header */ 93 | int bufSize; 94 | unsigned long* pkeys; 95 | const unsigned long* pcrc_32_tab; 96 | unsigned long crcForCrypting; 97 | { 98 | int n; /* index in random header */ 99 | int t; /* temporary */ 100 | int c; /* random byte */ 101 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 102 | static unsigned calls = 0; /* ensure different random header each time */ 103 | 104 | if (bufSize<RAND_HEAD_LEN) 105 | return 0; 106 | 107 | /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the 108 | * output of rand() to get less predictability, since rand() is 109 | * often poorly implemented. 110 | */ 111 | if (++calls == 1) 112 | { 113 | srand((unsigned)(time(NULL) ^ ZCR_SEED2)); 114 | } 115 | init_keys(passwd, pkeys, pcrc_32_tab); 116 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 117 | { 118 | c = (rand() >> 7) & 0xff; 119 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 120 | } 121 | /* Encrypt random header (last two bytes is high word of crc) */ 122 | init_keys(passwd, pkeys, pcrc_32_tab); 123 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 124 | { 125 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 126 | } 127 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 128 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 129 | return n; 130 | } 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/ZipArchive/minizip/ioapi.c: -------------------------------------------------------------------------------- 1 | /* ioapi.c -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | */ 8 | 9 | #include <stdio.h> 10 | #include <stdlib.h> 11 | #include <string.h> 12 | 13 | #include "zlib.h" 14 | #include "ioapi.h" 15 | 16 | 17 | 18 | /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 19 | 20 | #ifndef SEEK_CUR 21 | #define SEEK_CUR 1 22 | #endif 23 | 24 | #ifndef SEEK_END 25 | #define SEEK_END 2 26 | #endif 27 | 28 | #ifndef SEEK_SET 29 | #define SEEK_SET 0 30 | #endif 31 | 32 | voidpf ZCALLBACK fopen_file_func OF(( 33 | voidpf opaque, 34 | const char* filename, 35 | int mode)); 36 | 37 | uLong ZCALLBACK fread_file_func OF(( 38 | voidpf opaque, 39 | voidpf stream, 40 | void* buf, 41 | uLong size)); 42 | 43 | uLong ZCALLBACK fwrite_file_func OF(( 44 | voidpf opaque, 45 | voidpf stream, 46 | const void* buf, 47 | uLong size)); 48 | 49 | long ZCALLBACK ftell_file_func OF(( 50 | voidpf opaque, 51 | voidpf stream)); 52 | 53 | long ZCALLBACK fseek_file_func OF(( 54 | voidpf opaque, 55 | voidpf stream, 56 | uLong offset, 57 | int origin)); 58 | 59 | int ZCALLBACK fclose_file_func OF(( 60 | voidpf opaque, 61 | voidpf stream)); 62 | 63 | int ZCALLBACK ferror_file_func OF(( 64 | voidpf opaque, 65 | voidpf stream)); 66 | 67 | 68 | voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) 69 | voidpf opaque; 70 | const char* filename; 71 | int mode; 72 | { 73 | FILE* file = NULL; 74 | const char* mode_fopen = NULL; 75 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 76 | mode_fopen = "rb"; 77 | else 78 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 79 | mode_fopen = "r+b"; 80 | else 81 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 82 | mode_fopen = "wb"; 83 | 84 | if ((filename!=NULL) && (mode_fopen != NULL)) 85 | file = fopen(filename, mode_fopen); 86 | return file; 87 | } 88 | 89 | 90 | uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) 91 | voidpf opaque; 92 | voidpf stream; 93 | void* buf; 94 | uLong size; 95 | { 96 | uLong ret; 97 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); 98 | return ret; 99 | } 100 | 101 | 102 | uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) 103 | voidpf opaque; 104 | voidpf stream; 105 | const void* buf; 106 | uLong size; 107 | { 108 | uLong ret; 109 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); 110 | return ret; 111 | } 112 | 113 | long ZCALLBACK ftell_file_func (opaque, stream) 114 | voidpf opaque; 115 | voidpf stream; 116 | { 117 | long ret; 118 | ret = ftell((FILE *)stream); 119 | return ret; 120 | } 121 | 122 | long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) 123 | voidpf opaque; 124 | voidpf stream; 125 | uLong offset; 126 | int origin; 127 | { 128 | int fseek_origin=0; 129 | long ret; 130 | switch (origin) 131 | { 132 | case ZLIB_FILEFUNC_SEEK_CUR : 133 | fseek_origin = SEEK_CUR; 134 | break; 135 | case ZLIB_FILEFUNC_SEEK_END : 136 | fseek_origin = SEEK_END; 137 | break; 138 | case ZLIB_FILEFUNC_SEEK_SET : 139 | fseek_origin = SEEK_SET; 140 | break; 141 | default: return -1; 142 | } 143 | ret = 0; 144 | fseek((FILE *)stream, offset, fseek_origin); 145 | return ret; 146 | } 147 | 148 | int ZCALLBACK fclose_file_func (opaque, stream) 149 | voidpf opaque; 150 | voidpf stream; 151 | { 152 | int ret; 153 | ret = fclose((FILE *)stream); 154 | return ret; 155 | } 156 | 157 | int ZCALLBACK ferror_file_func (opaque, stream) 158 | voidpf opaque; 159 | voidpf stream; 160 | { 161 | int ret; 162 | ret = ferror((FILE *)stream); 163 | return ret; 164 | } 165 | 166 | void fill_fopen_filefunc (pzlib_filefunc_def) 167 | zlib_filefunc_def* pzlib_filefunc_def; 168 | { 169 | pzlib_filefunc_def->zopen_file = fopen_file_func; 170 | pzlib_filefunc_def->zread_file = fread_file_func; 171 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 172 | pzlib_filefunc_def->ztell_file = ftell_file_func; 173 | pzlib_filefunc_def->zseek_file = fseek_file_func; 174 | pzlib_filefunc_def->zclose_file = fclose_file_func; 175 | pzlib_filefunc_def->zerror_file = ferror_file_func; 176 | pzlib_filefunc_def->opaque = NULL; 177 | } 178 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/ZipArchive/minizip/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | */ 8 | 9 | #ifndef _ZLIBIOAPI_H 10 | #define _ZLIBIOAPI_H 11 | 12 | 13 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 14 | #define ZLIB_FILEFUNC_SEEK_END (2) 15 | #define ZLIB_FILEFUNC_SEEK_SET (0) 16 | 17 | #define ZLIB_FILEFUNC_MODE_READ (1) 18 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 19 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 20 | 21 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 22 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 23 | 24 | 25 | #ifndef ZCALLBACK 26 | 27 | #if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 28 | #define ZCALLBACK CALLBACK 29 | #else 30 | #define ZCALLBACK 31 | #endif 32 | #endif 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 39 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 40 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 41 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 42 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 43 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 44 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 45 | 46 | typedef struct zlib_filefunc_def_s 47 | { 48 | open_file_func zopen_file; 49 | read_file_func zread_file; 50 | write_file_func zwrite_file; 51 | tell_file_func ztell_file; 52 | seek_file_func zseek_file; 53 | close_file_func zclose_file; 54 | testerror_file_func zerror_file; 55 | voidpf opaque; 56 | } zlib_filefunc_def; 57 | 58 | 59 | 60 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 61 | 62 | #define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) 63 | #define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) 64 | #define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) 65 | #define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) 66 | #define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) 67 | #define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) 68 | 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | 76 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/ZipArchive/minizip/mztools.c: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | /* Code */ 8 | #include <stdio.h> 9 | #include <stdlib.h> 10 | #include <string.h> 11 | #include "zlib.h" 12 | #include "unzip.h" 13 | 14 | #define READ_8(adr) ((unsigned char)*(adr)) 15 | #define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) 16 | #define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) 17 | 18 | #define WRITE_8(buff, n) do { \ 19 | *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ 20 | } while(0) 21 | #define WRITE_16(buff, n) do { \ 22 | WRITE_8((unsigned char*)(buff), n); \ 23 | WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ 24 | } while(0) 25 | #define WRITE_32(buff, n) do { \ 26 | WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ 27 | WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ 28 | } while(0) 29 | 30 | extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) 31 | const char* file; 32 | const char* fileOut; 33 | const char* fileOutTmp; 34 | uLong* nRecovered; 35 | uLong* bytesRecovered; 36 | { 37 | int err = Z_OK; 38 | FILE* fpZip = fopen(file, "rb"); 39 | FILE* fpOut = fopen(fileOut, "wb"); 40 | FILE* fpOutCD = fopen(fileOutTmp, "wb"); 41 | if (fpZip != NULL && fpOut != NULL) { 42 | int entries = 0; 43 | uLong totalBytes = 0; 44 | char header[30]; 45 | char filename[256]; 46 | char extra[1024]; 47 | int offset = 0; 48 | int offsetCD = 0; 49 | while ( fread(header, 1, 30, fpZip) == 30 ) { 50 | int currentOffset = offset; 51 | 52 | /* File entry */ 53 | if (READ_32(header) == 0x04034b50) { 54 | unsigned int version = READ_16(header + 4); 55 | unsigned int gpflag = READ_16(header + 6); 56 | unsigned int method = READ_16(header + 8); 57 | unsigned int filetime = READ_16(header + 10); 58 | unsigned int filedate = READ_16(header + 12); 59 | unsigned int crc = READ_32(header + 14); /* crc */ 60 | unsigned int cpsize = READ_32(header + 18); /* compressed size */ 61 | unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ 62 | unsigned int fnsize = READ_16(header + 26); /* file name length */ 63 | unsigned int extsize = READ_16(header + 28); /* extra field length */ 64 | filename[0] = extra[0] = '\0'; 65 | 66 | /* Header */ 67 | if (fwrite(header, 1, 30, fpOut) == 30) { 68 | offset += 30; 69 | } else { 70 | err = Z_ERRNO; 71 | break; 72 | } 73 | 74 | /* Filename */ 75 | if (fnsize > 0) { 76 | if (fread(filename, 1, fnsize, fpZip) == fnsize) { 77 | if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { 78 | offset += fnsize; 79 | } else { 80 | err = Z_ERRNO; 81 | break; 82 | } 83 | } else { 84 | err = Z_ERRNO; 85 | break; 86 | } 87 | } else { 88 | err = Z_STREAM_ERROR; 89 | break; 90 | } 91 | 92 | /* Extra field */ 93 | if (extsize > 0) { 94 | if (fread(extra, 1, extsize, fpZip) == extsize) { 95 | if (fwrite(extra, 1, extsize, fpOut) == extsize) { 96 | offset += extsize; 97 | } else { 98 | err = Z_ERRNO; 99 | break; 100 | } 101 | } else { 102 | err = Z_ERRNO; 103 | break; 104 | } 105 | } 106 | 107 | /* Data */ 108 | { 109 | int dataSize = cpsize; 110 | if (dataSize == 0) { 111 | dataSize = uncpsize; 112 | } 113 | if (dataSize > 0) { 114 | char* data = malloc(dataSize); 115 | if (data != NULL) { 116 | if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { 117 | if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { 118 | offset += dataSize; 119 | totalBytes += dataSize; 120 | } else { 121 | err = Z_ERRNO; 122 | } 123 | } else { 124 | err = Z_ERRNO; 125 | } 126 | free(data); 127 | if (err != Z_OK) { 128 | break; 129 | } 130 | } else { 131 | err = Z_MEM_ERROR; 132 | break; 133 | } 134 | } 135 | } 136 | 137 | /* Central directory entry */ 138 | { 139 | char header[46]; 140 | char* comment = ""; 141 | int comsize = (int) strlen(comment); 142 | WRITE_32(header, 0x02014b50); 143 | WRITE_16(header + 4, version); 144 | WRITE_16(header + 6, version); 145 | WRITE_16(header + 8, gpflag); 146 | WRITE_16(header + 10, method); 147 | WRITE_16(header + 12, filetime); 148 | WRITE_16(header + 14, filedate); 149 | WRITE_32(header + 16, crc); 150 | WRITE_32(header + 20, cpsize); 151 | WRITE_32(header + 24, uncpsize); 152 | WRITE_16(header + 28, fnsize); 153 | WRITE_16(header + 30, extsize); 154 | WRITE_16(header + 32, comsize); 155 | WRITE_16(header + 34, 0); /* disk # */ 156 | WRITE_16(header + 36, 0); /* int attrb */ 157 | WRITE_32(header + 38, 0); /* ext attrb */ 158 | WRITE_32(header + 42, currentOffset); 159 | /* Header */ 160 | if (fwrite(header, 1, 46, fpOutCD) == 46) { 161 | offsetCD += 46; 162 | 163 | /* Filename */ 164 | if (fnsize > 0) { 165 | if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { 166 | offsetCD += fnsize; 167 | } else { 168 | err = Z_ERRNO; 169 | break; 170 | } 171 | } else { 172 | err = Z_STREAM_ERROR; 173 | break; 174 | } 175 | 176 | /* Extra field */ 177 | if (extsize > 0) { 178 | if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { 179 | offsetCD += extsize; 180 | } else { 181 | err = Z_ERRNO; 182 | break; 183 | } 184 | } 185 | 186 | /* Comment field */ 187 | if (comsize > 0) { 188 | if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { 189 | offsetCD += comsize; 190 | } else { 191 | err = Z_ERRNO; 192 | break; 193 | } 194 | } 195 | 196 | 197 | } else { 198 | err = Z_ERRNO; 199 | break; 200 | } 201 | } 202 | 203 | /* Success */ 204 | entries++; 205 | 206 | } else { 207 | break; 208 | } 209 | } 210 | 211 | /* Final central directory */ 212 | { 213 | int entriesZip = entries; 214 | char header[22]; 215 | char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; 216 | int comsize = (int) strlen(comment); 217 | if (entriesZip > 0xffff) { 218 | entriesZip = 0xffff; 219 | } 220 | WRITE_32(header, 0x06054b50); 221 | WRITE_16(header + 4, 0); /* disk # */ 222 | WRITE_16(header + 6, 0); /* disk # */ 223 | WRITE_16(header + 8, entriesZip); /* hack */ 224 | WRITE_16(header + 10, entriesZip); /* hack */ 225 | WRITE_32(header + 12, offsetCD); /* size of CD */ 226 | WRITE_32(header + 16, offset); /* offset to CD */ 227 | WRITE_16(header + 20, comsize); /* comment */ 228 | 229 | /* Header */ 230 | if (fwrite(header, 1, 22, fpOutCD) == 22) { 231 | 232 | /* Comment field */ 233 | if (comsize > 0) { 234 | if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { 235 | err = Z_ERRNO; 236 | } 237 | } 238 | 239 | } else { 240 | err = Z_ERRNO; 241 | } 242 | } 243 | 244 | /* Final merge (file + central directory) */ 245 | fclose(fpOutCD); 246 | if (err == Z_OK) { 247 | fpOutCD = fopen(fileOutTmp, "rb"); 248 | if (fpOutCD != NULL) { 249 | int nRead; 250 | char buffer[8192]; 251 | while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { 252 | if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { 253 | err = Z_ERRNO; 254 | break; 255 | } 256 | } 257 | fclose(fpOutCD); 258 | } 259 | } 260 | 261 | /* Close */ 262 | fclose(fpZip); 263 | fclose(fpOut); 264 | 265 | /* Wipe temporary file */ 266 | (void)remove(fileOutTmp); 267 | 268 | /* Number of recovered entries */ 269 | if (err == Z_OK) { 270 | if (nRecovered != NULL) { 271 | *nRecovered = entries; 272 | } 273 | if (bytesRecovered != NULL) { 274 | *bytesRecovered = totalBytes; 275 | } 276 | } 277 | } else { 278 | err = Z_STREAM_ERROR; 279 | } 280 | return err; 281 | } 282 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/Third/ZipArchive/minizip/mztools.h: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | #ifndef _zip_tools_H 8 | #define _zip_tools_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #ifndef _ZLIB_H 15 | #include "zlib.h" 16 | #endif 17 | 18 | #include "unzip.h" 19 | 20 | /* Repair a ZIP file (missing central directory) 21 | file: file to recover 22 | fileOut: output file after recovery 23 | fileOutTmp: temporary file name used for recovery 24 | */ 25 | extern int ZEXPORT unzRepair(const char* file, 26 | const char* fileOut, 27 | const char* fileOutTmp, 28 | uLong* nRecovered, 29 | uLong* bytesRecovered); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/View/LSYBottomMenuView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYBottomMenuView.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/6/1. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import <UIKit/UIKit.h> 10 | #import "LSYRecordModel.h" 11 | @protocol LSYMenuViewDelegate; 12 | 13 | @interface LSYBottomMenuView : UIView 14 | @property (nonatomic,weak) id<LSYMenuViewDelegate>delegate; 15 | @property (nonatomic,strong) LSYRecordModel *readModel; 16 | @end 17 | 18 | @interface LSYThemeView : UIView 19 | 20 | @end 21 | 22 | @interface LSYReadProgressView : UIView 23 | -(void)title:(NSString *)title progress:(NSString *)progress; 24 | @end 25 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/View/LSYMagnifierView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYMagnifierView.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/6/12. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import <UIKit/UIKit.h> 10 | 11 | @interface LSYMagnifierView : UIView 12 | @property (nonatomic,weak) UIView *readView; 13 | @property (nonatomic) CGPoint touchPoint; 14 | @end 15 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/View/LSYMagnifierView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYMagnifierView.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/6/12. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYMagnifierView.h" 10 | 11 | @implementation LSYMagnifierView 12 | 13 | - (id)initWithFrame:(CGRect)frame { 14 | 15 | if (self = [super initWithFrame:CGRectMake(0, 0, 80, 80)]) { 16 | self.layer.borderColor = [[UIColor lightGrayColor] CGColor]; 17 | [self setBackgroundColor:[LSYReadConfig shareInstance].theme]; 18 | self.layer.borderWidth = 1; 19 | self.layer.cornerRadius = 40; 20 | self.layer.masksToBounds = YES; 21 | } 22 | return self; 23 | } 24 | - (void)setTouchPoint:(CGPoint)touchPoint { 25 | 26 | _touchPoint = touchPoint; 27 | self.center = CGPointMake(touchPoint.x, touchPoint.y - 70); 28 | [self setNeedsDisplay]; 29 | } 30 | - (void)drawRect:(CGRect)rect { 31 | 32 | CGContextRef context = UIGraphicsGetCurrentContext(); 33 | CGContextTranslateCTM(context, self.frame.size.width*0.5,self.frame.size.height*0.5); 34 | CGContextScaleCTM(context, 1.5, 1.5); 35 | CGContextTranslateCTM(context, -1 * (_touchPoint.x), -1 * (_touchPoint.y)); 36 | [self.readView.layer renderInContext:context]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/View/LSYMenuView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYMenuView.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/6/1. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import <UIKit/UIKit.h> 10 | #import "LSYRecordModel.h" 11 | #import "LSYTopMenuView.h" 12 | @class LSYMenuView; 13 | @class LSYBottomMenuView; 14 | @protocol LSYMenuViewDelegate <NSObject> 15 | @optional 16 | -(void)menuViewDidHidden:(LSYMenuView *)menu; 17 | -(void)menuViewDidAppear:(LSYMenuView *)menu; 18 | -(void)menuViewInvokeCatalog:(LSYBottomMenuView *)bottomMenu; 19 | -(void)menuViewJumpChapter:(NSUInteger)chapter page:(NSUInteger)page; 20 | -(void)menuViewFontSize:(LSYBottomMenuView *)bottomMenu; 21 | -(void)menuViewMark:(LSYTopMenuView *)topMenu; 22 | @end 23 | @interface LSYMenuView : UIView 24 | @property (nonatomic,weak) id<LSYMenuViewDelegate> delegate; 25 | @property (nonatomic,strong) LSYRecordModel *recordModel; 26 | @property (nonatomic,strong) LSYTopMenuView *topView; 27 | @property (nonatomic,strong) LSYBottomMenuView *bottomView; 28 | -(void)showAnimation:(BOOL)animation; 29 | -(void)hiddenAnimation:(BOOL)animation; 30 | @end 31 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/View/LSYMenuView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYMenuView.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/6/1. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYMenuView.h" 10 | #import "LSYTopMenuView.h" 11 | #import "LSYBottomMenuView.h" 12 | #define AnimationDelay 0.3f 13 | #define TopViewHeight 64.0f 14 | #define BottomViewHeight 200.0f 15 | @interface LSYMenuView ()<LSYMenuViewDelegate> 16 | 17 | @end 18 | @implementation LSYMenuView 19 | - (instancetype)initWithFrame:(CGRect)frame 20 | { 21 | self = [super initWithFrame:frame]; 22 | if (self) { 23 | [self setup]; 24 | } 25 | return self; 26 | } 27 | -(void)setup 28 | { 29 | self.backgroundColor = [UIColor clearColor]; 30 | [self addSubview:self.topView]; 31 | [self addSubview:self.bottomView]; 32 | [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenSelf)]]; 33 | } 34 | -(LSYTopMenuView *)topView 35 | { 36 | if (!_topView) { 37 | _topView = [[LSYTopMenuView alloc] init]; 38 | _topView.delegate = self; 39 | } 40 | return _topView; 41 | } 42 | -(LSYBottomMenuView *)bottomView 43 | { 44 | if (!_bottomView) { 45 | _bottomView = [[LSYBottomMenuView alloc] init]; 46 | _bottomView.delegate = self; 47 | } 48 | return _bottomView; 49 | } 50 | -(void)setRecordModel:(LSYRecordModel *)recordModel 51 | { 52 | _recordModel = recordModel; 53 | _bottomView.readModel = recordModel; 54 | } 55 | #pragma mark - LSYMenuViewDelegate 56 | 57 | -(void)menuViewInvokeCatalog:(LSYBottomMenuView *)bottomMenu 58 | { 59 | if ([self.delegate respondsToSelector:@selector(menuViewInvokeCatalog:)]) { 60 | [self.delegate menuViewInvokeCatalog:bottomMenu]; 61 | } 62 | } 63 | -(void)menuViewJumpChapter:(NSUInteger)chapter page:(NSUInteger)page 64 | { 65 | if ([self.delegate respondsToSelector:@selector(menuViewJumpChapter:page:)]) { 66 | [self.delegate menuViewJumpChapter:chapter page:page]; 67 | } 68 | } 69 | -(void)menuViewFontSize:(LSYBottomMenuView *)bottomMenu 70 | { 71 | if ([self.delegate respondsToSelector:@selector(menuViewFontSize:)]) { 72 | [self.delegate menuViewFontSize:bottomMenu]; 73 | } 74 | } 75 | -(void)menuViewMark:(LSYTopMenuView *)topMenu 76 | { 77 | if ([self.delegate respondsToSelector:@selector(menuViewMark:)]) { 78 | [self.delegate menuViewMark:topMenu]; 79 | } 80 | } 81 | #pragma mark - 82 | -(void)hiddenSelf 83 | { 84 | [self hiddenAnimation:YES]; 85 | } 86 | -(void)showAnimation:(BOOL)animation 87 | { 88 | self.hidden = NO; 89 | [UIView animateWithDuration:animation?AnimationDelay:0 animations:^{ 90 | _topView.frame = CGRectMake(0, 0, ViewSize(self).width, TopViewHeight); 91 | _bottomView.frame = CGRectMake(0, ViewSize(self).height-BottomViewHeight, ViewSize(self).width,BottomViewHeight); 92 | } completion:^(BOOL finished) { 93 | 94 | }]; 95 | if ([self.delegate respondsToSelector:@selector(menuViewDidAppear:)]) { 96 | [self.delegate menuViewDidAppear:self]; 97 | } 98 | } 99 | -(void)hiddenAnimation:(BOOL)animation 100 | { 101 | [UIView animateWithDuration:animation?AnimationDelay:0 animations:^{ 102 | _topView.frame = CGRectMake(0, -TopViewHeight, ViewSize(self).width, TopViewHeight); 103 | _bottomView.frame = CGRectMake(0, ViewSize(self).height, ViewSize(self).width,BottomViewHeight); 104 | } completion:^(BOOL finished) { 105 | self.hidden = YES; 106 | }]; 107 | if ([self.delegate respondsToSelector:@selector(menuViewDidHidden:)]) { 108 | [self.delegate menuViewDidHidden:self]; 109 | } 110 | } 111 | -(void)layoutSubviews 112 | { 113 | [super layoutSubviews]; 114 | 115 | if (@available(iOS 11.0, *)){ 116 | // do nothing. 117 | // looks the layout of view in iOS 11 is different with iOS 10. 118 | } else { 119 | _topView.frame = CGRectMake(0, -TopViewHeight, ViewSize(self).width,TopViewHeight); 120 | _bottomView.frame = CGRectMake(0, ViewSize(self).height, ViewSize(self).width,BottomViewHeight); 121 | } 122 | 123 | 124 | 125 | } 126 | @end 127 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/View/LSYTopMenuView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LSYTopMenuView.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/6/1. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import <UIKit/UIKit.h> 10 | @protocol LSYMenuViewDelegate; 11 | @interface LSYTopMenuView : UIView 12 | @property (nonatomic,assign) BOOL state; //(0--未保存过,1--保存过) 13 | @property (nonatomic,weak) id<LSYMenuViewDelegate>delegate; 14 | @end 15 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/View/LSYTopMenuView.m: -------------------------------------------------------------------------------- 1 | // 2 | // LSYTopMenuView.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/6/1. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "LSYTopMenuView.h" 10 | #import "LSYMenuView.h" 11 | @interface LSYTopMenuView () 12 | @property (nonatomic,strong) UIButton *back; 13 | @property (nonatomic,strong) UIButton *more; 14 | @end 15 | @implementation LSYTopMenuView 16 | - (instancetype)initWithFrame:(CGRect)frame 17 | { 18 | self = [super initWithFrame:frame]; 19 | if (self) { 20 | [self setup]; 21 | } 22 | return self; 23 | } 24 | -(void)setup 25 | { 26 | [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8]]; 27 | [self addSubview:self.back]; 28 | [self addSubview:self.more]; 29 | } 30 | -(void)setState:(BOOL)state 31 | { 32 | _state = state; 33 | if (state) { 34 | [_more setImage:[[UIImage imageNamed:@"sale_discount_yellow"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal]; 35 | return; 36 | } 37 | [_more setImage:[[UIImage imageNamed:@"sale_discount_yellow"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]forState:UIControlStateNormal]; 38 | } 39 | -(UIButton *)back 40 | { 41 | if (!_back) { 42 | _back = [LSYReadUtilites commonButtonSEL:@selector(backView) target:self]; 43 | [_back setImage:[UIImage imageNamed:@"bg_back_white"] forState:UIControlStateNormal]; 44 | } 45 | return _back; 46 | } 47 | -(UIButton *)more 48 | { 49 | if (!_more) { 50 | _more = [LSYReadUtilites commonButtonSEL:@selector(moreOption) target:self]; 51 | [_more setImage:[[UIImage imageNamed:@"sale_discount_yellow"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]forState:UIControlStateNormal]; 52 | [_more setImageEdgeInsets:UIEdgeInsetsMake(7.5, 12.5, 7.5, 12.5)]; 53 | } 54 | return _more; 55 | } 56 | -(void)moreOption 57 | { 58 | if ([self.delegate respondsToSelector:@selector(menuViewMark:)]) { 59 | [self.delegate menuViewMark:self]; 60 | } 61 | } 62 | -(void)backView 63 | { 64 | [[LSYReadUtilites getCurrentVC] dismissViewControllerAnimated:YES completion:nil]; 65 | } 66 | -(void)layoutSubviews 67 | { 68 | [super layoutSubviews]; 69 | _back.frame = CGRectMake(0, 24, 40, 40); 70 | _more.frame = CGRectMake(ViewSize(self).width-50, 24, 40, 40); 71 | } 72 | /* 73 | // Only override drawRect: if you perform custom drawing. 74 | // An empty implementation adversely affects performance during animation. 75 | - (void)drawRect:(CGRect)rect { 76 | // Drawing code 77 | } 78 | */ 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/Reader/View/bt_tjcp_no@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/Reader/View/bt_tjcp_no@2x.png -------------------------------------------------------------------------------- /LSYReader/LSYReader/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import <UIKit/UIKit.h> 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "LSYReadViewController.h" 11 | #import "LSYReadPageViewController.h" 12 | #import "LSYReadUtilites.h" 13 | #import "LSYReadModel.h" 14 | @interface ViewController () 15 | @property (weak, nonatomic) IBOutlet UIButton *begin; 16 | @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activity; 17 | @property (weak, nonatomic) IBOutlet UIButton *beginEpub; 18 | @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *epubActivity; 19 | 20 | @end 21 | 22 | @implementation ViewController 23 | 24 | - (void)viewDidLoad { 25 | [super viewDidLoad]; 26 | _activity.hidesWhenStopped = YES; 27 | _epubActivity.hidesWhenStopped = YES; 28 | } 29 | 30 | - (IBAction)begin:(id)sender { 31 | [_activity startAnimating]; 32 | [_begin setTitle:@"" forState:UIControlStateNormal]; 33 | [_beginEpub setEnabled:NO]; 34 | LSYReadPageViewController *pageView = [[LSYReadPageViewController alloc] init]; 35 | NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"mdjyml"withExtension:@"txt"]; 36 | pageView.resourceURL = fileURL; //文件位置 37 | 38 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ 39 | 40 | pageView.model = [LSYReadModel getLocalModelWithURL:fileURL]; 41 | 42 | dispatch_async(dispatch_get_main_queue(), ^{ 43 | [_activity stopAnimating]; 44 | [_begin setTitle:@"Beign txt Read" forState:UIControlStateNormal]; 45 | [_beginEpub setEnabled:YES]; 46 | 47 | [self presentViewController:pageView animated:YES completion:nil]; 48 | }); 49 | }); 50 | 51 | 52 | 53 | 54 | } 55 | - (IBAction)beginEPub:(id)sender { 56 | [_epubActivity startAnimating]; 57 | [_beginEpub setTitle:@"" forState:UIControlStateNormal]; 58 | [_beginEpub setEnabled:NO]; 59 | LSYReadPageViewController *pageView = [[LSYReadPageViewController alloc] init]; 60 | NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"细说明朝"withExtension:@"epub"]; 61 | pageView.resourceURL = fileURL; //文件位置 62 | 63 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ 64 | 65 | pageView.model = [LSYReadModel getLocalModelWithURL:fileURL]; 66 | 67 | dispatch_async(dispatch_get_main_queue(), ^{ 68 | [_epubActivity stopAnimating]; 69 | [_beginEpub setTitle:@"Beign epub Read" forState:UIControlStateNormal]; 70 | [_beginEpub setEnabled:YES]; 71 | 72 | [self presentViewController:pageView animated:YES completion:nil]; 73 | }); 74 | }); 75 | } 76 | 77 | - (void)didReceiveMemoryWarning { 78 | [super didReceiveMemoryWarning]; 79 | // Dispose of any resources that can be recreated. 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // LSYReader 4 | // 5 | // Created by Labanotation on 16/5/30. 6 | // Copyright © 2016年 okwei. All rights reserved. 7 | // 8 | 9 | #import <UIKit/UIKit.h> 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LSYReader/LSYReader/mdjyml.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/LSYReader/mdjyml.txt -------------------------------------------------------------------------------- /LSYReader/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Inspirelife96/Reader/37bdfc095e23685657c62728c2c8a88609d35b23/LSYReader/demo.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##Reader 2 | --- 3 | 基于`Core Text`实现的iOS客户端的`电子书阅读器`。</br> 4 | **支持ePub与text格式** 5 | 6 | --- 7 | 8 | ###2016.10.02 更新 9 | 针对text小说的bug fix。 10 | 11 | 1. 当字体变化时,小说有时候不会自动调整界面。 12 | 2. 当字体变化时,还有小说的书签,笔记定位不准确,甚至程序崩溃。3. 13 | 14 | 大概思路: 15 | 16 | 1. 当字体变化时,所有小说的章节都会基于新的字体重新调整,分页等。 17 | 2. 记录笔记/书签文字开始位置的在整个章节中的下标位置,笔记/书签定位时,基于当前的字体分页,看当前的下标位置是否坐落在哪一页中,然后跳转到那一页。 18 | 19 | 20 | --- 21 | 22 | 23 | 24 | ###2016.06.16 更新 25 | **添加对ePub格式的支持** 26 | 27 | --- 28 | **部分功能实现效果**</br> 29 | ![](https://github.com/GGGHub/Reader/blob/master/LSYReader/demo.gif "部分功能")<br> 30 | --- 31 | 32 | **关于Reader**</br> 33 | 34 | 1. 可以自动提取章节并生成目录 35 | 2. 选取一段文字可进行复制,做笔记等功能 36 | 3. 保存阅读进度,即使退出应用也可以继续之前的阅读 37 | 4. 更改字体大小,进度跳转,主题更换等功能 38 | 5. 支持`txt`与`ePub`格式的电子书文件 39 | 40 | --- 41 | ##安装与使用 42 | ###安装 43 | 1. 将`Reader`目录下的所有文件都添加到工程中</br> 44 | 2. 由于解压`ePub`文件,需要用到开源的`.c文件`用于解压缩。所以使用时如果项目中有`.pch文件`参考本项目中`.pch`文件写法</br> 45 | ```c 46 | #ifdef __OBJC__ 47 | //在.pch中这里写引用的.h文件与宏 48 | #endif 49 | ``` 50 | 3.需要导入`libz.tbd`库 51 | 52 | ###使用 53 | text文件</br> 54 | ```objective-c 55 | LSYReadPageViewController *pageView = [[LSYReadPageViewController alloc] init]; 56 | NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"mdjyml"withExtension:@"txt"]; 57 | pageView.resourceURL = fileURL; //文件位置 58 | pageView.model = [LSYReadModel getLocalModelWithURL:fileURL]; //阅读模型 59 | [self presentViewController:pageView animated:YES completion:nil]; 60 | ``` 61 | ePub文件</br> 62 | ```objective-c 63 | LSYReadPageViewController *pageView = [[LSYReadPageViewController alloc] init]; 64 | NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"细说明朝"withExtension:@"epub"]; 65 | pageView.resourceURL = fileURL; //文件位置 66 | pageView.model = [LSYReadModel getLocalModelWithURL:fileURL]; //阅读模型 67 | [self presentViewController:pageView animated:YES completion:nil]; 68 | ``` 69 | 70 | ###提示 71 | **之前安装过的下载最新版,应把之前安装的卸载后再安装** 72 | 73 | ###说明 74 | 对于有图片和定制样式的epub文件只显示纯文本信息,因为对epub每个章节的html文件直接转成字符串来处理,css样式与epub自带的本地图片没有做处理。 75 | --------------------------------------------------------------------------------