Skip to content

Commit

Permalink
Added .clang-format and formatted/cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Parry committed Jun 3, 2015
1 parent 21efa3c commit 424d3cd
Show file tree
Hide file tree
Showing 25 changed files with 590 additions and 571 deletions.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BasedOnStyle: LLVM

DerivePointerAlignment: false
PointerAlignment: Right
ObjCSpaceAfterProperty: true
UseTab: Always
IndentWidth: 4
TabWidth: 4
ColumnLimit: 0
BreakBeforeBraces: Allman
IndentCaseLabels: true
SpacesInContainerLiterals: true
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,47 @@ Add the following line to import the required classes.

Syntax is similar to creating a `UIImage`:

PDFImage* image = [PDFImage imageNamed:@"email"];
PDFImage *image = [PDFImage imageNamed:@"email"];

This will load the `email.pdf` file from the main bundle.

To show the `PDFImage` on the screen:

PDFImage* image = [PDFImage imageNamed:@"email"];
PDFImage *image = [PDFImage imageNamed:@"email"];

PDFImageView* imageView = [[PDFImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[imageView setImage:image];
PDFImageView *imageView = [[PDFImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
imageView.image = image;
[view addSubview:imageView];

The `PDFImageView` will automatically make sure a pixel perfect version of the loaded PDF is drawn to screen, even if the view is resized or animated.

A `UIImage` can be generated as so:

PDFImage* image = [PDFImage imageNamed:@"email"];
PDFImage *image = [PDFImage imageNamed:@"email"];

PDFImageOptions* options = [PDFImageOptions optionsWithSize:CGSizeMake(50, 50)];
PDFImageOptions *options = [PDFImageOptions optionsWithSize:CGSizeMake(50, 50)];

UIImage* result = [image imageWithOptions:options];
UIImage *result = [image imageWithOptions:options];

By default, the resulting `UIImage` is drawn scale to fill. If required, the options can use any `UIViewContentMode` to adjust how the result is drawn.

PDFImage* image = [PDFImage imageNamed:@"email"];
PDFImage *image = [PDFImage imageNamed:@"email"];

PDFImageOptions* options = [PDFImageOptions optionsWithSize:CGSizeMake(50, 50)];
[options setContentMode:UIViewContentModeScaleAspectFit];
PDFImageOptions *options = [PDFImageOptions optionsWithSize:CGSizeMake(50, 50)];
options.contentMode = UIViewContentModeScaleAspectFit;

UIImage* result = [image imageWithOptions:options];
UIImage *result = [image imageWithOptions:options];


A tintColor can also be specified to change the entire color, useful for reusing the same graphics in different colors.

PDFImageOptions* options = ...;
[options setTintColor:[UIColor redColor]];
PDFImageOptions *options = ...;
options.tintColor = [UIColor redColor];

// or

PDFImageView* imageView = ...;
[imageView setTintColor:[UIColor redColor]];
PDFImageView *imageView = ...;
imageView.tintColor = [UIColor redColor];

See the included headers of the [`PDFImage.framework`](../../releases/latest) for the full API interface.

Expand Down
2 changes: 1 addition & 1 deletion Xcode/PDFImage/PDFBarButtonItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@

// Scales the image down proportionally to fit into a target size of 28x28
// for best results, the PDFImage should be as close to the target size as possible
- (instancetype) initWithImage:(PDFImage*) image style:(UIBarButtonItemStyle) style target:(id) target action:(SEL) action;
- (instancetype)initWithImage:(PDFImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action;

@end
43 changes: 21 additions & 22 deletions Xcode/PDFImage/PDFBarButtonItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,73 +34,72 @@

@interface PDFBarButtonItem ()

@property (nonatomic, readonly) PDFImage* originalImage;
@property (nonatomic, readonly) PDFImage *originalImage;
@property (nonatomic, readonly) CGSize targetSize;

@end

@implementation PDFBarButtonItem

+ (void) initialize
+ (void)initialize
{
if(self == [PDFBarButtonItem class])
if (self == [PDFBarButtonItem class])
{
isiOS7OrGreater = ([UIDevice currentDevice].systemVersion.integerValue >= 7);
}
}

#pragma mark -

- (instancetype) initWithImage:(PDFImage*) image style:(UIBarButtonItemStyle) style target:(id) target action:(SEL) action
- (instancetype)initWithImage:(PDFImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action
{
return [self initWithImage:image style:style target:target action:action targetSize:CGSizeMake(28, 28)];
}

- (instancetype) initWithImage:(PDFImage*) image style:(UIBarButtonItemStyle) style target:(id) target action:(SEL) action targetSize:(CGSize) targetSize
- (instancetype)initWithImage:(PDFImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action targetSize:(CGSize)targetSize
{
self = [super initWithImage:nil style:style target:target action:action];
if(self != nil)

if (self != nil)
{
_originalImage = image;
_targetSize = targetSize;

[self updateBarButtonImage];
}

return self;
}

#pragma mark -
#pragma mark Super

- (void) setTintColor:(UIColor *)tintColor
- (void)setTintColor:(UIColor *)tintColor
{
[super setTintColor:tintColor];

[self updateBarButtonImage];
}

#pragma mark -
#pragma mark Private

- (void) updateBarButtonImage
- (void)updateBarButtonImage
{
PDFImage* originalImage = self.originalImage;
PDFImage *originalImage = self.originalImage;
const CGSize imageSize = [[PDFImageOptions optionsWithSize:self.targetSize] wholeProportionalFitForContentSize:originalImage.size];

// The color of the image,
// on iOS6 we colorize it only if we're using a bordered style (not plain),
// on iOS7+ white is used, as the UIBarButtonItem tint color will colorize our image anyway
UIColor* tintColor = self.tintColor;
if(tintColor == nil || (self.style != UIBarButtonItemStylePlain && !isiOS7OrGreater) || isiOS7OrGreater)
UIColor *tintColor = self.tintColor;
if (tintColor == nil || (self.style != UIBarButtonItemStylePlain && !isiOS7OrGreater) || isiOS7OrGreater)
tintColor = [UIColor whiteColor];

PDFImageOptions* options = [PDFImageOptions optionsWithSize:imageSize];
[options setTintColor:tintColor];

UIImage* image = [originalImage imageWithOptions:options];
[self setImage:image];

PDFImageOptions *options = [PDFImageOptions optionsWithSize:imageSize];
options.tintColor = tintColor;

self.image = [originalImage imageWithOptions:options];
}

@end
22 changes: 11 additions & 11 deletions Xcode/PDFImage/PDFImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@
// may result in a new instance and not the version in NSCache, the same applies to imageWithOptions:
@interface PDFImage : NSObject

@property (nonatomic, readonly) CGSize size; // original page size
@property (nonatomic, readonly) CGSize size; // original page size

+ (instancetype) imageNamed:(NSString*) name; // from the main bundle, the .pdf extension can be omitted,
// this and +imageNamed:inBundle: are the only methods that will NSCache PDFImages, as bundles are read-only
+ (instancetype)imageNamed:(NSString *)name; // from the main bundle, the .pdf extension can be omitted,
// this and +imageNamed:inBundle: are the only methods that will NSCache PDFImages, as bundles are read-only

+ (instancetype) imageNamed:(NSString*) name inBundle:(NSBundle*) bundle;
+ (instancetype)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;

+ (instancetype) imageWithContentsOfFile:(NSString*) path;
+ (instancetype) imageWithData:(NSData*) data;
+ (instancetype)imageWithContentsOfFile:(NSString *)path;
+ (instancetype)imageWithData:(NSData *)data;

- (instancetype) initWithContentsOfFile:(NSString*) path;
- (instancetype) initWithData:(NSData*) data;
- (instancetype)initWithContentsOfFile:(NSString *)path;
- (instancetype)initWithData:(NSData *)data;

- (instancetype) initWithDocument:(CGPDFDocumentRef) document;
- (instancetype)initWithDocument:(CGPDFDocumentRef)document;

- (UIImage*) imageWithOptions:(PDFImageOptions*) options; // will NSCache the image if the same options are used again
- (void) drawInRect:(CGRect) rect;
- (UIImage *)imageWithOptions:(PDFImageOptions *)options; // will NSCache the image if the same options are used again
- (void)drawInRect:(CGRect)rect;

@end
Loading

0 comments on commit 424d3cd

Please sign in to comment.