Skip to content
This repository was archived by the owner on Aug 3, 2022. It is now read-only.

Commit 8df364a

Browse files
authored
Merge pull request #4 from SDWebImage/support_sd_5.5
Update to support SDWebImage 5.5's new `thumbnailPixelSize` option
2 parents 2b65879 + 3dd4bac commit 8df364a

File tree

8 files changed

+48
-22
lines changed

8 files changed

+48
-22
lines changed

Diff for: Cartfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "SDWebImage/SDWebImage" ~> 5.0
1+
github "SDWebImage/SDWebImage" ~> 5.5
22
github "SVGKit/SVGKit" >= 2.1

Diff for: Example/Podfile.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ PODS:
22
- CocoaLumberjack (3.6.0):
33
- CocoaLumberjack/Core (= 3.6.0)
44
- CocoaLumberjack/Core (3.6.0)
5-
- SDWebImage/Core (5.3.1)
5+
- SDWebImage/Core (5.5.2)
66
- SDWebImageSVGKitPlugin (1.0.0):
7-
- SDWebImage/Core (~> 5.0)
7+
- SDWebImage/Core (~> 5.5)
88
- SVGKit (>= 2.1)
99
- SVGKit (2.1.0):
1010
- CocoaLumberjack (~> 3.0)
@@ -27,13 +27,13 @@ EXTERNAL SOURCES:
2727

2828
CHECKOUT OPTIONS:
2929
SVGKit:
30-
:commit: 39dd210fd47e3195f57f914354ffd2d0b4b8ff1c
30+
:commit: 8560ef56bd61e34d5cd8d9739954f9765e3ac794
3131
:git: https://github.com/SVGKit/SVGKit.git
3232

3333
SPEC CHECKSUMS:
3434
CocoaLumberjack: 78b0c238666f4f58db069738ec176f4519557516
35-
SDWebImage: 7137d57385fb632129838c1e6ab9528a22c666cc
36-
SDWebImageSVGKitPlugin: ec8a6a4492d1dc40f5f9fa1dee4acca07f93ad15
35+
SDWebImage: 4d5c027c935438f341ed33dbac53ff9f479922ca
36+
SDWebImageSVGKitPlugin: 02e1f98cf9ed0814788bba781fad59ac4185dfc4
3737
SVGKit: 8a2fc74258bdb2abb54d3b65f3dd68b0277a9c4d
3838

3939
PODFILE CHECKSUM: 91804dc9be5d336ef696711e8704688dfe2f0a2a

Diff for: Example/SDWebImageSVGKitPlugin/SDViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ - (void)viewDidLoad
6161
}
6262
}];
6363
// For `UIImageView`, you can specify a desired SVG size instead of original SVG viewport (which may be small)
64-
[imageView3 sd_setImageWithURL:svgURL3 placeholderImage:nil options:SDWebImageRetryFailed context:@{SDWebImageContextSVGKImageSize : @(CGSizeMake(100, 100))} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
64+
[imageView3 sd_setImageWithURL:svgURL3 placeholderImage:nil options:SDWebImageRetryFailed context:@{SDWebImageContextImageThumbnailPixelSize : @(CGSizeMake(100, 100))} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
6565
if (image) {
6666
NSLog(@"UIImageView SVG load success");
6767
}

Diff for: README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
## What's for
1111
SDWebImageSVGKitPlugin is a SVG coder plugin for [SDWebImage](https://github.com/rs/SDWebImage/) framework, which provide the image loading support for [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) using [SVGKit](https://github.com/SVGKit/SVGKit) SVG engine.
1212

13+
Note: iOS 13+/macOS 10.15+ supports native SVG rendering (called [Symbol Image](https://developer.apple.com/documentation/uikit/uiimage/configuring_and_displaying_symbol_images_in_your_ui/)), with system framework to load SVG. Check [SDWebImageSVGCoder](https://github.com/SDWebImage/SDWebImageSVGCoder) for more information.
14+
1315
## Example
1416

1517
To run the example project, clone the repo, and run `pod install` from the Example directory first.
@@ -18,9 +20,9 @@ You can modify the code or use some other SVG files to check the compatibility.
1820

1921
## Requirements
2022

21-
+ iOS 8
22-
+ tvOS 9
23-
+ macOS 10.10
23+
+ iOS 8+
24+
+ tvOS 9+
25+
+ macOS 10.10+
2426

2527
## Installation
2628

@@ -53,7 +55,7 @@ github "SDWebImage/SDWebImageSVGKitPlugin"
5355

5456
To use SVG coder, you should firstly add the `SDImageSVGKCoder` to the coders manager. Then you can call the View Category method to start load SVG images.
5557

56-
Because SVG is a [vector image](https://en.wikipedia.org/wiki/Vector_graphics) format, which means it does not have a fixed bitmap size. However, `UIImage` or `CGImage` are all [bitmap image](https://en.wikipedia.org/wiki/Raster_graphics). For `UIImageView`, we will only parse SVG with a fixed image size (from the SVG viewPort information). But we also support you to specify a desired size during image loading using `SDWebImageContextSVGKImageSize` context option. And you can specify whether or not to keep aspect ratio during scale using `SDWebImageContextSVGKImagePreserveAspectRatio` context option.
58+
Because SVG is a [vector image](https://en.wikipedia.org/wiki/Vector_graphics) format, which means it does not have a fixed bitmap size. However, `UIImage` or `CGImage` are all [bitmap image](https://en.wikipedia.org/wiki/Raster_graphics). For `UIImageView`, we will only parse SVG with a fixed image size (from the SVG viewPort information). But we also support you to specify a desired size during image loading using `SDWebImageContextThumbnailPixelSize` context option. And you can specify whether or not to keep aspect ratio during scale using `SDWebImageContextImagePreserveAspectRatio` context option.
5759

5860
+ Objective-C
5961

@@ -63,7 +65,7 @@ SDImageSVGKCoder *svgCoder = [SDImageSVGKCoder sharedCoder];
6365
UIImageView *imageView;
6466
// this arg is optional, if don't provide, use the viewport size instead
6567
CGSize svgImageSize = CGSizeMake(100, 100);
66-
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextSVGKImageSize : @(svgImageSize)];
68+
[imageView sd_setImageWithURL:url placeholderImage:nil options:0 context:@{SDWebImageContextThumbnailPixelSize : @(svgImageSize)];
6769
```
6870
6971
+ Swift
@@ -75,7 +77,7 @@ let imageView: UIImageView
7577
imageView.sd_setImage(with: url)
7678
// this arg is optional, if don't provide, use the viewport size instead
7779
let svgImageSize = CGSize(width: 100, height: 100)
78-
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.svgkImageSize : svgImageSize])
80+
imageView.sd_setImage(with: url, placeholderImage: nil, options: [], context: [.imageThumbnailPixelSize : svgImageSize])
7981
```
8082

8183
### Use SVGKImageView (render SVG as vector image)
@@ -120,7 +122,7 @@ NSData *imageData = [image sd_imageDataAsFormat:SDImageFormatSVG];
120122
+ Swift
121123
122124
```swift
123-
let image; // Image generated from SDWebImage framework, actually a `SDSVGKImage` instance.
125+
let image: UIImage // Image generated from SDWebImage framework, actually a `SDSVGKImage` instance.
124126
let imageData = image.sd_imageData(as: .SVG)
125127
```
126128

Diff for: SDWebImageSVGKitPlugin.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ TODO: Add long description of the pod here.
3333
s.source_files = 'SDWebImageSVGKitPlugin/Classes/**/*', 'SDWebImageSVGKitPlugin/Module/SDWebImageSVGKitPlugin.h'
3434
s.module_map = 'SDWebImageSVGKitPlugin/Module/SDWebImageSVGKitPlugin.modulemap'
3535

36-
s.dependency 'SDWebImage/Core', '~> 5.0'
36+
s.dependency 'SDWebImage/Core', '~> 5.5'
3737
s.dependency 'SVGKit', '>= 2.1'
3838
end

Diff for: SDWebImageSVGKitPlugin/Classes/SDImageSVGKCoder.m

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ - (UIImage *)decodedImageWithData:(NSData *)data options:(SDImageCoderOptions *)
4141

4242
CGSize imageSize = CGSizeZero;
4343
BOOL preserveAspectRatio = YES;
44+
45+
#pragma clang diagnostic push
46+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
4447
// Parse args
4548
SDWebImageContext *context = options[SDImageCoderWebImageContext];
4649
if (context[SDWebImageContextSVGKImageSize]) {
@@ -49,11 +52,21 @@ - (UIImage *)decodedImageWithData:(NSData *)data options:(SDImageCoderOptions *)
4952
imageSize = sizeValue.CGSizeValue;
5053
#else
5154
imageSize = sizeValue.sizeValue;
55+
#endif
56+
} else if (options[SDImageCoderDecodeThumbnailPixelSize]) {
57+
NSValue *sizeValue = options[SDImageCoderDecodeThumbnailPixelSize];
58+
#if SD_UIKIT
59+
imageSize = sizeValue.CGSizeValue;
60+
#else
61+
imageSize = sizeValue.sizeValue;
5262
#endif
5363
}
5464
if (context[SDWebImageContextSVGKImagePreserveAspectRatio]) {
5565
preserveAspectRatio = [context[SDWebImageContextSVGKImagePreserveAspectRatio] boolValue];
66+
} else if (options[SDImageCoderDecodePreserveAspectRatio]) {
67+
preserveAspectRatio = [options[SDImageCoderDecodePreserveAspectRatio] boolValue];
5668
}
69+
#pragma clang diagnostic pop
5770

5871
if (!CGSizeEqualToSize(imageSize, CGSizeZero)) {
5972
if (preserveAspectRatio) {

Diff for: SDWebImageSVGKitPlugin/Classes/SDSVGKImage.m

+16-5
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,29 @@ - (instancetype)initWithData:(NSData *)data scale:(CGFloat)scale options:(SDImag
6161
if (!svgImage) {
6262
return nil;
6363
}
64+
CGSize imageSize = CGSizeZero;
65+
6466
// Check specified image size
6567
SDWebImageContext *context = options[SDImageCoderWebImageContext];
68+
#pragma clang diagnostic push
69+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
6670
if (context[SDWebImageContextSVGKImageSize]) {
6771
NSValue *sizeValue = context[SDWebImageContextSVGKImageSize];
6872
#if SD_UIKIT
69-
CGSize imageSize = sizeValue.CGSizeValue;
73+
imageSize = sizeValue.CGSizeValue;
7074
#else
71-
CGSize imageSize = sizeValue.sizeValue;
75+
imageSize = sizeValue.sizeValue;
7276
#endif
73-
if (!CGSizeEqualToSize(imageSize, CGSizeZero)) {
74-
svgImage.size = imageSize;
75-
}
77+
} else if (options[SDImageCoderDecodeThumbnailPixelSize]) {
78+
NSValue *sizeValue = options[SDImageCoderDecodeThumbnailPixelSize];
79+
#if SD_UIKIT
80+
imageSize = sizeValue.CGSizeValue;
81+
#else
82+
imageSize = sizeValue.sizeValue;
83+
#endif
84+
}
85+
if (!CGSizeEqualToSize(imageSize, CGSizeZero)) {
86+
svgImage.size = imageSize;
7687
}
7788
return [self initWithSVGKImage:svgImage];
7889
}

Diff for: SDWebImageSVGKitPlugin/Classes/SDWebImageSVGKitDefine.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ FOUNDATION_EXPORT void SDAdjustSVGContentMode(SVGKImage * __nonnull image, UIVie
2525
A CGSize raw value which specify the desired SVG image size during image loading. Because vector image like SVG format, may not contains a fixed size, or you want to get a larger size bitmap representation UIImage. (NSValue)
2626
If you don't provide this value, use viewBox size of SVG for default value;
2727
*/
28-
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGKImageSize;
28+
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGKImageSize __attribute__((deprecated("Use the new context option (for WebCache category), or coder option (for SDImageCoder protocol) instead", "SDWebImageContextImageThumbnailPixelSize")));
2929

3030
/**
3131
A BOOL value which specify the whether SVG image should keep aspect ratio during image loading. Because when you specify image size via `SDWebImageContextSVGKImageSize`, we need to know whether to keep aspect ratio or not when image size aspect ratio is not equal to SVG viewBox size aspect ratio. (NSNumber)
3232
If you don't provide this value, use YES for default value.
3333
*/
34-
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGKImagePreserveAspectRatio;
34+
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextSVGKImagePreserveAspectRatio __attribute__((deprecated("Use the new context option (for WebCache category), or coder option (for SDImageCoder protocol) instead", "SDWebImageContextImagePreserveAspectRatio")));

0 commit comments

Comments
 (0)