Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing support #672

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
691e4c1
Initial commit
May 3, 2016
a170764
Show UIPrintInteractionController on Learn More tap
May 3, 2016
7586e5a
Revert changes in ORKTaskViewController
May 3, 2016
b9cf4b1
Added isAnswerEmpty method to ORKResult
May 3, 2016
22d2efc
PR changes
May 4, 2016
9de872a
Made ORKHTMLPrintFormatter a subclass of UIMarkupTextPrintFormatter
May 4, 2016
7d62cce
PR changes
May 4, 2016
c733919
Added html header/footer support
May 6, 2016
9d613f3
PR changes
May 6, 2016
0689741
PR changes
May 6, 2016
a9e1b92
PR changes
May 7, 2016
39b9fe7
Added image scaling
May 7, 2016
35d50d6
PR changes
May 7, 2016
972c442
PR changes
May 7, 2016
f888bf0
PR changes
May 7, 2016
e5ac42c
PR changes
May 7, 2016
ac3be2e
PR changes
May 7, 2016
1e964c7
Renamed PrintFormatter and PrintPageRenderer
May 7, 2016
6b95520
PR Changes
May 10, 2016
30b7aaa
PR changes
May 12, 2016
ae67fc8
PR changes
May 13, 2016
3fbdeba
PR updates
May 28, 2016
c1dd180
PR updates
May 28, 2016
385dc49
Remove header/footer print formatters
Jun 9, 2016
58751ad
Merge branch 'master' into printing
Jul 27, 2016
bfcf5f8
PR changes
Jul 27, 2016
166d10f
PR changes
Aug 10, 2016
b327462
PR changes
Aug 14, 2016
c379008
PR changes
Aug 16, 2016
9c6be9f
PR changes
Aug 17, 2016
02a4d61
PR changes
Aug 17, 2016
dfa5732
Merge branch 'master' into printing
Aug 17, 2016
d61f623
PR changes
Aug 17, 2016
950628d
PR changes
Aug 17, 2016
7218a52
Merge branch 'videoInstructionStep' into printing
Aug 17, 2016
1d27460
PR changes
Aug 17, 2016
10f009a
PR changes
Aug 17, 2016
ad49bac
PR changes
Aug 17, 2016
62fcc2e
PR changes
Aug 17, 2016
5c933e9
PR changes
Aug 17, 2016
e20e2c6
Fixing merge
Aug 21, 2016
06612ad
PR changes
Aug 21, 2016
17135e1
PR changes
Aug 21, 2016
57ba24d
PR changes
Aug 21, 2016
ff3c2e0
PR changes
Aug 21, 2016
07b4c0c
PR changes
Aug 21, 2016
9ba66a1
PR changes
Aug 24, 2016
3bd16da
Merge remote-tracking branch 'apple/master' into printing
Aug 24, 2016
ef07461
PR changes
Aug 24, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 44 additions & 8 deletions ResearchKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ResearchKit/Common/ORKAnswerFormat.m
Expand Up @@ -1040,7 +1040,7 @@ + (BOOL)supportsSecureCoding {
}

- (NSString *)stringForAnswer:(id)answer {
return ORKTimeOfDayStringFromComponents(answer);
return answer ? ORKTimeOfDayStringFromComponents(answer) : nil;
}

@end
Expand Down
14 changes: 14 additions & 0 deletions ResearchKit/Common/ORKHelpers.m
Expand Up @@ -89,6 +89,20 @@ id findInArrayByKey(NSArray * array, NSString *key, id value) {
return nil;
}

NSString *ORKLocalizedStringFromDate(NSDate *date) {
if (!date) {
return @"";
}
static NSDateFormatter *formatter = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
formatter = [NSDateFormatter new];
formatter.dateStyle = NSDateFormatterShortStyle;
formatter.timeStyle = NSDateFormatterMediumStyle;
});
return [formatter stringFromDate:date];
}

NSString *ORKStringFromDateISO8601(NSDate *date) {
static NSDateFormatter *formatter = nil;
static dispatch_once_t onceToken;
Expand Down
4 changes: 4 additions & 0 deletions ResearchKit/Common/ORKHelpers_Internal.h
Expand Up @@ -158,6 +158,10 @@ UIColor *ORKRGBA(uint32_t x, CGFloat alpha);

id findInArrayByKey(NSArray * array, NSString *key, id value);

NSString *ORKLocalizedStringFromDate(NSDate *date);
NSString *ORKStringFromDateISO8601(NSDate *date);
NSDate *ORKDateFromStringISO8601(NSString *string);

NSString *ORKSignatureStringFromDate(NSDate *date);

NSURL *ORKCreateRandomBaseURL();
Expand Down
Expand Up @@ -34,7 +34,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface ORKHTMLPDFWriter : NSObject
@interface ORKPDFWriter : NSObject

- (void)writePDFFromHTML:(NSString *)html withCompletionBlock:(void (^)(NSData *data, NSError *error))completionBlock;

Expand Down
Expand Up @@ -29,7 +29,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*/


#import "ORKHTMLPDFWriter.h"
#import "ORKPDFWriter.h"

#import "ORKHelpers_Internal.h"

Expand Down Expand Up @@ -83,7 +83,7 @@ - (void)drawFooterForPageAtIndex:(NSInteger)pageIndex
@end


@interface ORKHTMLPDFWriter () <UIWebViewDelegate> {
@interface ORKPDFWriter () <UIWebViewDelegate> {
id _selfRetain;
}

Expand All @@ -97,7 +97,7 @@ @interface ORKHTMLPDFWriter () <UIWebViewDelegate> {
@end


@implementation ORKHTMLPDFWriter
@implementation ORKPDFWriter

static const CGFloat HeaderHeight = 25.0;
static const CGFloat FooterHeight = 25.0;
Expand All @@ -106,7 +106,7 @@ @implementation ORKHTMLPDFWriter
- (void)writePDFFromHTML:(NSString *)html withCompletionBlock:(void (^)(NSData *data, NSError *error))completionBlock {

_pageMargins = UIEdgeInsetsMake(PageEdge, PageEdge, PageEdge, PageEdge);
_pageSize = [ORKHTMLPDFWriter defaultPageSize];
_pageSize = [ORKPDFWriter defaultPageSize];

_data = nil;
_error = nil;
Expand Down
7 changes: 7 additions & 0 deletions ResearchKit/Common/ORKResult.h
Expand Up @@ -856,6 +856,13 @@ ORK_CLASS_AVAILABLE
*/
@property (nonatomic) ORKQuestionType questionType;

/**
A Boolean value indicating whether the result of a question step is empty.

@return YES if no answer has been given, otherwise NO.
*/
- (BOOL) isAnswerEmpty;

@end


Expand Down
4 changes: 4 additions & 0 deletions ResearchKit/Common/ORKResult.m
Expand Up @@ -1299,6 +1299,10 @@ - (NSString *)descriptionWithNumberOfPaddingSpaces:(NSUInteger)numberOfPaddingSp
return [description copy];
}

- (BOOL)isAnswerEmpty {
return ORKIsAnswerEmpty(self.answer);
}

@end


Expand Down
6 changes: 3 additions & 3 deletions ResearchKit/Consent/ORKConsentDocument.m
Expand Up @@ -40,7 +40,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#import "ORKConsentSectionFormatter.h"
#import "ORKConsentSignature.h"
#import "ORKConsentSignatureFormatter.h"
#import "ORKHTMLPDFWriter.h"
#import "ORKPDFWriter.h"

#import "ORKHelpers_Internal.h"
#import "ORKErrors.h"
Expand All @@ -53,12 +53,12 @@ @implementation ORKConsentDocument {
#pragma mark - Initializers

- (instancetype)init {
return [self initWithHTMLPDFWriter:[[ORKHTMLPDFWriter alloc] init]
return [self initWithPDFWriter:[[ORKPDFWriter alloc] init]
consentSectionFormatter:[[ORKConsentSectionFormatter alloc] init]
consentSignatureFormatter:[[ORKConsentSignatureFormatter alloc] init]];
}

- (instancetype)initWithHTMLPDFWriter:(ORKHTMLPDFWriter *)writer
- (instancetype)initWithPDFWriter:(ORKPDFWriter *)writer
consentSectionFormatter:(ORKConsentSectionFormatter *)sectionFormatter
consentSignatureFormatter:(ORKConsentSignatureFormatter *)signatureFormatter{
if (self = [super init]) {
Expand Down
4 changes: 2 additions & 2 deletions ResearchKit/Consent/ORKConsentDocument_Internal.h
Expand Up @@ -35,13 +35,13 @@

NS_ASSUME_NONNULL_BEGIN

@class ORKHTMLPDFWriter;
@class ORKPDFWriter;
@class ORKConsentSectionFormatter;
@class ORKConsentSignatureFormatter;

@interface ORKConsentDocument ()

@property (nonatomic, strong, nullable) ORKHTMLPDFWriter *writer;
@property (nonatomic, strong, nullable) ORKPDFWriter *writer;
@property (nonatomic, strong, nullable) ORKConsentSectionFormatter *sectionFormatter;
@property (nonatomic, strong, nullable) ORKConsentSignatureFormatter *signatureFormatter;

Expand Down
3 changes: 3 additions & 0 deletions ResearchKit/Localized/en.lproj/ResearchKit.strings
Expand Up @@ -423,6 +423,9 @@
/* Charts */
"CHART_NO_DATA_TEXT" = "No Data";

/* Printing */
"PRINT_TIMESTAMP" = "Started: %1$@, Completed: %2$@";

/* Accessibility */
"AX_BUTTON_BACK" = "Back";

Expand Down
76 changes: 76 additions & 0 deletions ResearchKit/Printing/HTMLPrintingStylesheet.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions ResearchKit/Printing/ORKHTMLPrintingTemplate.h
@@ -0,0 +1,63 @@
/*
Copyright (c) 2016, Oliver Schaefer

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. Neither the name of the copyright holder(s) nor the names of any contributors
may be used to endorse or promote products derived from this software without
specific prior written permission. No license is granted to the trademarks of
the copyright holders even if such marks are included in this software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#import <Foundation/Foundation.h>


NS_ASSUME_NONNULL_BEGIN

@interface ORKHTMLPrintingTemplate : NSObject

- (NSString *)html;

- (NSString *)step;

- (NSString *)stepHeader;

- (NSString *)formStep;

- (NSString *)formStepAnswer;

- (NSString *)questionStepAnswer;

- (NSString *)stepAnswer;

- (NSString *)stepSelectedAnswer;

- (NSString *)stepUnselectedAnswer;

- (NSString *)stepFooter;

- (NSString *)image;

@end

NS_ASSUME_NONNULL_END