diff --git a/src/ios/APPPrinterLayout.h b/src/ios/APPPrinterLayout.h index 346417f..73a783f 100644 --- a/src/ios/APPPrinterLayout.h +++ b/src/ios/APPPrinterLayout.h @@ -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. diff --git a/src/ios/APPPrinterLayout.m b/src/ios/APPPrinterLayout.m index a1cae01..75367b7 100644 --- a/src/ios/APPPrinterLayout.m +++ b/src/ios/APPPrinterLayout.m @@ -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 diff --git a/src/ios/APPPrinterRenderer.m b/src/ios/APPPrinterRenderer.m index 4386b25..5b5ed95 100644 --- a/src/ios/APPPrinterRenderer.m +++ b/src/ios/APPPrinterRenderer.m @@ -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]; - } + [APPPrinterLayout configureFormatter:formatter + withLayoutFromDictionary:spec[@"layout"] + withStyleFromDictionary:spec[@"style"]]; [self addPrintFormatter:formatter startingAtPageAtIndex:0];