Update ios code for version 0.8
This commit is contained in:
101
src/ios/APPPrinterLayout.m
Normal file
101
src/ios/APPPrinterLayout.m
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#import "APPPrinterLayout.h"
|
||||
|
||||
@implementation APPPrinterLayout
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Init
|
||||
|
||||
- (id) initWithDictionary:(NSDictionary *)spec
|
||||
{
|
||||
self = [self init];
|
||||
|
||||
NSDictionary* insests = spec[@"padding"];
|
||||
double maxWidth = [spec[@"maxWidth"] doubleValue];
|
||||
double maxHeight = [spec[@"maxHeight"] doubleValue];
|
||||
double dots = [self pointsPerUnit:spec[@"unit"]];
|
||||
|
||||
_contentInsets = UIEdgeInsetsMake(dots * [insests[@"top"] doubleValue],
|
||||
dots * [insests[@"left"] doubleValue],
|
||||
dots * [insests[@"bottom"] doubleValue],
|
||||
dots * [insests[@"right"] doubleValue]);
|
||||
|
||||
_maximumContentWidth = dots * maxWidth;
|
||||
|
||||
_maximumContentHeight = dots * maxHeight;
|
||||
|
||||
_pageIndex = [spec[@"page"] integerValue];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Public
|
||||
|
||||
+ (UIPrintFormatter *) configureFormatter:(UIPrintFormatter *)formatter withLayoutFromDictionary:(NSDictionary *)spec
|
||||
{
|
||||
id layout = [[self alloc] initWithDictionary:spec];
|
||||
|
||||
[layout configureFormatter:formatter];
|
||||
|
||||
return formatter;
|
||||
}
|
||||
|
||||
- (void) configureFormatter:(UIPrintFormatter *)formatter
|
||||
{
|
||||
if (_maximumContentHeight)
|
||||
{
|
||||
formatter.maximumContentHeight = _maximumContentHeight;
|
||||
}
|
||||
|
||||
if (_maximumContentWidth)
|
||||
{
|
||||
formatter.maximumContentWidth = _maximumContentWidth;
|
||||
}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user