Skip to content

Commit

Permalink
Merge branch 'release-1.7.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Feb 19, 2015
2 parents 0089481 + c8debc9 commit 988a96d
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 52 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
language: objective-c
#osx_image: xcode61

before_install:
# - brew update
Expand Down
16 changes: 13 additions & 3 deletions Core/Source/DTASN1/DTASN1Parser.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ - (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange
case DTASN1TypeTeletexString:
case DTASN1TypeGraphicString:
case DTASN1TypePrintableString:
case DTASN1TypeUTF8String:
case DTASN1TypeIA5String:
case DTASN1TypeUTF8String:
case DTASN1TypeIA5String:
{
if (_delegateFlags.delegateSupportsString)
{
Expand All @@ -324,7 +324,17 @@ - (BOOL)_parseValueWithTag:(NSUInteger)tag dataRange:(NSRange)dataRange

NSString *string = [[NSString alloc] initWithBytesNoCopy:buffer length:dataRange.length encoding:NSUTF8StringEncoding freeWhenDone:YES];

[_delegate parser:self foundString:string];
// FIXME: This does not properly deal with Latin1 strings, those get simply ignored

if (string)
{
[_delegate parser:self foundString:string];
}
else
{
free(buffer);
buffer = NULL;
}
}
break;
}
Expand Down
7 changes: 7 additions & 0 deletions Core/Source/DTCoreGraphicsUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
// Copyright 2010 Cocoanetics. All rights reserved.
//

#import <tgmath.h>

/**
Various CoreGraphics-related utility functions
*/

/**
Promotes value to CGFloat type.
*/
#define CGFloat_(__x) ((CGFloat) (__x))

/**
Calculates a size that fits an original size into a different size preserving the aspect ratio.
*/
Expand Down
28 changes: 26 additions & 2 deletions Core/Source/DTCoreGraphicsUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CGSize DTCGSizeThatFitsKeepingAspectRatio(CGSize originalSize, CGSize sizeToFit)

CGFloat smallerZoom = MIN(necessaryZoomWidth, necessaryZoomHeight);

return CGSizeMake(roundf(originalSize.width*smallerZoom), roundf(originalSize.height*smallerZoom));
return CGSizeMake(round(originalSize.width*smallerZoom), round(originalSize.height*smallerZoom));
}

CGSize DTCGSizeThatFillsKeepingAspectRatio(CGSize originalSize, CGSize sizeToFit)
Expand All @@ -25,7 +25,7 @@ CGSize DTCGSizeThatFillsKeepingAspectRatio(CGSize originalSize, CGSize sizeToFit

CGFloat largerZoom = MAX(necessaryZoomWidth, necessaryZoomHeight);

return CGSizeMake(roundf(originalSize.width*largerZoom), roundf(originalSize.height*largerZoom));
return CGSizeMake(round(originalSize.width*largerZoom), round(originalSize.height*largerZoom));
}

BOOL DTCGSizeMakeWithDictionaryRepresentation(NSDictionary *dict, CGSize *size)
Expand All @@ -40,17 +40,27 @@ BOOL DTCGSizeMakeWithDictionaryRepresentation(NSDictionary *dict, CGSize *size)

if (size)
{
#if CGFLOAT_IS_DOUBLE
size->width = [widthNumber doubleValue];
size->height = [heightNumber doubleValue];
#else
size->width = [widthNumber floatValue];
size->height = [heightNumber floatValue];
#endif
}

return YES;
}

NSDictionary *DTCGSizeCreateDictionaryRepresentation(CGSize size)
{
#if CGFLOAT_IS_DOUBLE
NSNumber *widthNumber = [NSNumber numberWithDouble:size.width];
NSNumber *heightNumber = [NSNumber numberWithDouble:size.height];
#else
NSNumber *widthNumber = [NSNumber numberWithFloat:size.width];
NSNumber *heightNumber = [NSNumber numberWithFloat:size.height];
#endif

return [NSDictionary dictionaryWithObjectsAndKeys:widthNumber, @"Width", heightNumber, @"Height", nil];
}
Expand All @@ -70,21 +80,35 @@ BOOL DTCGRectMakeWithDictionaryRepresentation(NSDictionary *dict, CGRect *rect)

if (rect)
{
#if CGFLOAT_IS_DOUBLE
rect->origin.x = [xNumber doubleValue];
rect->origin.y = [yNumber doubleValue];
rect->size.width = [widthNumber doubleValue];
rect->size.height = [heightNumber doubleValue];
#else
rect->origin.x = [xNumber floatValue];
rect->origin.y = [yNumber floatValue];
rect->size.width = [widthNumber floatValue];
rect->size.height = [heightNumber floatValue];
#endif
}

return YES;
}

NSDictionary *DTCGRectCreateDictionaryRepresentation(CGRect rect)
{
#if CGFLOAT_IS_DOUBLE
NSNumber *widthNumber = [NSNumber numberWithDouble:rect.size.width];
NSNumber *heightNumber = [NSNumber numberWithDouble:rect.size.height];
NSNumber *xNumber = [NSNumber numberWithDouble:rect.origin.x];
NSNumber *yNumber = [NSNumber numberWithDouble:rect.origin.y];
#else
NSNumber *widthNumber = [NSNumber numberWithFloat:rect.size.width];
NSNumber *heightNumber = [NSNumber numberWithFloat:rect.size.height];
NSNumber *xNumber = [NSNumber numberWithFloat:rect.origin.x];
NSNumber *yNumber = [NSNumber numberWithFloat:rect.origin.y];
#endif

return [NSDictionary dictionaryWithObjectsAndKeys:widthNumber, @"Width", heightNumber, @"Height", xNumber, @"X", yNumber, @"Y", nil];
}
Expand Down
18 changes: 13 additions & 5 deletions Core/Source/DTHTMLParser/DTHTMLParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ - (BOOL)parse
unsigned long dataSize = [_data length];

// detect encoding if necessary
xmlCharEncoding charEnc = 0;
xmlCharEncoding charEnc = XML_CHAR_ENCODING_NONE;

if (!_encoding)
{
Expand All @@ -276,12 +276,20 @@ - (BOOL)parse
else
{
// convert the encoding
// TODO: proper mapping from _encoding to xmlCharEncoding
CFStringEncoding cfenc = CFStringConvertNSStringEncodingToEncoding(_encoding);
CFStringRef cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc);
const char *enc = CFStringGetCStringPtr(cfencstr, 0);

charEnc = xmlParseCharEncoding(enc);
if (cfenc != kCFStringEncodingInvalidId)
{
CFStringRef cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc);

if (cfencstr)
{
NSString *NS_VALID_UNTIL_END_OF_SCOPE encstr = [NSString stringWithString:(__bridge NSString*)cfencstr];
const char *enc = [encstr UTF8String];

charEnc = xmlParseCharEncoding(enc);
}
}
}

// create a parse context
Expand Down
2 changes: 1 addition & 1 deletion Core/Source/DTZipArchive/DTZipArchiveNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
File or directory name
*/
@property (nonatomic, strong) NSString *name;
@property (nonatomic, copy) NSString *name;

/**
Size of file in bytes
Expand Down
2 changes: 1 addition & 1 deletion Core/Source/iOS/DTPieProgressIndicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
The progress in percent
*/
@property (nonatomic, assign) CGFloat progressPercent;
@property (nonatomic, assign) float progressPercent;

/**
The color of the pie
Expand Down
24 changes: 16 additions & 8 deletions Core/Source/iOS/DTPieProgressIndicator.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
//

#import "DTPieProgressIndicator.h"
#import "DTCoreGraphicsUtils.h"

#define PIE_SIZE 34.0f
#define PIE_SIZE CGFloat_(34)

@implementation DTPieProgressIndicator
{
CGFloat _progressPercent;
float _progressPercent;
UIColor *_color;
}

Expand All @@ -32,6 +33,13 @@ - (id)initWithFrame:(CGRect)frame
return self;
}

- (void)awakeFromNib
{
[super awakeFromNib];

self.contentMode = UIViewContentModeRedraw;
self.backgroundColor = [UIColor clearColor];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
Expand All @@ -51,21 +59,21 @@ - (void)drawRect:(CGRect)rect

CGContextBeginTransparencyLayer(ctx, NULL);

CGFloat smallerDimension = MIN(self.bounds.size.width-6.0f, self.bounds.size.height-6.0f);
CGRect drawRect = CGRectMake(roundf(CGRectGetMidX(self.bounds)-smallerDimension/2.0f), roundf(CGRectGetMidY(self.bounds)-smallerDimension/2.0f), smallerDimension, smallerDimension);
CGFloat smallerDimension = MIN(self.bounds.size.width-CGFloat_(6), self.bounds.size.height-CGFloat_(6));
CGRect drawRect = CGRectMake(round(CGRectGetMidX(self.bounds)-smallerDimension/CGFloat_(2)), round(CGRectGetMidY(self.bounds)-smallerDimension/CGFloat_(2)), smallerDimension, smallerDimension);

CGContextSetLineWidth(ctx, 3.0f);
CGContextSetLineWidth(ctx, CGFloat_(3));
CGContextStrokeEllipseInRect(ctx, drawRect);

// enough percent to draw
if (_progressPercent > 0.1f)
{
CGPoint center = CGPointMake(CGRectGetMidX(drawRect), CGRectGetMidY(drawRect));
CGFloat radius = center.x - drawRect.origin.x;
CGFloat angle = _progressPercent * 2.0f * M_PI;
CGFloat angle = CGFloat_(_progressPercent) * CGFloat_(2.0 * M_PI);

CGContextMoveToPoint(ctx, center.x, center.y);
CGContextAddArc(ctx, center.x, center.y, radius, -M_PI_2, angle-M_PI_2, 0);
CGContextAddArc(ctx, center.x, center.y, radius, CGFloat_(-M_PI_2), angle-CGFloat_(M_PI_2), 0);
CGContextAddLineToPoint(ctx, center.x, center.y);

CGContextFillPath(ctx);
Expand All @@ -77,7 +85,7 @@ - (void)drawRect:(CGRect)rect

#pragma mark Properties

- (void)setProgressPercent:(CGFloat)progressPercent
- (void)setProgressPercent:(float)progressPercent
{
if (_progressPercent != progressPercent)
{
Expand Down
11 changes: 6 additions & 5 deletions Core/Source/iOS/DTSmartPagingScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "DTSmartPagingScrollView.h"
#import "DTCoreGraphicsUtils.h"
#import <QuartzCore/QuartzCore.h>

@interface DTSmartPagingScrollView ()
Expand Down Expand Up @@ -80,7 +81,7 @@ - (void)layoutSubviews

- (void)_updateCurrentPage
{
NSUInteger newPageIndex = roundf(self.contentOffset.x / self.frame.size.width);
NSUInteger newPageIndex = round(self.contentOffset.x / self.frame.size.width);

if (_currentPageIndex != newPageIndex)
{
Expand All @@ -100,8 +101,8 @@ - (NSRange)rangeOfVisiblePages
{
CGFloat position = self.contentOffset.x / self.bounds.size.width;

NSInteger firstVisibleIndex = MAX(0, floorf(position));
NSInteger lastVisibleIndex = MIN(ceilf(position), _numberOfPages-1);
NSInteger firstVisibleIndex = MAX(CGFloat_(0), floor(position));
NSInteger lastVisibleIndex = MIN(ceil(position), CGFloat_(_numberOfPages-1));

// check if right page is really visible
CGRect rightFrame = [self frameForPageViewAtIndex:lastVisibleIndex];
Expand Down Expand Up @@ -193,14 +194,14 @@ - (CGRect)frameForPageViewAtIndex:(NSUInteger)index
CGRect frame = self.bounds;
frame.origin.x = index * frame.size.width;

frame = CGRectInset(frame, 10, 0);
frame = CGRectInset(frame, CGFloat_(10), CGFloat_(0));

return frame;
}

- (void)scrollToPage:(NSInteger)page animated:(BOOL)animated
{
CGRect pageRect = CGRectMake(page * self.frame.size.width, 0, self.frame.size.width, self.frame.size.height);
CGRect pageRect = CGRectMake(CGFloat_(page) * self.frame.size.width, CGFloat_(0), self.frame.size.width, self.frame.size.height);
[self scrollRectToVisible:pageRect animated:animated];
}

Expand Down
19 changes: 14 additions & 5 deletions Core/Source/iOS/Experimental/DTStripedLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "DTStripedLayer.h"
#import "DTStripedLayerTile.h"
#import "DTCoreGraphicsUtils.h"
#import "UIColor+DTDebug.h"

@interface DTStripedLayer () // private
Expand Down Expand Up @@ -37,7 +38,7 @@ - (id)init

if (self)
{
_stripeHeight = 512.0f;
_stripeHeight = CGFloat_(512);
_visibleTileKeys = [[NSMutableSet alloc] init];
_tileCreationQueue = [[NSOperationQueue alloc] init];
_tilesWithDrawingInQueue = [[NSMutableSet alloc] init];
Expand Down Expand Up @@ -89,15 +90,23 @@ - (void)setFrame:(CGRect)frame

- (NSRange)_rangeOfVisibleStripesInBounds:(CGRect)bounds
{
NSUInteger firstIndex = floorf(MAX(0, CGRectGetMinY(bounds))/_stripeHeight);
NSUInteger lastIndex = floorf(MIN(_contentSize.height, CGRectGetMaxY(bounds))/_stripeHeight);
NSInteger firstIndex = floor(MAX(CGFloat_(0), CGRectGetMinY(bounds))/_stripeHeight);
NSInteger lastIndex = floor(MIN(_contentSize.height, CGRectGetMaxY(bounds))/_stripeHeight);

return NSMakeRange(firstIndex, lastIndex - firstIndex + 1);
// validate range length
NSInteger length = lastIndex - firstIndex + 1;
if (length < 0)
{
DTLogDebug(@"length of visible stripes < 0: %ld", (long int)length);
length = 0;
}

return NSMakeRange(firstIndex, length);
}

- (CGRect)_frameOfStripeAtIndex:(NSUInteger)index
{
CGRect frame = CGRectMake(0, index*_stripeHeight, _contentSize.width, _stripeHeight);
CGRect frame = CGRectMake(0, CGFloat_(index)*_stripeHeight, _contentSize.width, _stripeHeight);

// need to crop by total bounds, last item not full height
frame = CGRectIntersection(self.bounds, frame);
Expand Down
Loading

0 comments on commit 988a96d

Please sign in to comment.