Support style attributes for simple text formatter
This commit is contained in:
parent
e1405e914b
commit
22e8d95128
@ -21,10 +21,8 @@
|
||||
|
||||
@interface APPPrinterLayout : NSObject
|
||||
|
||||
+ (UIPrintFormatter *) configureFormatter:(UIPrintFormatter *)formatter withLayoutFromDictionary:(NSDictionary *)layout;
|
||||
+ (UIPrintFormatter *) configureFormatter:(UIPrintFormatter *)formatter withLayoutFromDictionary:(nullable NSDictionary *)layoutSpec withStyleFromDictionary:(nullable NSDictionary *)styleSpec;
|
||||
|
||||
// The index of the page for where to apply the layout.
|
||||
@property(nonatomic) NSInteger pageIndex;
|
||||
// The margins for each printed page.
|
||||
@property(nonatomic) UIEdgeInsets contentInsets;
|
||||
// The maximum height of the content area.
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "APPPrinterLayout.h"
|
||||
#include "APPPrinterStyle.h"
|
||||
#include "APPPrinterUnit.h"
|
||||
|
||||
@implementation APPPrinterLayout
|
||||
@ -27,10 +28,12 @@
|
||||
#pragma mark -
|
||||
#pragma mark Init
|
||||
|
||||
- (id) initWithDictionary:(NSDictionary *)spec
|
||||
- (id) initWithDictionary:(nullable NSDictionary *)spec
|
||||
{
|
||||
self = [self init];
|
||||
|
||||
if (!spec) return self;
|
||||
|
||||
NSDictionary* insests = spec[@"padding"];
|
||||
double maxWidth = [spec[@"maxWidth"] doubleValue];
|
||||
double maxHeight = [spec[@"maxHeight"] doubleValue];
|
||||
@ -45,20 +48,26 @@
|
||||
|
||||
_maximumContentHeight = dots * maxHeight;
|
||||
|
||||
_pageIndex = [spec[@"page"] integerValue];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Public
|
||||
|
||||
+ (UIPrintFormatter *) configureFormatter:(UIPrintFormatter *)formatter withLayoutFromDictionary:(NSDictionary *)spec
|
||||
+ (UIPrintFormatter *) configureFormatter:(UIPrintFormatter *)formatter
|
||||
withLayoutFromDictionary:(NSDictionary *)layoutSpec
|
||||
withStyleFromDictionary:(nullable NSDictionary *)styleSpec
|
||||
{
|
||||
id layout = [[self alloc] initWithDictionary:spec];
|
||||
id layout = [[self alloc] initWithDictionary:layoutSpec];
|
||||
|
||||
[layout configureFormatter:formatter];
|
||||
|
||||
if (styleSpec && ![formatter isKindOfClass:UIMarkupTextPrintFormatter.class])
|
||||
{
|
||||
[layout configureTextFormatter:(UISimpleTextPrintFormatter *)formatter
|
||||
withStyleFromDictionary:styleSpec];
|
||||
}
|
||||
|
||||
return formatter;
|
||||
}
|
||||
|
||||
@ -77,4 +86,15 @@
|
||||
formatter.perPageContentInsets = _contentInsets;
|
||||
}
|
||||
|
||||
- (void) configureTextFormatter:(UISimpleTextPrintFormatter *)formatter
|
||||
withStyleFromDictionary:(NSDictionary *)spec
|
||||
{
|
||||
APPPrinterStyle *style = [[APPPrinterStyle alloc]
|
||||
initWithDictionary:spec];
|
||||
|
||||
formatter.font = style.font;
|
||||
formatter.color = style.color;
|
||||
formatter.textAlignment = style.textAlignment;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -37,18 +37,15 @@
|
||||
|
||||
- (instancetype) initWithDictionary:(NSDictionary *)spec formatter:(UIPrintFormatter *)formatter
|
||||
{
|
||||
NSDictionary* layout = spec[@"layout"];
|
||||
NSDictionary* header = spec[@"header"];
|
||||
NSDictionary* footer = spec[@"footer"];
|
||||
double dots = 0;
|
||||
|
||||
self = [self init];
|
||||
|
||||
if (layout)
|
||||
{
|
||||
[APPPrinterLayout configureFormatter:formatter
|
||||
withLayoutFromDictionary:layout];
|
||||
}
|
||||
withLayoutFromDictionary:spec[@"layout"]
|
||||
withStyleFromDictionary:spec[@"style"]];
|
||||
|
||||
[self addPrintFormatter:formatter startingAtPageAtIndex:0];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user