Skip to content

Commit ec27a88

Browse files
committed
Remove the SDImageCoderDecodePDFPrefersBitmap, for bitmap representation, use thumbnailPixelSize value instead
1 parent 8831f33 commit ec27a88

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

Example/SDWebImagePDFCoder/SDViewController.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ - (void)viewDidLoad
2525
[[SDImageCodersManager sharedManager] addCoder:PDFCoder];
2626
NSURL *pdfURL = [NSURL URLWithString:@"https://raw.githubusercontent.com/icons8/flat-color-icons/master/pdf/about.pdf"];
2727
NSURL *pdfURL2 = [NSURL URLWithString:@"https://raw.githubusercontent.com/icons8/flat-color-icons/master/pdf/webcam.pdf"];
28+
NSURL *pdfURL3 = [NSURL URLWithString:@"https://raw.githubusercontent.com/icons8/flat-color-icons/master/pdf/like.pdf"];
2829

2930
CGSize screenSize = self.view.bounds.size;
3031

@@ -36,8 +37,13 @@ - (void)viewDidLoad
3637
imageView2.contentMode = UIViewContentModeScaleAspectFit;
3738
imageView2.clipsToBounds = YES;
3839

40+
UIImageView *imageView3 = [[UIImageView alloc] init];
41+
imageView3.frame = CGRectMake(screenSize.width - 100, screenSize.height - 100, 100, 100);
42+
imageView3.contentMode = UIViewContentModeScaleToFill;
43+
3944
[self.view addSubview:imageView1];
4045
[self.view addSubview:imageView2];
46+
[self.view addSubview:imageView3];
4147

4248
[imageView1 sd_setImageWithURL:pdfURL placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
4349
if (image) {
@@ -46,7 +52,7 @@ - (void)viewDidLoad
4652
NSAssert(pdfData.length > 0, @"PDF Data export failed");
4753
}
4854
}];
49-
[imageView2 sd_setImageWithURL:pdfURL2 placeholderImage:nil options:SDWebImageRetryFailed context:@{SDWebImageContextImageThumbnailPixelSize : @(imageView2.bounds.size)} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
55+
[imageView2 sd_setImageWithURL:pdfURL2 placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
5056
if (image) {
5157
NSLog(@"PDF load animation success");
5258
[UIView animateWithDuration:2 animations:^{
@@ -58,6 +64,13 @@ - (void)viewDidLoad
5864
}];
5965
}
6066
}];
67+
[imageView3 sd_setImageWithURL:pdfURL3 placeholderImage:nil options:SDWebImageRetryFailed context:@{SDWebImageContextImageThumbnailPixelSize: @(CGSizeMake(100, 100))} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
68+
if (image) {
69+
NSLog(@"PDF bitmap load success.");
70+
NSData *svgData = [image sd_imageDataAsFormat:SDImageFormatPDF];
71+
NSAssert(!svgData, @"SVG Data should not exist");
72+
}
73+
}];
6174
}
6275

6376
- (void)didReceiveMemoryWarning

SDWebImagePDFCoder/Classes/SDImagePDFCoder.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,24 @@ - (UIImage *)decodedImageWithData:(NSData *)data options:(SDImageCoderOptions *)
6565
} else if (options[SDImageCoderDecodePDFPageNumber]) {
6666
pageNumber = [options[SDImageCoderDecodePDFPageNumber] unsignedIntegerValue];
6767
}
68-
if (context[SDWebImageContextPDFPrefersBitmap]) {
69-
prefersBitmap = [context[SDWebImageContextPDFPrefersBitmap] boolValue];
70-
} else if (options[SDImageCoderDecodePDFPrefersBitmap]) {
71-
prefersBitmap = [options[SDImageCoderDecodePDFPrefersBitmap] boolValue];
72-
}
7368
if (context[SDWebImageContextPDFImageSize]) {
69+
prefersBitmap = YES;
7470
NSValue *sizeValue = context[SDWebImageContextPDFImageSize];
7571
#if SD_MAC
7672
imageSize = sizeValue.sizeValue;
7773
#else
7874
imageSize = sizeValue.CGSizeValue;
7975
#endif
8076
} else if (options[SDImageCoderDecodeThumbnailPixelSize]) {
77+
prefersBitmap = YES;
8178
NSValue *sizeValue = options[SDImageCoderDecodeThumbnailPixelSize];
8279
#if SD_MAC
8380
imageSize = sizeValue.sizeValue;
8481
#else
8582
imageSize = sizeValue.CGSizeValue;
8683
#endif
84+
} else if (context[SDWebImageContextPDFPrefersBitmap]) {
85+
prefersBitmap = [context[SDWebImageContextPDFPrefersBitmap] boolValue];
8786
}
8887
if (context[SDWebImageContextPDFImagePreserveAspectRatio]) {
8988
preserveAspectRatio = [context[SDWebImageContextPDFImagePreserveAspectRatio] boolValue];

SDWebImagePDFCoder/Classes/SDWebImagePDFCoderDefine.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextPDFPag
2323
A BOOL value which specify whether we prefer the actual bitmap representation instead of vector representation for PDF image. This is because the UIImage on iOS 11+ (NSImgae on macOS) can use the vector image format, which support dynamic scale without losing any detail. However, for some image processing logic, user may need the actual bitmap representation to manage pixels. Also, for lower firmware on iOS, the `UIImage` does not support vector rendering, user may want to handle them using the same code. (NSNumber)
2424
If you don't provide this value, use NO for default value and prefer the vector format when possible.
2525
*/
26-
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextPDFPrefersBitmap;
26+
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextPDFPrefersBitmap __attribute__((deprecated("Use the new context option (for WebCache category), or coder option (for SDImageCoder protocol) instead. Pass CGSize.zero means the box size of PDF", "SDWebImageContextImageThumbnailPixelSize")));
2727

2828
#pragma mark - Bitmap Representation Options
2929
/**
@@ -50,13 +50,6 @@ FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextPDFIma
5050
*/
5151
FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodePDFPageNumber;
5252

53-
/**
54-
A BOOL value which specify whether we prefer the actual bitmap representation instead of vector representation for PDF image. This is because the UIImage on iOS 11+ (NSImgae on macOS) can use the vector image format, which support dynamic scale without losing any detail. However, for some image processing logic, user may need the actual bitmap representation to manage pixels. Also, for lower firmware on iOS, the `UIImage` does not support vector rendering, user may want to handle them using the same code. (NSNumber)
55-
If you don't provide this value, use NO for default value and prefer the vector format when possible.
56-
@note works for `SDImageCoder`
57-
*/
58-
FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderDecodePDFPrefersBitmap;
59-
6053
/**
6154
`SDImageCoderDecodeThumnailPixelSize`: The same as context option `SDWebImageContextImageThumbnailPixelSize`
6255
`SDImageCoderDecodePreserveAspectRatio`: The same as context option `SDWebImageContextImagePreserveAspectRatio`

0 commit comments

Comments
 (0)