diff --git a/plugin.xml b/plugin.xml index 2a481b6..e1ec912 100644 --- a/plugin.xml +++ b/plugin.xml @@ -78,6 +78,9 @@ + + + diff --git a/src/ios/APPPrinter.m b/src/ios/APPPrinter.m index 426728b..13fc84c 100755 --- a/src/ios/APPPrinter.m +++ b/src/ios/APPPrinter.m @@ -19,9 +19,9 @@ under the License. */ -#import "APPPrinter.h" -#import "APPPrinterItem.h" -#import "APPPrinterPaper.h" +#include "APPPrinter.h" +#include "APPPrinterItem.h" +#include "APPPrinterPaper.h" #include "APPPrinterRenderer.h" #include "UIPrintInteractionController+APPPrinter.h" diff --git a/src/ios/APPPrinterInfo.m b/src/ios/APPPrinterInfo.m index 3744f06..05eb3e0 100644 --- a/src/ios/APPPrinterInfo.m +++ b/src/ios/APPPrinterInfo.m @@ -19,7 +19,7 @@ under the License. */ -#import "APPPrinterInfo.h" +#include "APPPrinterInfo.h" @implementation APPPrinterInfo diff --git a/src/ios/APPPrinterItem.m b/src/ios/APPPrinterItem.m index 60ad14d..96646af 100644 --- a/src/ios/APPPrinterItem.m +++ b/src/ios/APPPrinterItem.m @@ -19,7 +19,7 @@ under the License. */ -#import "APPPrinterItem.h" +#include "APPPrinterItem.h" @implementation APPPrinterItem diff --git a/src/ios/APPPrinterLayout.m b/src/ios/APPPrinterLayout.m index 3617aaf..a1cae01 100644 --- a/src/ios/APPPrinterLayout.m +++ b/src/ios/APPPrinterLayout.m @@ -19,7 +19,8 @@ under the License. */ -#import "APPPrinterLayout.h" +#include "APPPrinterLayout.h" +#include "APPPrinterUnit.h" @implementation APPPrinterLayout @@ -33,7 +34,7 @@ NSDictionary* insests = spec[@"padding"]; double maxWidth = [spec[@"maxWidth"] doubleValue]; double maxHeight = [spec[@"maxHeight"] doubleValue]; - double dots = [self pointsPerUnit:spec[@"unit"]]; + double dots = [APPPrinterUnit convert:spec[@"unit"]]; _contentInsets = UIEdgeInsetsMake(dots * [insests[@"top"] doubleValue], dots * [insests[@"left"] doubleValue], @@ -76,26 +77,4 @@ formatter.perPageContentInsets = _contentInsets; } -#pragma mark - -#pragma mark Private - -- (double) pointsPerUnit:(NSString *)unit -{ - if ([unit isEqualToString:@"in"]) - return 72.0; - - if ([unit isEqualToString:@"mm"]) - return 72.0 / 25.4; - - if ([unit isEqualToString:@"cm"]) - return 72.0 / 2.54; - - if (![unit isEqualToString:@"pp"]) - { - NSLog(@"[cordova-plugin-printer] unit not recogniced: %@", unit); - } - - return 1.0; -} - @end diff --git a/src/ios/APPPrinterPaper.m b/src/ios/APPPrinterPaper.m index 5ef3ae5..2758e16 100644 --- a/src/ios/APPPrinterPaper.m +++ b/src/ios/APPPrinterPaper.m @@ -19,7 +19,8 @@ under the License. */ -#import "APPPrinterPaper.h" +#include "APPPrinterPaper.h" +#include "APPPrinterUnit.h" @implementation APPPrinterPaper @@ -30,7 +31,7 @@ { self = [self init]; - double dots = [self pointsPerUnit:spec[@"unit"]]; + double dots = [APPPrinterUnit convert:spec[@"unit"]]; double length = [spec[@"length"] doubleValue]; double height = [spec[@"height"] doubleValue]; double width = [spec[@"width"] doubleValue]; @@ -57,26 +58,4 @@ return paper; } -#pragma mark - -#pragma mark Private - -- (double) pointsPerUnit:(NSString*)unit -{ - if ([unit isEqualToString:@"in"]) - return 72.0; - - if ([unit isEqualToString:@"mm"]) - return 72.0 / 25.4; - - if ([unit isEqualToString:@"cm"]) - return 72.0 / 2.54; - - if (![unit isEqualToString:@"pp"]) - { - NSLog(@"[cordova-plugin-printer] unit not recogniced: %@", unit); - } - - return 1.0; -} - @end diff --git a/src/ios/APPPrinterRenderer.m b/src/ios/APPPrinterRenderer.m index c67c065..cf71a59 100644 --- a/src/ios/APPPrinterRenderer.m +++ b/src/ios/APPPrinterRenderer.m @@ -21,6 +21,7 @@ #include "APPPrinterLayout.h" #include "APPPrinterRenderer.h" +#include "APPPrinterUnit.h" @implementation APPPrinterRenderer @@ -46,13 +47,13 @@ if (header) { - dots = [self pointsPerUnit:header[@"unit"]]; + dots = [APPPrinterUnit convert:header[@"unit"]]; self.headerHeight = dots * [header[@"height"] doubleValue]; } if (footer) { - dots = [self pointsPerUnit:header[@"unit"]]; + dots = [APPPrinterUnit convert:header[@"unit"]]; self.footerHeight = dots * [footer[@"height"] doubleValue]; } @@ -94,23 +95,4 @@ [footer drawInRect:rect withAttributes:attrs]; } -- (double) pointsPerUnit:(NSString*)unit -{ - if ([unit isEqualToString:@"in"]) - return 72.0; - - if ([unit isEqualToString:@"mm"]) - return 72.0 / 25.4; - - if ([unit isEqualToString:@"cm"]) - return 72.0 / 2.54; - - if (![unit isEqualToString:@"pp"]) - { - NSLog(@"[cordova-plugin-printer] unit not recogniced: %@", unit); - } - - return 1.0; -} - @end diff --git a/src/ios/APPPrinterUnit.h b/src/ios/APPPrinterUnit.h new file mode 100644 index 0000000..12b5f07 --- /dev/null +++ b/src/ios/APPPrinterUnit.h @@ -0,0 +1,26 @@ +/* + Copyright 2013 appPlant GmbH + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +@interface APPPrinterUnit : NSObject + ++ (double) convert:(NSString *)unit; + +@end diff --git a/src/ios/APPPrinterUnit.m b/src/ios/APPPrinterUnit.m new file mode 100644 index 0000000..88f3dee --- /dev/null +++ b/src/ios/APPPrinterUnit.m @@ -0,0 +1,45 @@ +/* + Copyright 2013 appPlant GmbH + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +#include "APPPrinterUnit.h" + +@implementation APPPrinterUnit + ++ (double) convert:(NSString *)unit +{ + if ([unit isEqualToString:@"in"]) + return 72.0; + + if ([unit isEqualToString:@"mm"]) + return 72.0 / 25.4; + + if ([unit isEqualToString:@"cm"]) + return 72.0 / 2.54; + + if (![unit isEqualToString:@"pp"]) + { + NSLog(@"[cordova-plugin-printer] unit not recogniced: %@", unit); + } + + return 1.0; +} + +@end diff --git a/src/ios/UIPrintInteractionController+APPPrinter.m b/src/ios/UIPrintInteractionController+APPPrinter.m index 1729ef6..d9b4e89 100644 --- a/src/ios/UIPrintInteractionController+APPPrinter.m +++ b/src/ios/UIPrintInteractionController+APPPrinter.m @@ -22,7 +22,7 @@ #include "APPPrinterInfo.h" #include "UIPrintInteractionController+APPPrinter.h" -#import +#include @implementation UIPrintInteractionController (APPPrinter)