diff --git a/.gitignore b/.gitignore index 507c623c..19111e41 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -Pods/* +Pods +UserInterface.xcuserstate +xcuserdata/ +*.lock \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..881e74a6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,88 @@ +# SVGAPlayer-iOS CHANGELOG (2020-11-10) + +## [2.5.6](https://github.com/svga/SVGAPlayer-iOS/tree/2.5.6)(2020-11-10) +### Bug Fixes +* Fix: play with range error. ([db92d48](https://github.com/yyued/SVGAPlayer-iOS/commit/db92d48)) + +## [2.5.5](https://github.com/svga/SVGAPlayer-iOS/tree/2.5.5)(2020-10-15) +### Bug Fixes +* Fix: Add semaphore lock to videoCache and weakCache. ([5b3e530](https://github.com/yyued/SVGAPlayer-iOS/commit/5b3e530)) + +## [2.5.4](https://github.com/yyued/SVGAPlayer-iOS/tree/2.5.0-release)(2020-05-28) +### Bug Fixes +* Fix: audio could not play. ([cd6cca8](https://github.com/yyued/SVGAPlayer-iOS/commit/cd6cca8)) + +## [2.5.0](https://github.com/yyued/SVGAPlayer-iOS/tree/2.5.0-release)(2019-10-15) + +### Features + +* Add Support for matte layer and dynamic matte bitmap. +* Add Support for audio step to frame & percentage. + +## [2.3.5](https://github.com/yyued/SVGAPlayer-iOS/compare/2.3.4...2.3.5) (2019-09-29) + +### Bug Fixes + +* Let clearsAfterStop defaults too YES. ([4932be5](https://github.com/yyued/SVGAPlayer-iOS/commit/4932be5)) +* Add support for audio play in stepToFrame. ([873f8e4](https://github.com/yyued/SVGAPlayer-iOS/commit/873f8e4)) +* Correct mp3 file match in proto image for iOS13. ([eb45964](https://github.com/yyued/SVGAPlayer-iOS/commit/eb45964)) +* Correct ZIP file match when parse for iOS13. ([f3e204f](https://github.com/yyued/SVGAPlayer-iOS/commit/f3e204f)) + +## [2.3.4](https://github.com/yyued/SVGAPlayer-iOS/compare/2.3.3...2.3.4) (2019-08-02) + +### Bug Fixes + +* Correct file tag des hit target. ([0018e13](https://github.com/yyued/SVGAPlayer-iOS/commit/0018e13)) +* Correct file tag des hit target. ([dc2e403](https://github.com/yyued/SVGAPlayer-iOS/commit/dc2e403)) +* Fix static layer. ([ab1d4fc](https://github.com/yyued/SVGAPlayer-iOS/commit/ab1d4fc)) +* Fix demo aspect scale. ([33ea6b3](https://github.com/yyued/SVGAPlayer-iOS/commit/33ea6b3)) +* Fix key for svga 1.x format. ([ec43259](https://github.com/yyued/SVGAPlayer-iOS/commit/ec43259)) +* Return when videoItem is nil in startAnimation. ([cb27f0f](https://github.com/yyued/SVGAPlayer-iOS/commit/cb27f0f)) + +### Features + +* Add 2.x proto support for matte. ([527e76f](https://github.com/yyued/SVGAPlayer-iOS/commit/527e76f)) +* Add slider for animation demo. ([fc9d7ef](https://github.com/yyued/SVGAPlayer-iOS/commit/fc9d7ef)) +* Support bitmap matte layer. ([4c4e2b1](https://github.com/yyued/SVGAPlayer-iOS/commit/4c4e2b1)) +* Support muti mask. ([188c1b3](https://github.com/yyued/SVGAPlayer-iOS/commit/188c1b3)) +* Update 2.x proto support for matte. ([2b28845](https://github.com/yyued/SVGAPlayer-iOS/commit/2b28845)) + +### Bug Fixes + +* Rollback SSZipArchive to 1.8.1 because of crash. ([2f9d94b](https://github.com/yyued/SVGAPlayer-iOS/commit/2f9d94b)) + +## [2.3.1](https://github.com/yyued/SVGAPlayer-iOS/compare/2.3.0...2.3.1) (2018-12-18) + +### Bug Fixes + +* Add enabledMemoryCache option to SVGAParser, disable memory cache to default. ([116a91f](https://github.com/yyued/SVGAPlayer-iOS/commit/116a91f)) + +## 2.3.0 + +### Features + +* Add audio support. + +## 2.1.4 + +### Bug Fixes + +* Add classtype asserts to avoid crash. + +## 2.1.3 + +* Add SVGAImageView and SVGAVideoEntity to SVGA.h; +* Add URLRequest params to SVGAParser; + +## 2.1.2 + +* Add dynamicHidden and dynamicDrawing. + +## 2.1.1 + +### Bug Fixes +* Use CADisplayLink::invalid() replace removeFromRunloop. +improve: all Parser callback will perform on Main Thread. + + + diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..56c05682 --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,25 @@ +## Attention + +* Do not ask any usage question, issue board is a issue board, accept library bugs only. +* If you are facing any usage problem, read the README again. + +## Issue Template + +Issue Description(What's your problem) + +How To Reappear(How to reappear the issue) + +Any Attachment(Provide a sample about your issue) + +------ 中文分割线 ------ + +## 注意 + +* 不要在 Issue 板块提问使用问题,Issue 板块只接受 Bug 反馈。 +* 如果遇到使用上的问题,仔细阅读 README。 + +## Issue 模板 + +请尽量使用英文提交 Issue + +请确切回答:问题的描述、重现方式、附件(提供一个 Demo 以重现问题) diff --git a/Podfile b/Podfile index 62423ac6..3cb9a7ae 100644 --- a/Podfile +++ b/Podfile @@ -2,26 +2,7 @@ platform :ios, '8.0' target 'SVGAPlayer' do - pod 'SSZipArchive' + pod 'SSZipArchive', '~> 2.1.4' + pod 'Protobuf', '~> 3.4' end - -target 'SVGAPlayer React' do - - pod 'SSZipArchive' - pod 'React', :podspec => 'https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec', :subspecs => [ - 'Core', - 'ART', - 'RCTActionSheet', - 'RCTGeolocation', - 'RCTImage', - 'RCTNetwork', - 'RCTSettings', - 'RCTText', - 'RCTVibration', - 'RCTWebSocket', - 'RCTLinkingIOS', - ] - pod 'Yoga' - -end diff --git a/Podfile.lock b/Podfile.lock index 37ae9d81..be536f16 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,58 +1,20 @@ PODS: - - React/ART (0.45.1): - - React/Core - - React/Core (0.45.1): - - React/cxxreact - - Yoga - - React/cxxreact (0.45.1): - - React/jschelpers - - React/jschelpers (0.45.1) - - React/RCTActionSheet (0.45.1): - - React/Core - - React/RCTGeolocation (0.45.1): - - React/Core - - React/RCTImage (0.45.1): - - React/Core - - React/RCTNetwork - - React/RCTLinkingIOS (0.45.1): - - React/Core - - React/RCTNetwork (0.45.1): - - React/Core - - React/RCTSettings (0.45.1): - - React/Core - - React/RCTText (0.45.1): - - React/Core - - React/RCTVibration (0.45.1): - - React/Core - - React/RCTWebSocket (0.45.1): - - React/Core - - SSZipArchive (2.0.3) - - Yoga (1.6.0) + - Protobuf (3.6.1) + - SSZipArchive (2.1.4) DEPENDENCIES: - - React/ART (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/Core (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/RCTActionSheet (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/RCTGeolocation (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/RCTImage (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/RCTLinkingIOS (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/RCTNetwork (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/RCTSettings (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/RCTText (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/RCTVibration (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - React/RCTWebSocket (from `https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec`) - - SSZipArchive - - Yoga + - Protobuf (~> 3.4) + - SSZipArchive (~> 2.1.4) -EXTERNAL SOURCES: - React: - :podspec: https://raw.githubusercontent.com/yyued/react-native-runtime-ios/0.45.1/React.podspec +SPEC REPOS: + https://github.com/CocoaPods/Specs.git: + - Protobuf + - SSZipArchive SPEC CHECKSUMS: - React: 505e0132cd9aaba1a56e47ef509220dd794ec9be - SSZipArchive: b6648b70a36303ca5be9f0351174b347e1886236 - Yoga: 81670877477311136b1b3f69a6307ce62e1c89cf + Protobuf: 1eb9700044745f00181c136ef21b8ff3ad5a0fd5 + SSZipArchive: 41455d4b8d2b6ab93990820b50dc697c2554a322 -PODFILE CHECKSUM: 7583a464baac51f76d5deb4e6c1333f7eaf90881 +PODFILE CHECKSUM: 15ec3c806396baa34a298b2254638f0a6691580c -COCOAPODS: 1.2.0 +COCOAPODS: 1.9.1 diff --git a/Pods/Headers/Private/SSZipArchive/SSZipArchive.h b/Pods/Headers/Private/SSZipArchive/SSZipArchive.h deleted file mode 120000 index 951d7349..00000000 --- a/Pods/Headers/Private/SSZipArchive/SSZipArchive.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/SSZipArchive.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/ZipArchive.h b/Pods/Headers/Private/SSZipArchive/ZipArchive.h deleted file mode 120000 index 5dd79e88..00000000 --- a/Pods/Headers/Private/SSZipArchive/ZipArchive.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/ZipArchive.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/aes.h b/Pods/Headers/Private/SSZipArchive/aes.h deleted file mode 120000 index 32196452..00000000 --- a/Pods/Headers/Private/SSZipArchive/aes.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/aes.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/aesopt.h b/Pods/Headers/Private/SSZipArchive/aesopt.h deleted file mode 120000 index 452f4092..00000000 --- a/Pods/Headers/Private/SSZipArchive/aesopt.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/aesopt.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/aestab.h b/Pods/Headers/Private/SSZipArchive/aestab.h deleted file mode 120000 index fb03b74e..00000000 --- a/Pods/Headers/Private/SSZipArchive/aestab.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/aestab.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/brg_endian.h b/Pods/Headers/Private/SSZipArchive/brg_endian.h deleted file mode 120000 index 07e0ff21..00000000 --- a/Pods/Headers/Private/SSZipArchive/brg_endian.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/brg_endian.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/brg_types.h b/Pods/Headers/Private/SSZipArchive/brg_types.h deleted file mode 120000 index b7ebbfe1..00000000 --- a/Pods/Headers/Private/SSZipArchive/brg_types.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/brg_types.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/crypt.h b/Pods/Headers/Private/SSZipArchive/crypt.h deleted file mode 120000 index 87a02b47..00000000 --- a/Pods/Headers/Private/SSZipArchive/crypt.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/crypt.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/fileenc.h b/Pods/Headers/Private/SSZipArchive/fileenc.h deleted file mode 120000 index 15572dd2..00000000 --- a/Pods/Headers/Private/SSZipArchive/fileenc.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/fileenc.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/hmac.h b/Pods/Headers/Private/SSZipArchive/hmac.h deleted file mode 120000 index 3e2defae..00000000 --- a/Pods/Headers/Private/SSZipArchive/hmac.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/hmac.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/ioapi.h b/Pods/Headers/Private/SSZipArchive/ioapi.h deleted file mode 120000 index 3b7663c3..00000000 --- a/Pods/Headers/Private/SSZipArchive/ioapi.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/ioapi.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/prng.h b/Pods/Headers/Private/SSZipArchive/prng.h deleted file mode 120000 index b1ef2f7a..00000000 --- a/Pods/Headers/Private/SSZipArchive/prng.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/prng.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/pwd2key.h b/Pods/Headers/Private/SSZipArchive/pwd2key.h deleted file mode 120000 index b0d6b5d7..00000000 --- a/Pods/Headers/Private/SSZipArchive/pwd2key.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/pwd2key.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/sha1.h b/Pods/Headers/Private/SSZipArchive/sha1.h deleted file mode 120000 index 7bc66eb8..00000000 --- a/Pods/Headers/Private/SSZipArchive/sha1.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/aes/sha1.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/unzip.h b/Pods/Headers/Private/SSZipArchive/unzip.h deleted file mode 120000 index 2f0c6489..00000000 --- a/Pods/Headers/Private/SSZipArchive/unzip.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/unzip.h \ No newline at end of file diff --git a/Pods/Headers/Private/SSZipArchive/zip.h b/Pods/Headers/Private/SSZipArchive/zip.h deleted file mode 120000 index 4ad32d25..00000000 --- a/Pods/Headers/Private/SSZipArchive/zip.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/minizip/zip.h \ No newline at end of file diff --git a/Pods/Headers/Public/SSZipArchive/SSZipArchive.h b/Pods/Headers/Public/SSZipArchive/SSZipArchive.h deleted file mode 120000 index 951d7349..00000000 --- a/Pods/Headers/Public/SSZipArchive/SSZipArchive.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/SSZipArchive.h \ No newline at end of file diff --git a/Pods/Headers/Public/SSZipArchive/ZipArchive.h b/Pods/Headers/Public/SSZipArchive/ZipArchive.h deleted file mode 120000 index 5dd79e88..00000000 --- a/Pods/Headers/Public/SSZipArchive/ZipArchive.h +++ /dev/null @@ -1 +0,0 @@ -../../../SSZipArchive/SSZipArchive/ZipArchive.h \ No newline at end of file diff --git a/Pods/SSZipArchive/LICENSE.txt b/Pods/SSZipArchive/LICENSE.txt deleted file mode 100644 index 2229be4b..00000000 --- a/Pods/SSZipArchive/LICENSE.txt +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2010-2015, Sam Soffes, http://soff.es - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Pods/SSZipArchive/SSZipArchive/minizip/crypt.h b/Pods/SSZipArchive/SSZipArchive/minizip/crypt.h deleted file mode 100644 index 72e9536a..00000000 --- a/Pods/SSZipArchive/SSZipArchive/minizip/crypt.h +++ /dev/null @@ -1,57 +0,0 @@ -/* crypt.h -- base code for traditional PKWARE encryption - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - Modifications for Info-ZIP crypting - Copyright (C) 2003 Terry Thorsen - - This code is a modified version of crypting code in Info-ZIP distribution - - Copyright (C) 1990-2000 Info-ZIP. All rights reserved. - - This program is distributed under the terms of the same license as zlib. - See the accompanying LICENSE file for the full text of the license. -*/ - -#ifndef _MINICRYPT_H -#define _MINICRYPT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define RAND_HEAD_LEN 12 - -/***************************************************************************/ - -#define zdecode(pkeys,pcrc_32_tab,c) \ - (update_keys(pkeys,pcrc_32_tab, c ^= decrypt_byte(pkeys))) - -#define zencode(pkeys,pcrc_32_tab,c,t) \ - (t = decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c)) - -/***************************************************************************/ - -/* Return the next byte in the pseudo-random sequence */ -uint8_t decrypt_byte(uint32_t *pkeys); - -/* Update the encryption keys with the next byte of plain text */ -uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c); - -/* Initialize the encryption keys and the random header according to the given password. */ -void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab); - -/* Generate cryptographically secure random numbers */ -int cryptrand(unsigned char *buf, unsigned int len); - -/* Create encryption header */ -int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys, - const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2); - -/***************************************************************************/ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Pods/SSZipArchive/SSZipArchive/minizip/ioapi.c b/Pods/SSZipArchive/SSZipArchive/minizip/ioapi.c deleted file mode 100755 index bba26334..00000000 --- a/Pods/SSZipArchive/SSZipArchive/minizip/ioapi.c +++ /dev/null @@ -1,351 +0,0 @@ -/* ioapi.c -- IO base function header for compress/uncompress .zip - part of the MiniZip project - - Copyright (C) 1998-2010 Gilles Vollant - http://www.winimage.com/zLibDll/minizip.html - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson - http://result42.com - - This program is distributed under the terms of the same license as zlib. - See the accompanying LICENSE file for the full text of the license. -*/ - -#include -#include - -#if defined unix || defined __APPLE__ -#include -#include -#endif - -#include "ioapi.h" - -#if defined(_WIN32) -# define snprintf _snprintf -#endif - -voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc, const void *filename, int mode) -{ - if (pfilefunc->zfile_func64.zopen64_file != NULL) - return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque, filename, mode); - return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque, (const char*)filename, mode); -} - -voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode) -{ - if (pfilefunc->zfile_func64.zopendisk64_file != NULL) - return (*(pfilefunc->zfile_func64.zopendisk64_file)) (pfilefunc->zfile_func64.opaque, filestream, number_disk, mode); - return (*(pfilefunc->zopendisk32_file))(pfilefunc->zfile_func64.opaque, filestream, number_disk, mode); -} - -long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin) -{ - uint32_t offset_truncated = 0; - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); - offset_truncated = (uint32_t)offset; - if (offset_truncated != offset) - return -1; - return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream, offset_truncated, origin); -} - -uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream) -{ - uint64_t position; - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque, filestream); - position = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque, filestream); - if ((position) == UINT32_MAX) - return (uint64_t)-1; - return position; -} - -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32) -{ - p_filefunc64_32->zfile_func64.zopen64_file = NULL; - p_filefunc64_32->zfile_func64.zopendisk64_file = NULL; - p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; - p_filefunc64_32->zopendisk32_file = p_filefunc32->zopendisk_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; - p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; - p_filefunc64_32->zfile_func64.ztell64_file = NULL; - p_filefunc64_32->zfile_func64.zseek64_file = NULL; - p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; - p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; - p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; -} - -static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char *filename, int mode); -static uint32_t ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uint32_t size); -static uint32_t ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void *buf, uint32_t size); -static uint64_t ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream); -static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, uint64_t offset, int origin); -static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream); -static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream); - -typedef struct -{ - FILE *file; - int filenameLength; - void *filename; -} FILE_IOPOSIX; - -static voidpf file_build_ioposix(FILE *file, const char *filename) -{ - FILE_IOPOSIX *ioposix = NULL; - if (file == NULL) - return NULL; - ioposix = (FILE_IOPOSIX*)malloc(sizeof(FILE_IOPOSIX)); - ioposix->file = file; - ioposix->filenameLength = (int)strlen(filename) + 1; - ioposix->filename = (char*)malloc(ioposix->filenameLength * sizeof(char)); - strncpy((char*)ioposix->filename, filename, ioposix->filenameLength); - return (voidpf)ioposix; -} - -static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char *filename, int mode) -{ - FILE* file = NULL; - const char *mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename != NULL) && (mode_fopen != NULL)) - { - file = fopen(filename, mode_fopen); - return file_build_ioposix(file, filename); - } - return file; -} - -static voidpf ZCALLBACK fopen64_file_func(voidpf opaque, const void *filename, int mode) -{ - FILE* file = NULL; - const char *mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename != NULL) && (mode_fopen != NULL)) - { - file = fopen64((const char*)filename, mode_fopen); - return file_build_ioposix(file, (const char*)filename); - } - return file; -} - -static voidpf ZCALLBACK fopendisk64_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode) -{ - FILE_IOPOSIX *ioposix = NULL; - char *diskFilename = NULL; - voidpf ret = NULL; - int i = 0; - - if (stream == NULL) - return NULL; - ioposix = (FILE_IOPOSIX*)stream; - diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char)); - strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength); - for (i = ioposix->filenameLength - 1; i >= 0; i -= 1) - { - if (diskFilename[i] != '.') - continue; - snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1); - break; - } - if (i >= 0) - ret = fopen64_file_func(opaque, diskFilename, mode); - free(diskFilename); - return ret; -} - -static voidpf ZCALLBACK fopendisk_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode) -{ - FILE_IOPOSIX *ioposix = NULL; - char *diskFilename = NULL; - voidpf ret = NULL; - int i = 0; - - if (stream == NULL) - return NULL; - ioposix = (FILE_IOPOSIX*)stream; - diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char)); - strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength); - for (i = ioposix->filenameLength - 1; i >= 0; i -= 1) - { - if (diskFilename[i] != '.') - continue; - snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1); - break; - } - if (i >= 0) - ret = fopen_file_func(opaque, diskFilename, mode); - free(diskFilename); - return ret; -} - -static uint32_t ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uint32_t size) -{ - FILE_IOPOSIX *ioposix = NULL; - uint32_t read = (uint32_t)-1; - if (stream == NULL) - return read; - ioposix = (FILE_IOPOSIX*)stream; - read = (uint32_t)fread(buf, 1, (size_t)size, ioposix->file); - return read; -} - -static uint32_t ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void *buf, uint32_t size) -{ - FILE_IOPOSIX *ioposix = NULL; - uint32_t written = (uint32_t)-1; - if (stream == NULL) - return written; - ioposix = (FILE_IOPOSIX*)stream; - written = (uint32_t)fwrite(buf, 1, (size_t)size, ioposix->file); - return written; -} - -static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream) -{ - FILE_IOPOSIX *ioposix = NULL; - long ret = -1; - if (stream == NULL) - return ret; - ioposix = (FILE_IOPOSIX*)stream; - ret = ftell(ioposix->file); - return ret; -} - -static uint64_t ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream) -{ - FILE_IOPOSIX *ioposix = NULL; - uint64_t ret = (uint64_t)-1; - if (stream == NULL) - return ret; - ioposix = (FILE_IOPOSIX*)stream; - ret = ftello64(ioposix->file); - return ret; -} - -static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uint32_t offset, int origin) -{ - FILE_IOPOSIX *ioposix = NULL; - int fseek_origin = 0; - long ret = 0; - - if (stream == NULL) - return -1; - ioposix = (FILE_IOPOSIX*)stream; - - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR: - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END: - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET: - fseek_origin = SEEK_SET; - break; - default: - return -1; - } - if (fseek(ioposix->file, offset, fseek_origin) != 0) - ret = -1; - return ret; -} - -static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, uint64_t offset, int origin) -{ - FILE_IOPOSIX *ioposix = NULL; - int fseek_origin = 0; - long ret = 0; - - if (stream == NULL) - return -1; - ioposix = (FILE_IOPOSIX*)stream; - - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR: - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END: - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET: - fseek_origin = SEEK_SET; - break; - default: - return -1; - } - - if (fseeko64(ioposix->file, offset, fseek_origin) != 0) - ret = -1; - - return ret; -} - -static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream) -{ - FILE_IOPOSIX *ioposix = NULL; - int ret = -1; - if (stream == NULL) - return ret; - ioposix = (FILE_IOPOSIX*)stream; - if (ioposix->filename != NULL) - free(ioposix->filename); - ret = fclose(ioposix->file); - free(ioposix); - return ret; -} - -static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream) -{ - FILE_IOPOSIX *ioposix = NULL; - int ret = -1; - if (stream == NULL) - return ret; - ioposix = (FILE_IOPOSIX*)stream; - ret = ferror(ioposix->file); - return ret; -} - -void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen_file = fopen_file_func; - pzlib_filefunc_def->zopendisk_file = fopendisk_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell_file = ftell_file_func; - pzlib_filefunc_def->zseek_file = fseek_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} - -void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = fopen64_file_func; - pzlib_filefunc_def->zopendisk64_file = fopendisk64_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell64_file = ftell64_file_func; - pzlib_filefunc_def->zseek64_file = fseek64_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} diff --git a/Pods/SSZipArchive/SSZipArchive/minizip/ioapi.h b/Pods/SSZipArchive/SSZipArchive/minizip/ioapi.h deleted file mode 100755 index efb94a44..00000000 --- a/Pods/SSZipArchive/SSZipArchive/minizip/ioapi.h +++ /dev/null @@ -1,146 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - part of the MiniZip project - - Copyright (C) 1998-2010 Gilles Vollant - http://www.winimage.com/zLibDll/minizip.html - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson - http://result42.com - - This program is distributed under the terms of the same license as zlib. - See the accompanying LICENSE file for the full text of the license. -*/ - -#ifndef _ZLIBIOAPI64_H -#define _ZLIBIOAPI64_H - -#include -#include -#include - -#include "zlib.h" - -#if defined(USE_FILE32API) -# define fopen64 fopen -# define ftello64 ftell -# define fseeko64 fseek -#else -# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__APPLE__) -# define fopen64 fopen -# define ftello64 ftello -# define fseeko64 fseeko -# endif -# ifdef _MSC_VER -# define fopen64 fopen -# if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) -# define ftello64 _ftelli64 -# define fseeko64 _fseeki64 -# else /* old MSC */ -# define ftello64 ftell -# define fseeko64 fseek -# endif -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_FILEFUNC_SEEK_CUR (1) -#define ZLIB_FILEFUNC_SEEK_END (2) -#define ZLIB_FILEFUNC_SEEK_SET (0) - -#define ZLIB_FILEFUNC_MODE_READ (1) -#define ZLIB_FILEFUNC_MODE_WRITE (2) -#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) -#define ZLIB_FILEFUNC_MODE_EXISTING (4) -#define ZLIB_FILEFUNC_MODE_CREATE (8) - -#ifndef ZCALLBACK -# if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \ - defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) -# define ZCALLBACK CALLBACK -# else -# define ZCALLBACK -# endif -#endif - -typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char *filename, int mode); -typedef voidpf (ZCALLBACK *opendisk_file_func) (voidpf opaque, voidpf stream, uint32_t number_disk, int mode); -typedef uint32_t (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uint32_t size); -typedef uint32_t (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void *buf, uint32_t size); -typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream); -typedef int (ZCALLBACK *error_file_func) (voidpf opaque, voidpf stream); - -typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream); -typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uint32_t offset, int origin); - -/* here is the "old" 32 bits structure structure */ -typedef struct zlib_filefunc_def_s -{ - open_file_func zopen_file; - opendisk_file_func zopendisk_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell_file_func ztell_file; - seek_file_func zseek_file; - close_file_func zclose_file; - error_file_func zerror_file; - voidpf opaque; -} zlib_filefunc_def; - -typedef uint64_t (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream); -typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, uint64_t offset, int origin); -typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void *filename, int mode); -typedef voidpf (ZCALLBACK *opendisk64_file_func)(voidpf opaque, voidpf stream, uint32_t number_disk, int mode); - -typedef struct zlib_filefunc64_def_s -{ - open64_file_func zopen64_file; - opendisk64_file_func zopendisk64_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell64_file_func ztell64_file; - seek64_file_func zseek64_file; - close_file_func zclose_file; - error_file_func zerror_file; - voidpf opaque; -} zlib_filefunc64_def; - -void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def); -void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def); - -/* now internal definition, only for zip.c and unzip.h */ -typedef struct zlib_filefunc64_32_def_s -{ - zlib_filefunc64_def zfile_func64; - open_file_func zopen32_file; - opendisk_file_func zopendisk32_file; - tell_file_func ztell32_file; - seek_file_func zseek32_file; -} zlib_filefunc64_32_def; - -#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) -#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) -/*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/ -/*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/ -#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) -#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) - -voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc,const void*filename, int mode); -voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode); -long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin); -uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream); - -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32); - -#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) -#define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode))) -#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) -#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Pods/SSZipArchive/SSZipArchive/minizip/zip.c b/Pods/SSZipArchive/SSZipArchive/minizip/zip.c deleted file mode 100755 index dbb2265c..00000000 --- a/Pods/SSZipArchive/SSZipArchive/minizip/zip.c +++ /dev/null @@ -1,1984 +0,0 @@ -/* zip.c -- IO on .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - - Copyright (C) 1998-2010 Gilles Vollant - http://www.winimage.com/zLibDll/minizip.html - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson - http://result42.com - Modifications for AES, PKWARE disk spanning - Copyright (C) 2010-2014 Nathan Moinvaziri - - This program is distributed under the terms of the same license as zlib. - See the accompanying LICENSE file for the full text of the license. -*/ - -#include -#include -#include -#include -#include - -#include "zlib.h" -#include "zip.h" - -#ifdef HAVE_AES -# define AES_METHOD (99) -# define AES_PWVERIFYSIZE (2) -# define AES_AUTHCODESIZE (10) -# define AES_MAXSALTLENGTH (16) -# define AES_VERSION (0x0001) -# define AES_ENCRYPTIONMODE (0x03) - -# include "aes/aes.h" -# include "aes/fileenc.h" -# include "aes/prng.h" -#endif -#ifdef HAVE_APPLE_COMPRESSION -# include -#endif - -#ifndef NOCRYPT -# include "crypt.h" -#endif - -#define SIZEDATA_INDATABLOCK (4096-(4*4)) - -#define DISKHEADERMAGIC (0x08074b50) -#define LOCALHEADERMAGIC (0x04034b50) -#define CENTRALHEADERMAGIC (0x02014b50) -#define ENDHEADERMAGIC (0x06054b50) -#define ZIP64ENDHEADERMAGIC (0x06064b50) -#define ZIP64ENDLOCHEADERMAGIC (0x07064b50) -#define DATADESCRIPTORMAGIC (0x08074b50) - -#define FLAG_LOCALHEADER_OFFSET (0x06) -#define CRC_LOCALHEADER_OFFSET (0x0e) - -#define SIZECENTRALHEADER (0x2e) /* 46 */ -#define SIZECENTRALHEADERLOCATOR (0x14) /* 20 */ -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) - -#ifndef BUFREADCOMMENT -# define BUFREADCOMMENT (0x400) -#endif -#ifndef VERSIONMADEBY -# define VERSIONMADEBY (0x0) /* platform dependent */ -#endif - -#ifndef Z_BUFSIZE -# define Z_BUFSIZE (UINT16_MAX) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -/* NOT sure that this work on ALL platform */ -#define MAKEULONG64(a, b) ((uint64_t)(((unsigned long)(a)) | ((uint64_t)((unsigned long)(b))) << 32)) - -#ifndef DEF_MEM_LEVEL -# if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -# else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -# endif -#endif - -const char zip_copyright[] = " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; - -typedef struct linkedlist_datablock_internal_s -{ - struct linkedlist_datablock_internal_s *next_datablock; - uint32_t avail_in_this_block; - uint32_t filled_in_this_block; - uint32_t unused; /* for future use and alignment */ - uint8_t data[SIZEDATA_INDATABLOCK]; -} linkedlist_datablock_internal; - -typedef struct linkedlist_data_s -{ - linkedlist_datablock_internal *first_block; - linkedlist_datablock_internal *last_block; -} linkedlist_data; - -typedef struct -{ - z_stream stream; /* zLib stream structure for inflate */ -#ifdef HAVE_BZIP2 - bz_stream bstream; /* bzLib stream structure for bziped */ -#endif -#ifdef HAVE_APPLE_COMPRESSION - compression_stream astream; /* libcompression stream structure */ -#endif -#ifdef HAVE_AES - fcrypt_ctx aes_ctx; - prng_ctx aes_rng[1]; -#endif - int stream_initialised; /* 1 is stream is initialized */ - uint32_t pos_in_buffered_data; /* last written byte in buffered_data */ - - uint64_t pos_local_header; /* offset of the local header of the file currently writing */ - char *central_header; /* central header data for the current file */ - uint16_t size_centralextra; - uint16_t size_centralheader; /* size of the central header for cur file */ - uint16_t size_centralextrafree; /* Extra bytes allocated to the central header but that are not used */ - uint16_t size_comment; - uint16_t flag; /* flag of the file currently writing */ - - uint16_t method; /* compression method written to file.*/ - uint16_t compression_method; /* compression method to use */ - int raw; /* 1 for directly writing raw data */ - uint8_t buffered_data[Z_BUFSIZE]; /* buffer contain compressed data to be writ*/ - uint32_t dos_date; - uint32_t crc32; - int zip64; /* add ZIP64 extended information in the extra field */ - uint32_t number_disk; /* number of current disk used for spanning ZIP */ - uint64_t total_compressed; - uint64_t total_uncompressed; -#ifndef NOCRYPT - uint32_t keys[3]; /* keys defining the pseudo-random sequence */ - const z_crc_t *pcrc_32_tab; -#endif -} curfile64_info; - -typedef struct -{ - zlib_filefunc64_32_def z_filefunc; - voidpf filestream; /* io structure of the zipfile */ - voidpf filestream_with_CD; /* io structure of the zipfile with the central dir */ - linkedlist_data central_dir; /* datablock with central dir in construction*/ - int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ - int append; /* append mode */ - curfile64_info ci; /* info on the file currently writing */ - - uint64_t add_position_when_writting_offset; - uint64_t number_entry; - uint64_t disk_size; /* size of each disk */ - uint32_t number_disk; /* number of the current disk, used for spanning ZIP */ - uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP */ -#ifndef NO_ADDFILEINEXISTINGZIP - char *globalcomment; -#endif -} zip64_internal; - -/* Allocate a new data block */ -static linkedlist_datablock_internal *allocate_new_datablock(void) -{ - linkedlist_datablock_internal *ldi = NULL; - - ldi = (linkedlist_datablock_internal*)ALLOC(sizeof(linkedlist_datablock_internal)); - - if (ldi != NULL) - { - ldi->next_datablock = NULL; - ldi->filled_in_this_block = 0; - ldi->avail_in_this_block = SIZEDATA_INDATABLOCK; - } - return ldi; -} - -/* Free data block in linked list */ -static void free_datablock(linkedlist_datablock_internal *ldi) -{ - while (ldi != NULL) - { - linkedlist_datablock_internal *ldinext = ldi->next_datablock; - TRYFREE(ldi); - ldi = ldinext; - } -} - -/* Initialize linked list */ -static void init_linkedlist(linkedlist_data *ll) -{ - ll->first_block = ll->last_block = NULL; -} - -/* Free entire linked list and all data blocks */ -static void free_linkedlist(linkedlist_data *ll) -{ - free_datablock(ll->first_block); - ll->first_block = ll->last_block = NULL; -} - -/* Add data to linked list data block */ -static int add_data_in_datablock(linkedlist_data *ll, const void *buf, uint32_t len) -{ - linkedlist_datablock_internal *ldi = NULL; - const unsigned char *from_copy = NULL; - - if (ll == NULL) - return ZIP_INTERNALERROR; - - if (ll->last_block == NULL) - { - ll->first_block = ll->last_block = allocate_new_datablock(); - if (ll->first_block == NULL) - return ZIP_INTERNALERROR; - } - - ldi = ll->last_block; - from_copy = (unsigned char*)buf; - - while (len > 0) - { - uint32_t copy_this = 0; - uint32_t i = 0; - unsigned char *to_copy = NULL; - - if (ldi->avail_in_this_block == 0) - { - ldi->next_datablock = allocate_new_datablock(); - if (ldi->next_datablock == NULL) - return ZIP_INTERNALERROR; - ldi = ldi->next_datablock ; - ll->last_block = ldi; - } - - if (ldi->avail_in_this_block < len) - copy_this = ldi->avail_in_this_block; - else - copy_this = len; - - to_copy = &(ldi->data[ldi->filled_in_this_block]); - - for (i = 0; i < copy_this; i++) - *(to_copy+i) = *(from_copy+i); - - ldi->filled_in_this_block += copy_this; - ldi->avail_in_this_block -= copy_this; - from_copy += copy_this; - len -= copy_this; - } - return ZIP_OK; -} - -/* Inputs a long in LSB order to the given file: nbByte == 1, 2 ,4 or 8 (byte, short or long, uint64_t) */ -static int zipWriteValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, - uint64_t x, uint32_t len) -{ - unsigned char buf[8]; - uint32_t n = 0; - - for (n = 0; n < len; n++) - { - buf[n] = (unsigned char)(x & 0xff); - x >>= 8; - } - - if (x != 0) - { - /* Data overflow - hack for ZIP64 (X Roche) */ - for (n = 0; n < len; n++) - { - buf[n] = 0xff; - } - } - - if (ZWRITE64(*pzlib_filefunc_def, filestream, buf, len) != len) - return ZIP_ERRNO; - - return ZIP_OK; -} - -static void zipWriteValueToMemory(void* dest, uint64_t x, uint32_t len) -{ - unsigned char *buf = (unsigned char*)dest; - uint32_t n = 0; - - for (n = 0; n < len; n++) - { - buf[n] = (unsigned char)(x & 0xff); - x >>= 8; - } - - if (x != 0) - { - /* data overflow - hack for ZIP64 */ - for (n = 0; n < len; n++) - { - buf[n] = 0xff; - } - } -} - -static void zipWriteValueToMemoryAndMove(unsigned char **dest_ptr, uint64_t x, uint32_t len) -{ - zipWriteValueToMemory(*dest_ptr, x, len); - *dest_ptr += len; -} - -static int zipReadUInt8(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uint8_t *value) -{ - uint8_t c = 0; - if (ZREAD64(*pzlib_filefunc_def, filestream, &c, 1) == 1) - { - *value = (uint8_t)c; - return ZIP_OK; - } - if (ZERROR64(*pzlib_filefunc_def, filestream)) - return ZIP_ERRNO; - return ZIP_EOF; -} - -static int zipReadUInt16(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uint16_t *value) -{ - uint16_t x = 0; - uint8_t c = 0; - int err = ZIP_OK; - - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x = (uint16_t)c; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint16_t)c) << 8; - - if (err == ZIP_OK) - *value = x; - else - *value = 0; - return err; -} - -static int zipReadUInt32(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uint32_t *value) -{ - uint32_t x = 0; - uint8_t c = 0; - int err = ZIP_OK; - - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x = (uint32_t)c; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint32_t)c) << 8; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint32_t)c) << 16; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint32_t)c) << 24; - - if (err == ZIP_OK) - *value = x; - else - *value = 0; - return err; -} - -static int zipReadUInt64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uint64_t *value) -{ - uint64_t x = 0; - uint8_t c = 0; - int err = ZIP_OK; - - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x = (uint64_t)c; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint64_t)c) << 8; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint64_t)c) << 16; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint64_t)c) << 24; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint64_t)c) << 32; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint64_t)c) << 40; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint64_t)c) << 48; - if (err == ZIP_OK) - err = zipReadUInt8(pzlib_filefunc_def, filestream, &c); - x += ((uint64_t)c) << 56; - - if (err == ZIP_OK) - *value = x; - else - *value = 0; - - return err; -} - -/* Gets the amount of bytes left to write to the current disk for spanning archives */ -static void zipGetDiskSizeAvailable(zipFile file, uint64_t *size_available) -{ - zip64_internal *zi = NULL; - uint64_t current_disk_size = 0; - - zi = (zip64_internal*)file; - ZSEEK64(zi->z_filefunc, zi->filestream, 0, ZLIB_FILEFUNC_SEEK_END); - current_disk_size = ZTELL64(zi->z_filefunc, zi->filestream); - *size_available = zi->disk_size - current_disk_size; -} - -/* Goes to a specific disk number for spanning archives */ -static int zipGoToSpecificDisk(zipFile file, uint32_t number_disk, int open_existing) -{ - zip64_internal *zi = NULL; - int err = ZIP_OK; - - zi = (zip64_internal*)file; - if (zi->disk_size == 0) - return err; - - if ((zi->filestream != NULL) && (zi->filestream != zi->filestream_with_CD)) - ZCLOSE64(zi->z_filefunc, zi->filestream); - - zi->filestream = ZOPENDISK64(zi->z_filefunc, zi->filestream_with_CD, number_disk, (open_existing == 1) ? - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING) : - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE)); - - if (zi->filestream == NULL) - err = ZIP_ERRNO; - - return err; -} - -/* Goes to the first disk in a spanned archive */ -static int zipGoToFirstDisk(zipFile file) -{ - zip64_internal *zi = NULL; - uint32_t number_disk_next = 0; - int err = ZIP_OK; - - zi = (zip64_internal*)file; - - if (zi->disk_size == 0) - return err; - number_disk_next = 0; - if (zi->number_disk_with_CD > 0) - number_disk_next = zi->number_disk_with_CD - 1; - err = zipGoToSpecificDisk(file, number_disk_next, (zi->append == APPEND_STATUS_ADDINZIP)); - if ((err == ZIP_ERRNO) && (zi->append == APPEND_STATUS_ADDINZIP)) - err = zipGoToSpecificDisk(file, number_disk_next, 0); - if (err == ZIP_OK) - zi->number_disk = number_disk_next; - ZSEEK64(zi->z_filefunc, zi->filestream, 0, ZLIB_FILEFUNC_SEEK_END); - return err; -} - -/* Goes to the next disk in a spanned archive */ -static int zipGoToNextDisk(zipFile file) -{ - zip64_internal *zi = NULL; - uint64_t size_available_in_disk = 0; - uint32_t number_disk_next = 0; - int err = ZIP_OK; - - zi = (zip64_internal*)file; - if (zi->disk_size == 0) - return err; - - number_disk_next = zi->number_disk + 1; - - do - { - err = zipGoToSpecificDisk(file, number_disk_next, (zi->append == APPEND_STATUS_ADDINZIP)); - if ((err == ZIP_ERRNO) && (zi->append == APPEND_STATUS_ADDINZIP)) - err = zipGoToSpecificDisk(file, number_disk_next, 0); - if (err != ZIP_OK) - break; - zipGetDiskSizeAvailable(file, &size_available_in_disk); - zi->number_disk = number_disk_next; - zi->number_disk_with_CD = zi->number_disk + 1; - - number_disk_next += 1; - } - while (size_available_in_disk <= 0); - - return err; -} - -/* Locate the Central directory of a zipfile (at the end, just before the global comment) */ -static uint64_t zipSearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream) -{ - unsigned char *buf = NULL; - uint64_t file_size = 0; - uint64_t back_read = 4; - uint64_t max_back = UINT16_MAX; /* maximum size of global comment */ - uint64_t pos_found = 0; - uint32_t read_size = 0; - uint64_t read_pos = 0; - uint32_t i = 0; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf == NULL) - return 0; - - if (ZSEEK64(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0) - { - TRYFREE(buf); - return 0; - } - - file_size = ZTELL64(*pzlib_filefunc_def, filestream); - - if (max_back > file_size) - max_back = file_size; - - while (back_read < max_back) - { - if (back_read + BUFREADCOMMENT > max_back) - back_read = max_back; - else - back_read += BUFREADCOMMENT; - - read_pos = file_size-back_read; - read_size = ((BUFREADCOMMENT+4) < (file_size - read_pos)) ? - (BUFREADCOMMENT+4) : (uint32_t)(file_size - read_pos); - - if (ZSEEK64(*pzlib_filefunc_def, filestream, read_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) - break; - if (ZREAD64(*pzlib_filefunc_def, filestream, buf, read_size) != read_size) - break; - - for (i = read_size-3; (i--) > 0;) - if ((*(buf+i)) == (ENDHEADERMAGIC & 0xff) && - (*(buf+i+1)) == (ENDHEADERMAGIC >> 8 & 0xff) && - (*(buf+i+2)) == (ENDHEADERMAGIC >> 16 & 0xff) && - (*(buf+i+3)) == (ENDHEADERMAGIC >> 24 & 0xff)) - { - pos_found = read_pos+i; - break; - } - - if (pos_found != 0) - break; - } - TRYFREE(buf); - return pos_found; -} - -/* Locate the Central directory 64 of a zipfile (at the end, just before the global comment) */ -static uint64_t zipSearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, - const uint64_t endcentraloffset) -{ - uint64_t offset = 0; - uint32_t value32 = 0; - - /* Zip64 end of central directory locator */ - if (ZSEEK64(*pzlib_filefunc_def, filestream, endcentraloffset - SIZECENTRALHEADERLOCATOR, ZLIB_FILEFUNC_SEEK_SET) != 0) - return 0; - - /* Read locator signature */ - if (zipReadUInt32(pzlib_filefunc_def, filestream, &value32) != ZIP_OK) - return 0; - if (value32 != ZIP64ENDLOCHEADERMAGIC) - return 0; - /* Number of the disk with the start of the zip64 end of central directory */ - if (zipReadUInt32(pzlib_filefunc_def, filestream, &value32) != ZIP_OK) - return 0; - /* Relative offset of the zip64 end of central directory record */ - if (zipReadUInt64(pzlib_filefunc_def, filestream, &offset) != ZIP_OK) - return 0; - /* Total number of disks */ - if (zipReadUInt32(pzlib_filefunc_def, filestream, &value32) != ZIP_OK) - return 0; - /* Goto end of central directory record */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, offset, ZLIB_FILEFUNC_SEEK_SET) != 0) - return 0; - /* The signature */ - if (zipReadUInt32(pzlib_filefunc_def, filestream, &value32) != ZIP_OK) - return 0; - if (value32 != ZIP64ENDHEADERMAGIC) - return 0; - - return offset; -} - -extern zipFile ZEXPORT zipOpen4(const void *path, int append, uint64_t disk_size, const char **globalcomment, - zlib_filefunc64_32_def *pzlib_filefunc64_32_def) -{ - zip64_internal ziinit; - zip64_internal *zi = NULL; -#ifndef NO_ADDFILEINEXISTINGZIP - uint64_t byte_before_the_zipfile = 0; /* byte before the zipfile, (>0 for sfx)*/ - uint64_t size_central_dir = 0; /* size of the central directory */ - uint64_t offset_central_dir = 0; /* offset of start of central directory */ - uint64_t number_entry_CD = 0; /* total number of entries in the central dir */ - uint64_t number_entry = 0; - uint64_t central_pos = 0; - uint64_t size_central_dir_to_read = 0; - uint16_t value16 = 0; - uint32_t value32 = 0; - uint16_t size_comment = 0; - size_t buf_size = SIZEDATA_INDATABLOCK; - void *buf_read = NULL; -#endif - int err = ZIP_OK; - int mode = 0; - - ziinit.z_filefunc.zseek32_file = NULL; - ziinit.z_filefunc.ztell32_file = NULL; - - if (pzlib_filefunc64_32_def == NULL) - fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64); - else - ziinit.z_filefunc = *pzlib_filefunc64_32_def; - - if (append == APPEND_STATUS_CREATE) - mode = (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE); - else - mode = (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING); - - ziinit.filestream = ZOPEN64(ziinit.z_filefunc, path, mode); - if (ziinit.filestream == NULL) - return NULL; - - if (append == APPEND_STATUS_CREATEAFTER) - { - /* Don't support spanning ZIP with APPEND_STATUS_CREATEAFTER */ - if (disk_size > 0) - return NULL; - - ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END); - } - - ziinit.filestream_with_CD = ziinit.filestream; - ziinit.append = append; - ziinit.number_disk = 0; - ziinit.number_disk_with_CD = 0; - ziinit.disk_size = disk_size; - ziinit.in_opened_file_inzip = 0; - ziinit.ci.stream_initialised = 0; - ziinit.number_entry = 0; - ziinit.add_position_when_writting_offset = 0; - init_linkedlist(&(ziinit.central_dir)); - - zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); - if (zi == NULL) - { - ZCLOSE64(ziinit.z_filefunc,ziinit.filestream); - return NULL; - } - -#ifndef NO_ADDFILEINEXISTINGZIP - /* Add file in a zipfile */ - ziinit.globalcomment = NULL; - if (append == APPEND_STATUS_ADDINZIP) - { - /* Read and Cache Central Directory Records */ - central_pos = zipSearchCentralDir(&ziinit.z_filefunc,ziinit.filestream); - /* Disable to allow appending to empty ZIP archive (must be standard zip, not zip64) - if (central_pos == 0) - err = ZIP_ERRNO; - */ - - if (err == ZIP_OK) - { - /* Read end of central directory info */ - if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET) != 0) - err = ZIP_ERRNO; - - /* The signature, already checked */ - if (zipReadUInt32(&ziinit.z_filefunc, ziinit.filestream, &value32) != ZIP_OK) - err = ZIP_ERRNO; - /* Number of this disk */ - if (zipReadUInt16(&ziinit.z_filefunc, ziinit.filestream, &value16) != ZIP_OK) - err = ZIP_ERRNO; - ziinit.number_disk = value16; - /* Number of the disk with the start of the central directory */ - if (zipReadUInt16(&ziinit.z_filefunc, ziinit.filestream, &value16) != ZIP_OK) - err = ZIP_ERRNO; - ziinit.number_disk_with_CD = value16; - /* Total number of entries in the central dir on this disk */ - number_entry = 0; - if (zipReadUInt16(&ziinit.z_filefunc, ziinit.filestream, &value16) != ZIP_OK) - err = ZIP_ERRNO; - else - number_entry = value16; - /* Total number of entries in the central dir */ - number_entry_CD = 0; - if (zipReadUInt16(&ziinit.z_filefunc, ziinit.filestream, &value16) != ZIP_OK) - err = ZIP_ERRNO; - else - number_entry_CD = value16; - if (number_entry_CD!=number_entry) - err = ZIP_BADZIPFILE; - /* Size of the central directory */ - size_central_dir = 0; - if (zipReadUInt32(&ziinit.z_filefunc, ziinit.filestream, &value32) != ZIP_OK) - err = ZIP_ERRNO; - else - size_central_dir = value32; - /* Offset of start of central directory with respect to the starting disk number */ - offset_central_dir = 0; - if (zipReadUInt32(&ziinit.z_filefunc, ziinit.filestream, &value32) != ZIP_OK) - err = ZIP_ERRNO; - else - offset_central_dir = value32; - /* Zipfile global comment length */ - if (zipReadUInt16(&ziinit.z_filefunc, ziinit.filestream, &size_comment) != ZIP_OK) - err = ZIP_ERRNO; - - if ((err == ZIP_OK) && ((number_entry_CD == UINT16_MAX) || (offset_central_dir == UINT32_MAX))) - { - /* Format should be Zip64, as the central directory or file size is too large */ - central_pos = zipSearchCentralDir64(&ziinit.z_filefunc, ziinit.filestream, central_pos); - - if (central_pos) - { - uint64_t sizeEndOfCentralDirectory; - - if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) - err = ZIP_ERRNO; - - /* The signature, already checked */ - if (zipReadUInt32(&ziinit.z_filefunc, ziinit.filestream, &value32) != ZIP_OK) - err = ZIP_ERRNO; - /* Size of zip64 end of central directory record */ - if (zipReadUInt64(&ziinit.z_filefunc, ziinit.filestream, &sizeEndOfCentralDirectory) != ZIP_OK) - err = ZIP_ERRNO; - /* Version made by */ - if (zipReadUInt16(&ziinit.z_filefunc, ziinit.filestream, &value16) != ZIP_OK) - err = ZIP_ERRNO; - /* Version needed to extract */ - if (zipReadUInt16(&ziinit.z_filefunc, ziinit.filestream, &value16) != ZIP_OK) - err = ZIP_ERRNO; - /* Number of this disk */ - if (zipReadUInt32(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk) != ZIP_OK) - err = ZIP_ERRNO; - /* Number of the disk with the start of the central directory */ - if (zipReadUInt32(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk_with_CD) != ZIP_OK) - err = ZIP_ERRNO; - /* Total number of entries in the central directory on this disk */ - if (zipReadUInt64(&ziinit.z_filefunc, ziinit.filestream, &number_entry) != ZIP_OK) - err = ZIP_ERRNO; - /* Total number of entries in the central directory */ - if (zipReadUInt64(&ziinit.z_filefunc, ziinit.filestream, &number_entry_CD) != ZIP_OK) - err = ZIP_ERRNO; - if (number_entry_CD!=number_entry) - err = ZIP_BADZIPFILE; - /* Size of the central directory */ - if (zipReadUInt64(&ziinit.z_filefunc, ziinit.filestream, &size_central_dir) != ZIP_OK) - err = ZIP_ERRNO; - /* Offset of start of central directory with respect to the starting disk number */ - if (zipReadUInt64(&ziinit.z_filefunc, ziinit.filestream, &offset_central_dir) != ZIP_OK) - err = ZIP_ERRNO; - } - else - err = ZIP_BADZIPFILE; - } - } - - if ((err == ZIP_OK) && (central_pos < offset_central_dir + size_central_dir)) - err = ZIP_BADZIPFILE; - - if ((err == ZIP_OK) && (size_comment > 0)) - { - ziinit.globalcomment = (char*)ALLOC(size_comment+1); - if (ziinit.globalcomment) - { - if (ZREAD64(ziinit.z_filefunc, ziinit.filestream, ziinit.globalcomment, size_comment) != size_comment) - err = ZIP_ERRNO; - else - ziinit.globalcomment[size_comment] = 0; - } - } - - if (err != ZIP_OK) - { - ZCLOSE64(ziinit.z_filefunc, ziinit.filestream); - TRYFREE(ziinit.globalcomment); - TRYFREE(zi); - return NULL; - } - - byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); - ziinit.add_position_when_writting_offset = byte_before_the_zipfile; - - /* Store central directory in memory */ - size_central_dir_to_read = size_central_dir; - buf_size = SIZEDATA_INDATABLOCK; - buf_read = (void*)ALLOC(buf_size); - - if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, - offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) - err = ZIP_ERRNO; - - while ((size_central_dir_to_read > 0) && (err == ZIP_OK)) - { - uint64_t read_this = SIZEDATA_INDATABLOCK; - if (read_this > size_central_dir_to_read) - read_this = size_central_dir_to_read; - - if (ZREAD64(ziinit.z_filefunc, ziinit.filestream, buf_read, (uint32_t)read_this) != read_this) - err = ZIP_ERRNO; - - if (err == ZIP_OK) - err = add_data_in_datablock(&ziinit.central_dir, buf_read, (uint32_t)read_this); - - size_central_dir_to_read -= read_this; - } - TRYFREE(buf_read); - - ziinit.number_entry = number_entry_CD; - - if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, - offset_central_dir+byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) - err = ZIP_ERRNO; - } - - if (globalcomment) - *globalcomment = ziinit.globalcomment; -#endif - - if (err != ZIP_OK) - { -#ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(ziinit.globalcomment); -#endif - TRYFREE(zi); - return NULL; - } - - *zi = ziinit; - zipGoToFirstDisk((zipFile)zi); - return(zipFile)zi; -} - -extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment, - zlib_filefunc_def *pzlib_filefunc32_def) -{ - if (pzlib_filefunc32_def != NULL) - { - zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; - fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); - return zipOpen4(path, append, 0, globalcomment, &zlib_filefunc64_32_def_fill); - } - return zipOpen4(path, append, 0, globalcomment, NULL); -} - -extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment, - zlib_filefunc64_def *pzlib_filefunc_def) -{ - if (pzlib_filefunc_def != NULL) - { - zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; - zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; - zlib_filefunc64_32_def_fill.ztell32_file = NULL; - zlib_filefunc64_32_def_fill.zseek32_file = NULL; - return zipOpen4(path, append, 0, globalcomment, &zlib_filefunc64_32_def_fill); - } - return zipOpen4(path, append, 0, globalcomment, NULL); -} - -extern zipFile ZEXPORT zipOpen3(const char *path, int append, uint64_t disk_size, const char **globalcomment, - zlib_filefunc_def *pzlib_filefunc32_def) -{ - if (pzlib_filefunc32_def != NULL) - { - zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; - fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); - return zipOpen4(path, append, disk_size, globalcomment, &zlib_filefunc64_32_def_fill); - } - return zipOpen4(path, append, disk_size, globalcomment, NULL); -} - -extern zipFile ZEXPORT zipOpen3_64(const void *path, int append, uint64_t disk_size, const char **globalcomment, - zlib_filefunc64_def *pzlib_filefunc_def) -{ - if (pzlib_filefunc_def != NULL) - { - zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; - zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; - zlib_filefunc64_32_def_fill.ztell32_file = NULL; - zlib_filefunc64_32_def_fill.zseek32_file = NULL; - return zipOpen4(path, append, disk_size, globalcomment, &zlib_filefunc64_32_def_fill); - } - return zipOpen4(path, append, disk_size, globalcomment, NULL); -} - -extern zipFile ZEXPORT zipOpen(const char *path, int append) -{ - return zipOpen3((const void*)path, append, 0, NULL, NULL); -} - -extern zipFile ZEXPORT zipOpen64(const void *path, int append) -{ - return zipOpen3(path, append, 0, NULL, NULL); -} - -extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel, - int strategy, const char *password, uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64) -{ - zip64_internal *zi = NULL; - uint64_t size_available = 0; - uint64_t size_needed = 0; - uint16_t size_filename = 0; - uint16_t size_comment = 0; - uint16_t i = 0; - unsigned char *central_dir = NULL; - int err = ZIP_OK; - -#ifdef NOCRYPT - (crc_for_crypting); - if (password != NULL) - return ZIP_PARAMERROR; -#endif - - if (file == NULL) - return ZIP_PARAMERROR; - - if ((method != 0) && -#ifdef HAVE_BZIP2 - (method != Z_BZIP2ED) && -#endif - (method != Z_DEFLATED)) - return ZIP_PARAMERROR; - - zi = (zip64_internal*)file; - - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); - if (err != ZIP_OK) - return err; - } - - if (filename == NULL) - filename = "-"; - if (comment != NULL) - size_comment = (uint16_t)strlen(comment); - - size_filename = (uint16_t)strlen(filename); - - if (zipfi == NULL) - zi->ci.dos_date = 0; - else - { - if (zipfi->dos_date != 0) - zi->ci.dos_date = zipfi->dos_date; - } - - zi->ci.method = method; - zi->ci.compression_method = method; - zi->ci.raw = raw; - zi->ci.flag = flag_base | 8; - if ((level == 8) || (level == 9)) - zi->ci.flag |= 2; - if (level == 2) - zi->ci.flag |= 4; - if (level == 1) - zi->ci.flag |= 6; - - if (password != NULL) - { - zi->ci.flag |= 1; -#ifdef HAVE_AES - zi->ci.method = AES_METHOD; -#endif - } - else - { - zi->ci.flag &= ~1; - } - - if (zi->disk_size > 0) - { - if ((zi->number_disk == 0) && (zi->number_entry == 0)) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)DISKHEADERMAGIC, 4); - - /* Make sure enough space available on current disk for local header */ - zipGetDiskSizeAvailable((zipFile)zi, &size_available); - size_needed = 30 + size_filename + size_extrafield_local; -#ifdef HAVE_AES - if (zi->ci.method == AES_METHOD) - size_needed += 11; -#endif - if (size_available < size_needed) - zipGoToNextDisk((zipFile)zi); - } - - zi->ci.zip64 = zip64; - - zi->ci.pos_local_header = ZTELL64(zi->z_filefunc, zi->filestream); - if (zi->ci.pos_local_header >= UINT32_MAX) - zi->ci.zip64 = 1; - - zi->ci.size_comment = size_comment; - zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global; - zi->ci.size_centralextra = size_extrafield_global; - zi->ci.size_centralextrafree = 32; /* Extra space reserved for ZIP64 extra info */ -#ifdef HAVE_AES - if (zi->ci.method == AES_METHOD) - zi->ci.size_centralextrafree += 11; /* Extra space reserved for AES extra info */ -#endif - zi->ci.central_header = (char*)ALLOC((uint32_t)zi->ci.size_centralheader + zi->ci.size_centralextrafree + size_comment); - zi->ci.number_disk = zi->number_disk; - - /* Write central directory header */ - central_dir = (unsigned char*)zi->ci.central_header; - zipWriteValueToMemoryAndMove(¢ral_dir, (uint32_t)CENTRALHEADERMAGIC, 4); - zipWriteValueToMemoryAndMove(¢ral_dir, version_madeby, 2); - if (zi->ci.zip64) - zipWriteValueToMemoryAndMove(¢ral_dir, (uint16_t)45, 2); - else - zipWriteValueToMemoryAndMove(¢ral_dir, (uint16_t)20, 2); - zipWriteValueToMemoryAndMove(¢ral_dir, zi->ci.flag, 2); - zipWriteValueToMemoryAndMove(¢ral_dir, zi->ci.method, 2); - zipWriteValueToMemoryAndMove(¢ral_dir, zi->ci.dos_date, 4); - zipWriteValueToMemoryAndMove(¢ral_dir, (uint32_t)0, 4); /*crc*/ - zipWriteValueToMemoryAndMove(¢ral_dir, (uint32_t)0, 4); /*compr size*/ - zipWriteValueToMemoryAndMove(¢ral_dir, (uint32_t)0, 4); /*uncompr size*/ - zipWriteValueToMemoryAndMove(¢ral_dir, size_filename, 2); - zipWriteValueToMemoryAndMove(¢ral_dir, size_extrafield_global, 2); - zipWriteValueToMemoryAndMove(¢ral_dir, size_comment, 2); - zipWriteValueToMemoryAndMove(¢ral_dir, (uint16_t)zi->ci.number_disk, 2); /*disk nm start*/ - - if (zipfi == NULL) - zipWriteValueToMemoryAndMove(¢ral_dir, (uint16_t)0, 2); - else - zipWriteValueToMemoryAndMove(¢ral_dir, zipfi->internal_fa, 2); - if (zipfi == NULL) - zipWriteValueToMemoryAndMove(¢ral_dir, (uint32_t)0, 4); - else - zipWriteValueToMemoryAndMove(¢ral_dir, zipfi->external_fa, 4); - if (zi->ci.pos_local_header >= UINT32_MAX) - zipWriteValueToMemoryAndMove(¢ral_dir, UINT32_MAX, 4); - else - zipWriteValueToMemoryAndMove(¢ral_dir, - (uint32_t)(zi->ci.pos_local_header - zi->add_position_when_writting_offset), 4); - - for (i = 0; i < size_filename; i++) - zi->ci.central_header[SIZECENTRALHEADER+i] = filename[i]; - for (i = 0; i < size_extrafield_global; i++) - zi->ci.central_header[SIZECENTRALHEADER+size_filename+i] = - ((const char*)extrafield_global)[i]; - - /* Store comment at the end for later repositioning */ - for (i = 0; i < size_comment; i++) - zi->ci.central_header[zi->ci.size_centralheader+ - zi->ci.size_centralextrafree+i] = comment[i]; - - if (zi->ci.central_header == NULL) - return ZIP_INTERNALERROR; - - /* Write the local header */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)LOCALHEADERMAGIC, 4); - - if (err == ZIP_OK) - { - if (zi->ci.zip64) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint16_t)45, 2); /* version needed to extract */ - else - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint16_t)20, 2); /* version needed to extract */ - } - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->ci.flag, 2); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->ci.method, 2); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->ci.dos_date, 4); - - /* CRC & compressed size & uncompressed size is in data descriptor */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)0, 4); /* crc 32, unknown */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)0, 4); /* compressed size, unknown */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)0, 4); /* uncompressed size, unknown */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, size_filename, 2); - if (err == ZIP_OK) - { - uint64_t size_extrafield = size_extrafield_local; -#ifdef HAVE_AES - if (zi->ci.method == AES_METHOD) - size_extrafield += 11; -#endif - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint16_t)size_extrafield, 2); - } - if ((err == ZIP_OK) && (size_filename > 0)) - { - if (ZWRITE64(zi->z_filefunc, zi->filestream, filename, size_filename) != size_filename) - err = ZIP_ERRNO; - } - if ((err == ZIP_OK) && (size_extrafield_local > 0)) - { - if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local) - err = ZIP_ERRNO; - } - -#ifdef HAVE_AES - /* Write the AES extended info */ - if ((err == ZIP_OK) && (zi->ci.method == AES_METHOD)) - { - int headerid = 0x9901; - short datasize = 7; - - err = zipWriteValue(&zi->z_filefunc, zi->filestream, headerid, 2); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, datasize, 2); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, AES_VERSION, 2); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, 'A', 1); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, 'E', 1); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, AES_ENCRYPTIONMODE, 1); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->ci.compression_method, 2); - } -#endif - - zi->ci.crc32 = 0; - zi->ci.stream_initialised = 0; - zi->ci.pos_in_buffered_data = 0; - zi->ci.total_compressed = 0; - zi->ci.total_uncompressed = 0; - -#ifdef HAVE_BZIP2 - zi->ci.bstream.avail_in = (uint16_t)0; - zi->ci.bstream.avail_out = (uint16_t)Z_BUFSIZE; - zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; - zi->ci.bstream.total_in_hi32 = 0; - zi->ci.bstream.total_in_lo32 = 0; - zi->ci.bstream.total_out_hi32 = 0; - zi->ci.bstream.total_out_lo32 = 0; -#endif - - zi->ci.stream.avail_in = (uint16_t)0; - zi->ci.stream.avail_out = Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - zi->ci.stream.total_in = 0; - zi->ci.stream.total_out = 0; - zi->ci.stream.data_type = Z_BINARY; - - if ((err == ZIP_OK) && (!zi->ci.raw)) - { - if (method == Z_DEFLATED) - { - zi->ci.stream.zalloc = (alloc_func)0; - zi->ci.stream.zfree = (free_func)0; - zi->ci.stream.opaque = (voidpf)zi; - - if (windowBits > 0) - windowBits = -windowBits; - -#ifdef HAVE_APPLE_COMPRESSION - err = compression_stream_init(&zi->ci.astream, COMPRESSION_STREAM_ENCODE, COMPRESSION_ZLIB); - if (err == COMPRESSION_STATUS_ERROR) - err = Z_ERRNO; - else - err = Z_OK; -#else - err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy); -#endif - if (err == Z_OK) - zi->ci.stream_initialised = Z_DEFLATED; - } - else if (method == Z_BZIP2ED) - { -#ifdef HAVE_BZIP2 - zi->ci.bstream.bzalloc = 0; - zi->ci.bstream.bzfree = 0; - zi->ci.bstream.opaque = (voidpf)0; - - err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0, 35); - if (err == BZ_OK) - zi->ci.stream_initialised = Z_BZIP2ED; -#endif - } - } - -#ifndef NOCRYPT - if ((err == Z_OK) && (password != NULL)) - { -#ifdef HAVE_AES - if (zi->ci.method == AES_METHOD) - { - unsigned char passverify[AES_PWVERIFYSIZE]; - unsigned char saltvalue[AES_MAXSALTLENGTH]; - uint16_t saltlength = 0; - - if ((AES_ENCRYPTIONMODE < 1) || (AES_ENCRYPTIONMODE > 3)) - return Z_ERRNO; - - saltlength = SALT_LENGTH(AES_ENCRYPTIONMODE); - - prng_init(cryptrand, zi->ci.aes_rng); - prng_rand(saltvalue, saltlength, zi->ci.aes_rng); - prng_end(zi->ci.aes_rng); - - fcrypt_init(AES_ENCRYPTIONMODE, (uint8_t *)password, (uint32_t)strlen(password), saltvalue, passverify, &zi->ci.aes_ctx); - - if (ZWRITE64(zi->z_filefunc, zi->filestream, saltvalue, saltlength) != saltlength) - err = ZIP_ERRNO; - if (ZWRITE64(zi->z_filefunc, zi->filestream, passverify, AES_PWVERIFYSIZE) != AES_PWVERIFYSIZE) - err = ZIP_ERRNO; - - zi->ci.total_compressed += saltlength + AES_PWVERIFYSIZE + AES_AUTHCODESIZE; - } - else -#endif - { - unsigned char buf_head[RAND_HEAD_LEN]; - uint32_t size_head = 0; - uint8_t verify1 = 0; - uint8_t verify2 = 0; - - zi->ci.pcrc_32_tab = get_crc_table(); - - /* - Info-ZIP modification to ZipCrypto format: - If bit 3 of the general purpose bit flag is set, it uses high byte of 16-bit File Time. - - verify1 = (uint8_t)((crc_for_crypting >> 16) & 0xff); - verify2 = (uint8_t)((crc_for_crypting >> 24) & 0xff); */ - - verify1 = (uint8_t)((zi->ci.dos_date >> 16) & 0xff); - verify2 = (uint8_t)((zi->ci.dos_date >> 8) & 0xff); - - size_head = crypthead(password, buf_head, RAND_HEAD_LEN, zi->ci.keys, zi->ci.pcrc_32_tab, verify1, verify2); - zi->ci.total_compressed += size_head; - - if (ZWRITE64(zi->z_filefunc, zi->filestream, buf_head, size_head) != size_head) - err = ZIP_ERRNO; - } - } -#endif - - if (err == Z_OK) - zi->in_opened_file_inzip = 1; - return err; -} - -extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, - int memLevel, int strategy, const char *password, uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base) -{ - return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, - strategy, password, crc_for_crypting, version_madeby, flag_base, 0); -} - -extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, - int memLevel, int strategy, const char *password, uint32_t crc_for_crypting) -{ - return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, - strategy, password, crc_for_crypting, VERSIONMADEBY, 0, 0); -} - -extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, - int memLevel, int strategy, const char *password, uint32_t crc_for_crypting, int zip64) -{ - return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, strategy, - password, crc_for_crypting, VERSIONMADEBY, 0, zip64); -} - -extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw) -{ - return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, 0); -} - -extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int zip64) -{ - return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64); -} - -extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int zip64) -{ - return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64); -} - -extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level) -{ - return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, 0); -} - -/* Flushes the write buffer to disk */ -static int zipFlushWriteBuffer(zip64_internal *zi) -{ - uint64_t size_available = 0; - uint32_t written = 0; - uint32_t total_written = 0; - uint32_t write = 0; - uint32_t max_write = 0; - uint32_t i = 0; - uint8_t t = 0; - int err = ZIP_OK; - - if ((zi->ci.flag & 1) != 0) - { -#ifndef NOCRYPT -#ifdef HAVE_AES - if (zi->ci.method == AES_METHOD) - { - fcrypt_encrypt(zi->ci.buffered_data, zi->ci.pos_in_buffered_data, &zi->ci.aes_ctx); - } - else -#endif - { - for (i = 0; i < zi->ci.pos_in_buffered_data; i++) - zi->ci.buffered_data[i] = (uint8_t)zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i], t); - } -#endif - } - - write = zi->ci.pos_in_buffered_data; - - do - { - max_write = write; - - if (zi->disk_size > 0) - { - zipGetDiskSizeAvailable((zipFile)zi, &size_available); - - if (size_available == 0) - { - err = zipGoToNextDisk((zipFile)zi); - if (err != ZIP_OK) - return err; - } - - if (size_available < (uint64_t)max_write) - max_write = (uint32_t)size_available; - } - - written = ZWRITE64(zi->z_filefunc, zi->filestream, zi->ci.buffered_data + total_written, max_write); - if (written != max_write) - { - err = ZIP_ERRNO; - break; - } - - total_written += written; - write -= written; - } - while (write > 0); - - zi->ci.total_compressed += zi->ci.pos_in_buffered_data; - -#ifdef HAVE_BZIP2 - if (zi->ci.compression_method == Z_BZIP2ED) - { - zi->ci.total_uncompressed += zi->ci.bstream.total_in_lo32; - zi->ci.bstream.total_in_lo32 = 0; - zi->ci.bstream.total_in_hi32 = 0; - } - else -#endif - { - zi->ci.total_uncompressed += zi->ci.stream.total_in; - zi->ci.stream.total_in = 0; - } - - zi->ci.pos_in_buffered_data = 0; - - return err; -} - -extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len) -{ - zip64_internal *zi = NULL; - int err = ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip64_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - - zi->ci.crc32 = (uint32_t)crc32(zi->ci.crc32, buf, len); - -#ifdef HAVE_BZIP2 - if ((zi->ci.compression_method == Z_BZIP2ED) && (!zi->ci.raw)) - { - zi->ci.bstream.next_in = (void*)buf; - zi->ci.bstream.avail_in = len; - err = BZ_RUN_OK; - - while ((err == BZ_RUN_OK) && (zi->ci.bstream.avail_in > 0)) - { - if (zi->ci.bstream.avail_out == 0) - { - err = zipFlushWriteBuffer(zi); - - zi->ci.bstream.avail_out = (uint16_t)Z_BUFSIZE; - zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; - } - else - { - uint32_t total_out_before_lo = zi->ci.bstream.total_out_lo32; - uint32_t total_out_before_hi = zi->ci.bstream.total_out_hi32; - - err = BZ2_bzCompress(&zi->ci.bstream, BZ_RUN); - - zi->ci.pos_in_buffered_data += (uint16_t)(zi->ci.bstream.total_out_lo32 - total_out_before_lo); - } - } - - if (err == BZ_RUN_OK) - err = ZIP_OK; - } - else -#endif - { - zi->ci.stream.next_in = (uint8_t*)buf; - zi->ci.stream.avail_in = len; - - while ((err == ZIP_OK) && (zi->ci.stream.avail_in > 0)) - { - if (zi->ci.stream.avail_out == 0) - { - err = zipFlushWriteBuffer(zi); - - zi->ci.stream.avail_out = Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - - if (err != ZIP_OK) - break; - - if ((zi->ci.compression_method == Z_DEFLATED) && (!zi->ci.raw)) - { -#ifdef HAVE_APPLE_COMPRESSION - uLong total_out_before = zi->ci.stream.total_out; - - zi->ci.astream.src_ptr = zi->ci.stream.next_in; - zi->ci.astream.src_size = zi->ci.stream.avail_in; - zi->ci.astream.dst_ptr = zi->ci.stream.next_out; - zi->ci.astream.dst_size = zi->ci.stream.avail_out; - - compression_status status = 0; - compression_stream_flags flags = 0; - - status = compression_stream_process(&zi->ci.astream, flags); - - uLong total_out_after = len - zi->ci.astream.src_size; - - zi->ci.stream.next_in = zi->ci.astream.src_ptr; - zi->ci.stream.avail_in = zi->ci.astream.src_size; - zi->ci.stream.next_out = zi->ci.astream.dst_ptr; - zi->ci.stream.avail_out = zi->ci.astream.dst_size; - zi->ci.stream.total_in += total_out_after; - //zi->ci.stream.total_out += copy_this; - zi->ci.pos_in_buffered_data += total_out_after; - - if (status == COMPRESSION_STATUS_ERROR) - err = ZIP_INTERNALERROR; -#else - uint32_t total_out_before = (uint32_t)zi->ci.stream.total_out; - err = deflate(&zi->ci.stream, Z_NO_FLUSH); - zi->ci.pos_in_buffered_data += (uint32_t)(zi->ci.stream.total_out - total_out_before); -#endif - } - else - { - uint32_t copy_this = 0; - uint32_t i = 0; - if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) - copy_this = zi->ci.stream.avail_in; - else - copy_this = zi->ci.stream.avail_out; - - for (i = 0; i < copy_this; i++) - *(((char*)zi->ci.stream.next_out)+i) = - *(((const char*)zi->ci.stream.next_in)+i); - - zi->ci.stream.avail_in -= copy_this; - zi->ci.stream.avail_out -= copy_this; - zi->ci.stream.next_in += copy_this; - zi->ci.stream.next_out += copy_this; - zi->ci.stream.total_in += copy_this; - zi->ci.stream.total_out += copy_this; - zi->ci.pos_in_buffered_data += copy_this; - } - } - } - - return err; -} - -extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32) -{ - zip64_internal *zi = NULL; - uint16_t extra_data_size = 0; - uint32_t i = 0; - unsigned char *extra_info = NULL; - int err = ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip64_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - zi->ci.stream.avail_in = 0; - - if (!zi->ci.raw) - { - if (zi->ci.compression_method == Z_DEFLATED) - { - while (err == ZIP_OK) - { - uint32_t total_out_before = 0; - - if (zi->ci.stream.avail_out == 0) - { - err = zipFlushWriteBuffer(zi); - - zi->ci.stream.avail_out = Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - - if (err != ZIP_OK) - break; - -#ifdef HAVE_APPLE_COMPRESSION - total_out_before = zi->ci.stream.total_out; - - zi->ci.astream.src_ptr = zi->ci.stream.next_in; - zi->ci.astream.src_size = zi->ci.stream.avail_in; - zi->ci.astream.dst_ptr = zi->ci.stream.next_out; - zi->ci.astream.dst_size = zi->ci.stream.avail_out; - - compression_status status = 0; - status = compression_stream_process(&zi->ci.astream, COMPRESSION_STREAM_FINALIZE); - - uint32_t total_out_after = Z_BUFSIZE - zi->ci.astream.dst_size; - - zi->ci.stream.next_in = zi->ci.astream.src_ptr; - zi->ci.stream.avail_in = zi->ci.astream.src_size; - zi->ci.stream.next_out = zi->ci.astream.dst_ptr; - zi->ci.stream.avail_out = zi->ci.astream.dst_size; - //zi->ci.stream.total_in += total_out_after; - //zi->ci.stream.total_out += copy_this; - zi->ci.pos_in_buffered_data += total_out_after; - - if (status == COMPRESSION_STATUS_ERROR) - { - err = ZIP_INTERNALERROR; - } - else if (status == COMPRESSION_STATUS_END) - { - err = Z_STREAM_END; - } -#else - total_out_before = (uint32_t)zi->ci.stream.total_out; - err = deflate(&zi->ci.stream, Z_FINISH); - zi->ci.pos_in_buffered_data += (uint16_t)(zi->ci.stream.total_out - total_out_before); -#endif - } - } - else if (zi->ci.compression_method == Z_BZIP2ED) - { -#ifdef HAVE_BZIP2 - err = BZ_FINISH_OK; - while (err == BZ_FINISH_OK) - { - uint32_t total_out_before = 0; - - if (zi->ci.bstream.avail_out == 0) - { - err = zipFlushWriteBuffer(zi); - - zi->ci.bstream.avail_out = (uint16_t)Z_BUFSIZE; - zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; - } - - total_out_before = zi->ci.bstream.total_out_lo32; - err = BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH); - if (err == BZ_STREAM_END) - err = Z_STREAM_END; - zi->ci.pos_in_buffered_data += (uint16_t)(zi->ci.bstream.total_out_lo32 - total_out_before); - } - - if (err == BZ_FINISH_OK) - err = ZIP_OK; -#endif - } - } - - if (err == Z_STREAM_END) - err = ZIP_OK; /* this is normal */ - - if ((zi->ci.pos_in_buffered_data > 0) && (err == ZIP_OK)) - { - err = zipFlushWriteBuffer(zi); - } - -#ifdef HAVE_AES - if (zi->ci.method == AES_METHOD) - { - unsigned char authcode[AES_AUTHCODESIZE]; - - fcrypt_end(authcode, &zi->ci.aes_ctx); - - if (ZWRITE64(zi->z_filefunc, zi->filestream, authcode, AES_AUTHCODESIZE) != AES_AUTHCODESIZE) - err = ZIP_ERRNO; - } -#endif - - if (!zi->ci.raw) - { - if (zi->ci.compression_method == Z_DEFLATED) - { - int tmp_err = 0; -#ifdef HAVE_APPLE_COMPRESSION - tmp_err = compression_stream_destroy(&zi->ci.astream); -#else - tmp_err = deflateEnd(&zi->ci.stream); -#endif - if (err == ZIP_OK) - err = tmp_err; - zi->ci.stream_initialised = 0; - } -#ifdef HAVE_BZIP2 - else if (zi->ci.compression_method == Z_BZIP2ED) - { - int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream); - if (err == ZIP_OK) - err = tmperr; - zi->ci.stream_initialised = 0; - } -#endif - - crc32 = zi->ci.crc32; - uncompressed_size = zi->ci.total_uncompressed; - } - - /* Write data descriptor */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)DATADESCRIPTORMAGIC, 4); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, crc32, 4); - if (err == ZIP_OK) - { - if (zi->ci.zip64) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->ci.total_compressed, 8); - else - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)zi->ci.total_compressed, 4); - } - if (err == ZIP_OK) - { - if (zi->ci.zip64) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8); - else - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)uncompressed_size, 4); - } - - /* Update crc and sizes to central directory */ - zipWriteValueToMemory(zi->ci.central_header + 16, crc32, 4); /* crc */ - if (zi->ci.total_compressed >= UINT32_MAX) - zipWriteValueToMemory(zi->ci.central_header + 20, UINT32_MAX, 4); /* compr size */ - else - zipWriteValueToMemory(zi->ci.central_header + 20, zi->ci.total_compressed, 4); /* compr size */ - if (uncompressed_size >= UINT32_MAX) - zipWriteValueToMemory(zi->ci.central_header + 24, UINT32_MAX, 4); /* uncompr size */ - else - zipWriteValueToMemory(zi->ci.central_header + 24, uncompressed_size, 4); /* uncompr size */ - if (zi->ci.stream.data_type == Z_ASCII) - zipWriteValueToMemory(zi->ci.central_header + 36, (uint16_t)Z_ASCII, 2); /* internal file attrib */ - - /* Add ZIP64 extra info field for uncompressed size */ - if (uncompressed_size >= UINT32_MAX) - extra_data_size += 8; - /* Add ZIP64 extra info field for compressed size */ - if (zi->ci.total_compressed >= UINT32_MAX) - extra_data_size += 8; - /* Add ZIP64 extra info field for relative offset to local file header of current file */ - if (zi->ci.pos_local_header >= UINT32_MAX) - extra_data_size += 8; - - /* Add ZIP64 extra info header to central directory */ - if (extra_data_size > 0) - { - if ((uint32_t)(extra_data_size + 4) > zi->ci.size_centralextrafree) - return ZIP_BADZIPFILE; - - extra_info = (unsigned char*)zi->ci.central_header + zi->ci.size_centralheader; - - zipWriteValueToMemoryAndMove(&extra_info, 0x0001, 2); - zipWriteValueToMemoryAndMove(&extra_info, extra_data_size, 2); - - if (uncompressed_size >= UINT32_MAX) - zipWriteValueToMemoryAndMove(&extra_info, uncompressed_size, 8); - if (zi->ci.total_compressed >= UINT32_MAX) - zipWriteValueToMemoryAndMove(&extra_info, zi->ci.total_compressed, 8); - if (zi->ci.pos_local_header >= UINT32_MAX) - zipWriteValueToMemoryAndMove(&extra_info, zi->ci.pos_local_header, 8); - - zi->ci.size_centralextrafree -= extra_data_size + 4; - zi->ci.size_centralheader += extra_data_size + 4; - zi->ci.size_centralextra += extra_data_size + 4; - - zipWriteValueToMemory(zi->ci.central_header + 30, zi->ci.size_centralextra, 2); - } - -#ifdef HAVE_AES - /* Write AES extra info header to central directory */ - if (zi->ci.method == AES_METHOD) - { - extra_info = (unsigned char*)zi->ci.central_header + zi->ci.size_centralheader; - extra_data_size = 7; - - if ((uint32_t)(extra_data_size + 4) > zi->ci.size_centralextrafree) - return ZIP_BADZIPFILE; - - zipWriteValueToMemoryAndMove(&extra_info, 0x9901, 2); - zipWriteValueToMemoryAndMove(&extra_info, extra_data_size, 2); - zipWriteValueToMemoryAndMove(&extra_info, AES_VERSION, 2); - zipWriteValueToMemoryAndMove(&extra_info, 'A', 1); - zipWriteValueToMemoryAndMove(&extra_info, 'E', 1); - zipWriteValueToMemoryAndMove(&extra_info, AES_ENCRYPTIONMODE, 1); - zipWriteValueToMemoryAndMove(&extra_info, zi->ci.compression_method, 2); - - zi->ci.size_centralextrafree -= extra_data_size + 4; - zi->ci.size_centralheader += extra_data_size + 4; - zi->ci.size_centralextra += extra_data_size + 4; - - zipWriteValueToMemory(zi->ci.central_header + 30, zi->ci.size_centralextra, 2); - } -#endif - /* Restore comment to correct position */ - for (i = 0; i < zi->ci.size_comment; i++) - zi->ci.central_header[zi->ci.size_centralheader+i] = - zi->ci.central_header[zi->ci.size_centralheader+zi->ci.size_centralextrafree+i]; - zi->ci.size_centralheader += zi->ci.size_comment; - - if (err == ZIP_OK) - err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, zi->ci.size_centralheader); - - free(zi->ci.central_header); - - zi->number_entry++; - zi->in_opened_file_inzip = 0; - - return err; -} - -extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32) -{ - return zipCloseFileInZipRaw64(file, uncompressed_size, crc32); -} - -extern int ZEXPORT zipCloseFileInZip(zipFile file) -{ - return zipCloseFileInZipRaw(file, 0, 0); -} - -extern int ZEXPORT zipClose(zipFile file, const char *global_comment) -{ - return zipClose_64(file, global_comment); -} - -extern int ZEXPORT zipClose_64(zipFile file, const char *global_comment) -{ - return zipClose2_64(file, global_comment, VERSIONMADEBY); -} - -extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby) -{ - zip64_internal *zi = NULL; - uint32_t size_centraldir = 0; - uint16_t size_global_comment = 0; - uint64_t centraldir_pos_inzip = 0; - uint64_t pos = 0; - uint64_t cd_pos = 0; - uint32_t write = 0; - int err = ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip64_internal*)file; - - if (zi->in_opened_file_inzip == 1) - err = zipCloseFileInZip(file); - -#ifndef NO_ADDFILEINEXISTINGZIP - if (global_comment == NULL) - global_comment = zi->globalcomment; -#endif - - if (zi->filestream != zi->filestream_with_CD) - { - if (ZCLOSE64(zi->z_filefunc, zi->filestream) != 0) - if (err == ZIP_OK) - err = ZIP_ERRNO; - if (zi->disk_size > 0) - zi->number_disk_with_CD = zi->number_disk + 1; - zi->filestream = zi->filestream_with_CD; - } - - centraldir_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream); - - if (err == ZIP_OK) - { - linkedlist_datablock_internal *ldi = zi->central_dir.first_block; - while (ldi != NULL) - { - if ((err == ZIP_OK) && (ldi->filled_in_this_block > 0)) - { - write = ZWRITE64(zi->z_filefunc, zi->filestream, ldi->data, ldi->filled_in_this_block); - if (write != ldi->filled_in_this_block) - err = ZIP_ERRNO; - } - - size_centraldir += ldi->filled_in_this_block; - ldi = ldi->next_datablock; - } - } - - free_linkedlist(&(zi->central_dir)); - - pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; - - /* Write the ZIP64 central directory header */ - if (pos >= UINT32_MAX || zi->number_entry > UINT32_MAX) - { - uint64_t zip64_eocd_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream); - uint32_t zip64_datasize = 44; - - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)ZIP64ENDHEADERMAGIC, 4); - - /* Size of this 'zip64 end of central directory' */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint64_t)zip64_datasize, 8); - /* Version made by */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, version_madeby, 2); - /* version needed */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint16_t)45, 2); - /* Number of this disk */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->number_disk_with_CD, 4); - /* Number of the disk with the start of the central directory */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->number_disk_with_CD, 4); - /* Total number of entries in the central dir on this disk */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); - /* Total number of entries in the central dir */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); - /* Size of the central directory */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint64_t)size_centraldir, 8); - - if (err == ZIP_OK) - { - /* Offset of start of central directory with respect to the starting disk number */ - cd_pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; - err = zipWriteValue(&zi->z_filefunc, zi->filestream, cd_pos, 8); - } - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)ZIP64ENDLOCHEADERMAGIC, 4); - - /* Number of the disk with the start of the central directory */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->number_disk_with_CD, 4); - /* Relative offset to the Zip64EndOfCentralDirectory */ - if (err == ZIP_OK) - { - cd_pos = zip64_eocd_pos_inzip - zi->add_position_when_writting_offset; - err = zipWriteValue(&zi->z_filefunc, zi->filestream, cd_pos, 8); - } - /* Number of the disk with the start of the central directory */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, zi->number_disk_with_CD + 1, 4); - } - - /* Write the central directory header */ - - /* Signature */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)ENDHEADERMAGIC, 4); - /* Number of this disk */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint16_t)zi->number_disk_with_CD, 2); - /* Number of the disk with the start of the central directory */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint16_t)zi->number_disk_with_CD, 2); - /* Total number of entries in the central dir on this disk */ - if (err == ZIP_OK) - { - if (zi->number_entry >= UINT16_MAX) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, UINT16_MAX, 2); /* use value in ZIP64 record */ - else - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint16_t)zi->number_entry, 2); - } - /* Total number of entries in the central dir */ - if (err == ZIP_OK) - { - if (zi->number_entry >= UINT16_MAX) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, UINT16_MAX, 2); /* use value in ZIP64 record */ - else - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint16_t)zi->number_entry, 2); - } - /* Size of the central directory */ - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, size_centraldir, 4); - /* Offset of start of central directory with respect to the starting disk number */ - if (err == ZIP_OK) - { - cd_pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; - if (pos >= UINT32_MAX) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, UINT32_MAX, 4); - else - err = zipWriteValue(&zi->z_filefunc, zi->filestream, (uint32_t)cd_pos, 4); - } - - /* Write global comment */ - - if (global_comment != NULL) - size_global_comment = (uint16_t)strlen(global_comment); - if (err == ZIP_OK) - err = zipWriteValue(&zi->z_filefunc, zi->filestream, size_global_comment, 2); - if (err == ZIP_OK && size_global_comment > 0) - { - if (ZWRITE64(zi->z_filefunc, zi->filestream, global_comment, size_global_comment) != size_global_comment) - err = ZIP_ERRNO; - } - - if ((ZCLOSE64(zi->z_filefunc, zi->filestream) != 0) && (err == ZIP_OK)) - err = ZIP_ERRNO; - -#ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(zi->globalcomment); -#endif - TRYFREE(zi); - - return err; -} diff --git a/Pods/SSZipArchive/SSZipArchive/minizip/zip.h b/Pods/SSZipArchive/SSZipArchive/minizip/zip.h deleted file mode 100644 index e2a5d1c8..00000000 --- a/Pods/SSZipArchive/SSZipArchive/minizip/zip.h +++ /dev/null @@ -1,192 +0,0 @@ -/* zip.h -- IO on .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - - Copyright (C) 1998-2010 Gilles Vollant - http://www.winimage.com/zLibDll/minizip.html - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson - http://result42.com - - This program is distributed under the terms of the same license as zlib. - See the accompanying LICENSE file for the full text of the license. -*/ - -#ifndef _ZIP_H -#define _ZIP_H - -#define HAVE_AES - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -# include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -# include "ioapi.h" -#endif - -#ifdef HAVE_BZIP2 -# include "bzlib.h" -#endif - -#define Z_BZIP2ED 12 - -#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagzipFile__ { int unused; } zip_file__; -typedef zip_file__ *zipFile; -#else -typedef voidp zipFile; -#endif - -#define ZIP_OK (0) -#define ZIP_EOF (0) -#define ZIP_ERRNO (Z_ERRNO) -#define ZIP_PARAMERROR (-102) -#define ZIP_BADZIPFILE (-103) -#define ZIP_INTERNALERROR (-104) - -#ifndef DEF_MEM_LEVEL -# if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -# else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -# endif -#endif - -typedef struct -{ - uint32_t dos_date; - uint16_t internal_fa; /* internal file attributes 2 bytes */ - uint32_t external_fa; /* external file attributes 4 bytes */ -} zip_fileinfo; - -#define APPEND_STATUS_CREATE (0) -#define APPEND_STATUS_CREATEAFTER (1) -#define APPEND_STATUS_ADDINZIP (2) - -/***************************************************************************/ -/* Writing a zip file */ - -extern zipFile ZEXPORT zipOpen(const char *path, int append); -extern zipFile ZEXPORT zipOpen64(const void *path, int append); -/* Create a zipfile. - - path should contain the full path (by example, on a Windows XP computer - "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip". - - return NULL if zipfile cannot be opened - return zipFile handle if no error - - If the file path exist and append == APPEND_STATUS_CREATEAFTER, the zip - will be created at the end of the file. (useful if the file contain a self extractor code) - If the file path exist and append == APPEND_STATUS_ADDINZIP, we will add files in existing - zip (be sure you don't add file that doesn't exist) - - NOTE: There is no delete function into a zipfile. If you want delete file into a zipfile, - you must open a zipfile, and create another. Of course, you can use RAW reading and writing to copy - the file you did not want delete. */ - -extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment, - zlib_filefunc_def *pzlib_filefunc_def); - -extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment, - zlib_filefunc64_def *pzlib_filefunc_def); - -extern zipFile ZEXPORT zipOpen3(const char *path, int append, uint64_t disk_size, - const char **globalcomment, zlib_filefunc_def *pzlib_filefunc_def); -/* Same as zipOpen2 but allows specification of spanned zip size */ - -extern zipFile ZEXPORT zipOpen3_64(const void *path, int append, uint64_t disk_size, - const char **globalcomment, zlib_filefunc64_def *pzlib_filefunc_def); - -extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level); -/* Open a file in the ZIP for writing. - - filename : the filename in zip (if NULL, '-' without quote will be used - *zipfi contain supplemental information - extrafield_local buffer to store the local header extra field data, can be NULL - size_extrafield_local size of extrafield_local buffer - extrafield_global buffer to store the global header extra field data, can be NULL - size_extrafield_global size of extrafield_local buffer - comment buffer for comment string - method contain the compression method (0 for store, Z_DEFLATED for deflate) - level contain the level of compression (can be Z_DEFAULT_COMPRESSION) - zip64 is set to 1 if a zip64 extended information block should be added to the local file header. - this MUST be '1' if the uncompressed size is >= 0xffffffff. */ - -extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int zip64); -/* Same as zipOpenNewFileInZip with zip64 support */ - -extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw); -/* Same as zipOpenNewFileInZip, except if raw=1, we write raw file */ - -extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int zip64); -/* Same as zipOpenNewFileInZip3 with zip64 support */ - -extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel, - int strategy, const char *password, uint32_t crcForCrypting); -/* Same as zipOpenNewFileInZip2, except - windowBits, memLevel, strategy : see parameter strategy in deflateInit2 - password : crypting password (NULL for no crypting) - crcForCrypting : crc of file to compress (needed for crypting) */ - -extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel, - int strategy, const char *password, uint32_t crc_for_crypting, int zip64); -/* Same as zipOpenNewFileInZip3 with zip64 support */ - -extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel, - int strategy, const char *password, uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base); -/* Same as zipOpenNewFileInZip3 except versionMadeBy & flag fields */ - -extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, - const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, - uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel, - int strategy, const char *password, uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64); -/* Same as zipOpenNewFileInZip4 with zip64 support */ - -extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len); -/* Write data in the zipfile */ - -extern int ZEXPORT zipCloseFileInZip(zipFile file); -/* Close the current file in the zipfile */ - -extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32); -extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32); -/* Close the current file in the zipfile, for file opened with parameter raw=1 in zipOpenNewFileInZip2 - where raw is compressed data. Parameters uncompressed_size and crc32 are value for the uncompressed data. */ - -extern int ZEXPORT zipClose(zipFile file, const char *global_comment); -/* Close the zipfile */ - -extern int ZEXPORT zipClose_64(zipFile file, const char *global_comment); - -extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby); -/* Same as zipClose_64 except version_madeby field */ - -/***************************************************************************/ - -#ifdef __cplusplus -} -#endif - -#endif /* _ZIP_H */ diff --git a/Pods/Target Support Files/Pods-SVGAPlayer/Pods-SVGAPlayer-dummy.m b/Pods/Target Support Files/Pods-SVGAPlayer/Pods-SVGAPlayer-dummy.m deleted file mode 100644 index 71373141..00000000 --- a/Pods/Target Support Files/Pods-SVGAPlayer/Pods-SVGAPlayer-dummy.m +++ /dev/null @@ -1,5 +0,0 @@ -#import -@interface PodsDummy_Pods_SVGAPlayer : NSObject -@end -@implementation PodsDummy_Pods_SVGAPlayer -@end diff --git a/Pods/Target Support Files/SSZipArchive/SSZipArchive-dummy.m b/Pods/Target Support Files/SSZipArchive/SSZipArchive-dummy.m deleted file mode 100644 index 9fabf792..00000000 --- a/Pods/Target Support Files/SSZipArchive/SSZipArchive-dummy.m +++ /dev/null @@ -1,5 +0,0 @@ -#import -@interface PodsDummy_SSZipArchive : NSObject -@end -@implementation PodsDummy_SSZipArchive -@end diff --git a/React/SVGAPlayerManager.h b/React/SVGAPlayerManager.h deleted file mode 100644 index 1b12aa5d..00000000 --- a/React/SVGAPlayerManager.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// SVGAPlayerManager.h -// SVGAPlayer -// -// Created by 崔明辉 on 2017/6/15. -// Copyright © 2017年 UED Center. All rights reserved. -// - -#import -#import - -@interface SVGAPlayerManager : RCTViewManager - -@end diff --git a/React/SVGAPlayerManager.m b/React/SVGAPlayerManager.m deleted file mode 100644 index a2b6fa38..00000000 --- a/React/SVGAPlayerManager.m +++ /dev/null @@ -1,182 +0,0 @@ -// -// SVGAPlayerManager.m -// SVGAPlayer -// -// Created by 崔明辉 on 2017/6/15. -// Copyright © 2017年 UED Center. All rights reserved. -// - -#import "SVGAPlayerManager.h" -#import "SVGAPlayer.h" -#import "SVGAParser.h" -#import - -@interface SVGAPlayer (React) - -@property(nonatomic, copy) NSString *source; -@property(nonatomic, copy) NSString *currentState; -@property(nonatomic, assign) NSInteger toFrame; -@property(nonatomic, assign) NSInteger toPercentage; -@property(nonatomic, copy) RCTBubblingEventBlock onFinished; -@property(nonatomic, copy) RCTBubblingEventBlock onFrame; -@property(nonatomic, copy) RCTBubblingEventBlock onPercentage; - -@end - -@implementation SVGAPlayer (React) - -static int kReactSourceIdentifier; -static int kReactCurrentStateIdentifier; -static int kReactOnFinishedIdentifier; -static int kReactOnFrameIdentifier; -static int kReactOnPercentageIdentifier; - -- (void)loadWithSource:(NSString *)source { - SVGAParser *parser = [[SVGAParser alloc] init]; - if ([source hasPrefix:@"http"] || [source hasPrefix:@"https"]) { - [parser parseWithURL:[NSURL URLWithString:source] - completionBlock:^(SVGAVideoEntity *_Nullable videoItem) { - [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - [self setVideoItem:videoItem]; - [self startAnimation]; - }]; - } - failureBlock:nil]; - } else { - NSString *localPath = [[NSBundle mainBundle] pathForResource:source ofType:@"svga"]; - if (localPath != nil) { - [parser parseWithData:[NSData dataWithContentsOfFile:localPath] - cacheKey:source - completionBlock:^(SVGAVideoEntity *_Nonnull videoItem) { - [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - [self setVideoItem:videoItem]; - [self startAnimation]; - }]; - } - failureBlock:nil]; - } - } -} - -- (void)setSource:(NSString *)source { - if ([source isKindOfClass:[NSString class]] && ([self source] == nil || ![source isEqualToString:[self source]])) { - objc_setAssociatedObject(self, &kReactSourceIdentifier, source, OBJC_ASSOCIATION_COPY_NONATOMIC); - [self loadWithSource:source]; - } -} - -- (NSString *)source { - return objc_getAssociatedObject(self, &kReactSourceIdentifier); -} - -- (void)setCurrentState:(NSString *)currentState { - if ([currentState isKindOfClass:[NSString class]] && - ([self currentState] == nil || ![currentState isEqualToString:[self currentState]])) { - objc_setAssociatedObject(self, &kReactCurrentStateIdentifier, currentState, OBJC_ASSOCIATION_COPY_NONATOMIC); - if ([currentState isEqualToString:@"start"]) { - [self startAnimation]; - } else if ([currentState isEqualToString:@"pause"]) { - [self pauseAnimation]; - } else if ([currentState isEqualToString:@"stop"]) { - [self stopAnimation]; - } else if ([currentState isEqualToString:@"clear"]) { - [self stopAnimation]; - [self clear]; - } - } -} - -- (NSString *)currentState { - return objc_getAssociatedObject(self, &kReactCurrentStateIdentifier); -} - -- (void)setOnFinished:(RCTBubblingEventBlock)onFinished { - objc_setAssociatedObject(self, &kReactOnFinishedIdentifier, onFinished, OBJC_ASSOCIATION_COPY_NONATOMIC); -} - -- (RCTBubblingEventBlock)onFinished { - return objc_getAssociatedObject(self, &kReactOnFinishedIdentifier); -} - -- (void)setOnFrame:(RCTBubblingEventBlock)onFrame { - objc_setAssociatedObject(self, &kReactOnFrameIdentifier, onFrame, OBJC_ASSOCIATION_COPY_NONATOMIC); -} - -- (RCTBubblingEventBlock)onFrame { - return objc_getAssociatedObject(self, &kReactOnFrameIdentifier); -} - -- (void)setOnPercentage:(RCTBubblingEventBlock)onPercentage { - objc_setAssociatedObject(self, &kReactOnPercentageIdentifier, onPercentage, OBJC_ASSOCIATION_COPY_NONATOMIC); -} - -- (RCTBubblingEventBlock)onPercentage { - return objc_getAssociatedObject(self, &kReactOnPercentageIdentifier); -} - -- (void)setToFrame:(NSInteger)toFrame { - if (toFrame < 0) { - return; - } - [self stepToFrame:toFrame andPlay:[self.currentState isEqualToString:@"play"]]; -} - -- (NSInteger)toFrame { - return 0; -} - -- (void)setToPercentage:(NSInteger)toPercentage { - if (toPercentage < 0) { - return; - } - [self stepToPercentage:toPercentage andPlay:[self.currentState isEqualToString:@"play"]]; -} - -- (NSInteger)toPercentage { - return 0.0; -} - -- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player { - if (self.onFinished) { - self.onFinished(@{}); - } -} - -- (void)svgaPlayerDidAnimatedToFrame:(NSInteger)frame { - if (self.onFrame) { - self.onFrame(@{ @"value" : @(frame) }); - } -} - -- (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage { - if (self.onPercentage) { - self.onPercentage(@{ @"value" : @(percentage) }); - } -} - -@end - -@interface SVGAPlayerManager () - -@end - -@implementation SVGAPlayerManager - -RCT_EXPORT_MODULE() -RCT_EXPORT_VIEW_PROPERTY(loops, NSInteger) -RCT_EXPORT_VIEW_PROPERTY(clearsAfterStop, BOOL) -RCT_EXPORT_VIEW_PROPERTY(source, NSString) -RCT_EXPORT_VIEW_PROPERTY(currentState, NSString) -RCT_EXPORT_VIEW_PROPERTY(toFrame, NSInteger) -RCT_EXPORT_VIEW_PROPERTY(toPercentage, NSInteger) -RCT_EXPORT_VIEW_PROPERTY(onFinished, RCTBubblingEventBlock) -RCT_EXPORT_VIEW_PROPERTY(onFrame, RCTBubblingEventBlock) -RCT_EXPORT_VIEW_PROPERTY(onPercentage, RCTBubblingEventBlock) - -- (UIView *)view { - SVGAPlayer *aPlayer = [[SVGAPlayer alloc] init]; - aPlayer.delegate = aPlayer; - return aPlayer; -} - -@end diff --git a/SVGAPlayer-React.podspec b/SVGAPlayer-React.podspec deleted file mode 100644 index 995e9a46..00000000 --- a/SVGAPlayer-React.podspec +++ /dev/null @@ -1,30 +0,0 @@ - -Pod::Spec.new do |s| - - s.name = "SVGAPlayer" - s.version = "1.1.6" - s.summary = "SVGAPlayer 是一个高性能的动画播放器" - - s.description = <<-DESC - SVGA 是一个私有的动画格式,由 YY UED 主导开发。 - SVGA 由 SVG 演进而成,与 SVG 不兼容。 - SVGA 可以在 iOS / Android / Web(PC/移动端) 实现高性能的动画播放。 - DESC - - s.homepage = "http://code.yy.com/ued/SVGAPlayer" - - s.license = "Private" - - s.author = { "PonyCui" => "cuiminghui1@yy.com" } - - s.platform = :ios, "7.0" - - s.source = { :git => "https://github.com/yyued/SVGAPlayer-iOS.git", :tag => s.version } - - s.source_files = "Source", "Source/*.{h,m}", "React", "React/*.{h,m}" - - s.requires_arc = true - - s.dependency 'SSZipArchive' - -end \ No newline at end of file diff --git a/SVGAPlayer.podspec b/SVGAPlayer.podspec index fd5bac16..3753c367 100644 --- a/SVGAPlayer.podspec +++ b/SVGAPlayer.podspec @@ -1,30 +1,33 @@ Pod::Spec.new do |s| - s.name = "SVGAPlayer" - s.version = "1.1.6" + s.version = "2.5.7" s.summary = "SVGAPlayer 是一个高性能的动画播放器" - s.description = <<-DESC - SVGA 是一个私有的动画格式,由 YY UED 主导开发。 - SVGA 由 SVG 演进而成,与 SVG 不兼容。 - SVGA 可以在 iOS / Android / Web(PC/移动端) 实现高性能的动画播放。 + SVGA 是一种全新的动画格式,由 YY UED 团队主导开发; + SVGA 让动画开发分工明确,大大减少动画交互的沟通成本,提升开发效率; + SVGA 可以在 iOS / Android / Web / Flutter 实现高性能的动画播放。 DESC s.homepage = "http://code.yy.com/ued/SVGAPlayer" - s.license = "Apache 2.0" - s.author = { "PonyCui" => "cuiminghui1@yy.com" } - s.platform = :ios, "7.0" - - s.source = { :git => "https://github.com/yyued/SVGAPlayer-iOS.git", :tag => s.version } - - s.source_files = "Source", "Source/*.{h,m}" - - s.requires_arc = true - - s.dependency 'SSZipArchive' - -end \ No newline at end of file + s.source = { :git => "https://github.com/svga/SVGAPlayer-iOS.git", :tag => s.version } + s.subspec 'Core' do |ss| + ss.source_files = "Source/*.{h,m}" + ss.requires_arc = true + ss.dependency 'SSZipArchive', '>= 1.8.1' + ss.library = "z" + ss.framework = "AVFoundation" + ss.dependency 'SVGAPlayer/ProtoFiles' + end + s.subspec 'ProtoFiles' do |ss| + ss.source_files = "Source/pbobjc/*.{h,m}" + ss.requires_arc = false + ss.dependency 'Protobuf', '~> 3.4' + ss.pod_target_xcconfig = { + 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1', + } + end +end diff --git a/SVGAPlayer.xcodeproj/project.pbxproj b/SVGAPlayer.xcodeproj/project.pbxproj index 185d0f14..4f39f57f 100644 --- a/SVGAPlayer.xcodeproj/project.pbxproj +++ b/SVGAPlayer.xcodeproj/project.pbxproj @@ -7,7 +7,14 @@ objects = { /* Begin PBXBuildFile section */ - 4B62B1C5E6CE2BE2D914927B /* libPods-SVGAPlayer React.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 92332F7A897BF4379D765B05 /* libPods-SVGAPlayer React.a */; }; + 63712E6521787950001AE014 /* heartbeat.svga in Resources */ = {isa = PBXBuildFile; fileRef = 63712E6421787950001AE014 /* heartbeat.svga */; }; + 63712E6821787A45001AE014 /* SVGAAudioEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 63712E6721787A45001AE014 /* SVGAAudioEntity.m */; }; + 63E817012178809D001D2D62 /* SVGAAudioLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E817002178809D001D2D62 /* SVGAAudioLayer.m */; }; + 71418C93225E6F710029C69E /* mutiMatte.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71418C92225E6F710029C69E /* mutiMatte.svga */; }; + 718A146D235718E000FED5D3 /* Rocket.svga in Resources */ = {isa = PBXBuildFile; fileRef = 718A146C235718E000FED5D3 /* Rocket.svga */; }; + 71A8679122B7785100176CD6 /* matteRect.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71A8679022B7785100176CD6 /* matteRect.svga */; }; + 71A8679322B7853600176CD6 /* matteBitmap.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71A8679222B7853600176CD6 /* matteBitmap.svga */; }; + 71DAA8A52355B3ED006608A1 /* Goddess.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71DAA8A42355B3ED006608A1 /* Goddess.svga */; }; 80D4C7254846B96B9C6EED83 /* libPods-SVGAPlayer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DDA5FF396660C7C932DF9B8 /* libPods-SVGAPlayer.a */; }; 904D41F81D223DD20085A21A /* SVGABezierPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 904D41F71D223DD20085A21A /* SVGABezierPath.m */; }; 9052FC631E6EB8D4007BC925 /* SVGAExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 9052FC621E6EB8D4007BC925 /* SVGAExporter.m */; }; @@ -26,30 +33,27 @@ 90A676FD1D13A82A008A69F3 /* SVGAParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A676FC1D13A82A008A69F3 /* SVGAParser.m */; }; 90A677031D13AE19008A69F3 /* SVGAVideoEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A677021D13AE19008A69F3 /* SVGAVideoEntity.m */; }; 90A677061D13BF77008A69F3 /* SVGAPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A677051D13BF77008A69F3 /* SVGAPlayer.m */; }; - 90CB64CC1EF290F400DAA382 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A676E71D13A6DF008A69F3 /* ViewController.m */; }; - 90CB64CD1EF290F400DAA382 /* SVGAExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 9052FC621E6EB8D4007BC925 /* SVGAExporter.m */; }; - 90CB64CE1EF290F400DAA382 /* SVGAVideoEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A677021D13AE19008A69F3 /* SVGAVideoEntity.m */; }; - 90CB64CF1EF290F400DAA382 /* SVGAVideoSpriteFrameEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A364D91E5AED04009347F1 /* SVGAVideoSpriteFrameEntity.m */; }; - 90CB64D01EF290F400DAA382 /* SVGABitmapLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A364D01E5AEC11009347F1 /* SVGABitmapLayer.m */; }; - 90CB64D11EF290F400DAA382 /* SVGABezierPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 904D41F71D223DD20085A21A /* SVGABezierPath.m */; }; - 90CB64D21EF290F400DAA382 /* SVGAVideoSpriteEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A364D61E5AECBD009347F1 /* SVGAVideoSpriteEntity.m */; }; - 90CB64D31EF290F400DAA382 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A676E41D13A6DF008A69F3 /* AppDelegate.m */; }; - 90CB64D41EF290F400DAA382 /* SVGAContentLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A364DC1E5D33F8009347F1 /* SVGAContentLayer.m */; }; - 90CB64D51EF290F400DAA382 /* SVGA.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A676F91D13A81F008A69F3 /* SVGA.m */; }; - 90CB64D61EF290F400DAA382 /* SVGAPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A677051D13BF77008A69F3 /* SVGAPlayer.m */; }; - 90CB64D71EF290F400DAA382 /* SVGAVectorLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A364D31E5AEC1C009347F1 /* SVGAVectorLayer.m */; }; - 90CB64D81EF290F400DAA382 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A676E11D13A6DF008A69F3 /* main.m */; }; - 90CB64D91EF290F400DAA382 /* SVGAParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 90A676FC1D13A82A008A69F3 /* SVGAParser.m */; }; - 90CB64DD1EF290F400DAA382 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90A676EE1D13A6DF008A69F3 /* LaunchScreen.storyboard */; }; - 90CB64DE1EF290F400DAA382 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 90A676EC1D13A6DF008A69F3 /* Assets.xcassets */; }; - 90CB64DF1EF290F400DAA382 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 90A676E91D13A6DF008A69F3 /* Main.storyboard */; }; - 90CB64F71EF2925000DAA382 /* SVGAPlayerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 90CB64F61EF2925000DAA382 /* SVGAPlayerManager.m */; }; 90CB64F91EF297E800DAA382 /* SVGAPlayer React-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 90CB64F81EF297E800DAA382 /* SVGAPlayer React-Info.plist */; }; + 90D7CA161F7FA07A006E74F0 /* Svga.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 90D7CA141F7FA079006E74F0 /* Svga.pbobjc.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + 90D7CA1B1F7FB114006E74F0 /* rose_2.0.0.svga in Resources */ = {isa = PBXBuildFile; fileRef = 90D7CA191F7FB114006E74F0 /* rose_2.0.0.svga */; }; + 90D7CA1C1F7FB114006E74F0 /* rose_1.5.0.svga in Resources */ = {isa = PBXBuildFile; fileRef = 90D7CA1A1F7FB114006E74F0 /* rose_1.5.0.svga */; }; + 90D7CA1E1F7FB34E006E74F0 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 90D7CA1D1F7FB34E006E74F0 /* libz.tbd */; }; + 90DB59B51F96026E00894727 /* SVGAImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 90DB59B41F96026E00894727 /* SVGAImageView.m */; }; + E83A58D9247E0E6A00D9F404 /* audio_biling.svga in Resources */ = {isa = PBXBuildFile; fileRef = E83A58D8247E0E6A00D9F404 /* audio_biling.svga */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 1DDA5FF396660C7C932DF9B8 /* libPods-SVGAPlayer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-SVGAPlayer.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 2EF4851C027B3C0E45E3C5C0 /* Pods-SVGAPlayer React.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SVGAPlayer React.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SVGAPlayer React/Pods-SVGAPlayer React.debug.xcconfig"; sourceTree = ""; }; + 63712E6421787950001AE014 /* heartbeat.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = heartbeat.svga; sourceTree = ""; }; + 63712E6621787A45001AE014 /* SVGAAudioEntity.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGAAudioEntity.h; sourceTree = ""; }; + 63712E6721787A45001AE014 /* SVGAAudioEntity.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVGAAudioEntity.m; sourceTree = ""; }; + 63E816FF2178809D001D2D62 /* SVGAAudioLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGAAudioLayer.h; sourceTree = ""; }; + 63E817002178809D001D2D62 /* SVGAAudioLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVGAAudioLayer.m; sourceTree = ""; }; + 71418C92225E6F710029C69E /* mutiMatte.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = mutiMatte.svga; sourceTree = ""; }; + 718A146C235718E000FED5D3 /* Rocket.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = Rocket.svga; sourceTree = ""; }; + 71A8679022B7785100176CD6 /* matteRect.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = matteRect.svga; sourceTree = ""; }; + 71A8679222B7853600176CD6 /* matteBitmap.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = matteBitmap.svga; sourceTree = ""; }; + 71DAA8A42355B3ED006608A1 /* Goddess.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = Goddess.svga; sourceTree = ""; }; 8AD65028FA2D122A34DC4A63 /* Pods-SVGAPlayer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SVGAPlayer.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SVGAPlayer/Pods-SVGAPlayer.debug.xcconfig"; sourceTree = ""; }; 904D41F61D223DD20085A21A /* SVGABezierPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGABezierPath.h; sourceTree = ""; }; 904D41F71D223DD20085A21A /* SVGABezierPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGABezierPath.m; sourceTree = ""; }; @@ -83,13 +87,16 @@ 90A677021D13AE19008A69F3 /* SVGAVideoEntity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGAVideoEntity.m; sourceTree = ""; }; 90A677041D13BF77008A69F3 /* SVGAPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGAPlayer.h; sourceTree = ""; }; 90A677051D13BF77008A69F3 /* SVGAPlayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGAPlayer.m; sourceTree = ""; }; - 90CB64E51EF290F400DAA382 /* SVGAPlayer React.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SVGAPlayer React.app"; sourceTree = BUILT_PRODUCTS_DIR; }; - 90CB64F51EF2925000DAA382 /* SVGAPlayerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGAPlayerManager.h; sourceTree = ""; }; - 90CB64F61EF2925000DAA382 /* SVGAPlayerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGAPlayerManager.m; sourceTree = ""; }; 90CB64F81EF297E800DAA382 /* SVGAPlayer React-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "SVGAPlayer React-Info.plist"; sourceTree = ""; }; - 92332F7A897BF4379D765B05 /* libPods-SVGAPlayer React.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-SVGAPlayer React.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 90D7CA141F7FA079006E74F0 /* Svga.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Svga.pbobjc.m; sourceTree = ""; }; + 90D7CA151F7FA079006E74F0 /* Svga.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Svga.pbobjc.h; sourceTree = ""; }; + 90D7CA191F7FB114006E74F0 /* rose_2.0.0.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = rose_2.0.0.svga; sourceTree = ""; }; + 90D7CA1A1F7FB114006E74F0 /* rose_1.5.0.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = rose_1.5.0.svga; sourceTree = ""; }; + 90D7CA1D1F7FB34E006E74F0 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; + 90DB59B31F96026E00894727 /* SVGAImageView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGAImageView.h; sourceTree = ""; }; + 90DB59B41F96026E00894727 /* SVGAImageView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVGAImageView.m; sourceTree = ""; }; E02B8713B25C0283C736EE03 /* Pods-SVGAPlayer.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SVGAPlayer.release.xcconfig"; path = "Pods/Target Support Files/Pods-SVGAPlayer/Pods-SVGAPlayer.release.xcconfig"; sourceTree = ""; }; - FF89C40C3E9839DA5DE71191 /* Pods-SVGAPlayer React.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SVGAPlayer React.release.xcconfig"; path = "Pods/Target Support Files/Pods-SVGAPlayer React/Pods-SVGAPlayer React.release.xcconfig"; sourceTree = ""; }; + E83A58D8247E0E6A00D9F404 /* audio_biling.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = audio_biling.svga; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -97,18 +104,11 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 90D7CA1E1F7FB34E006E74F0 /* libz.tbd in Frameworks */, 80D4C7254846B96B9C6EED83 /* libPods-SVGAPlayer.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; - 90CB64DA1EF290F400DAA382 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 4B62B1C5E6CE2BE2D914927B /* libPods-SVGAPlayer React.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -117,8 +117,6 @@ children = ( 8AD65028FA2D122A34DC4A63 /* Pods-SVGAPlayer.debug.xcconfig */, E02B8713B25C0283C736EE03 /* Pods-SVGAPlayer.release.xcconfig */, - 2EF4851C027B3C0E45E3C5C0 /* Pods-SVGAPlayer React.debug.xcconfig */, - FF89C40C3E9839DA5DE71191 /* Pods-SVGAPlayer React.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -126,7 +124,6 @@ 90A676D41D13A6DF008A69F3 = { isa = PBXGroup; children = ( - 90CB64C81EF290E600DAA382 /* React */, 90A676F71D13A70E008A69F3 /* Source */, 90A676DF1D13A6DF008A69F3 /* SVGAPlayer */, 90A676DE1D13A6DF008A69F3 /* Products */, @@ -139,7 +136,6 @@ isa = PBXGroup; children = ( 90A676DD1D13A6DF008A69F3 /* SVGAPlayer.app */, - 90CB64E51EF290F400DAA382 /* SVGAPlayer React.app */, ); name = Products; sourceTree = ""; @@ -147,6 +143,7 @@ 90A676DF1D13A6DF008A69F3 /* SVGAPlayer */ = { isa = PBXGroup; children = ( + 90D7C9FA1F7E2AA3006E74F0 /* Samples */, 90A676E31D13A6DF008A69F3 /* AppDelegate.h */, 90A676E41D13A6DF008A69F3 /* AppDelegate.m */, 90A676E61D13A6DF008A69F3 /* ViewController.h */, @@ -172,12 +169,15 @@ 90A676F71D13A70E008A69F3 /* Source */ = { isa = PBXGroup; children = ( + 90D7CA081F7E2D4D006E74F0 /* pbobjc */, 90A676F81D13A81F008A69F3 /* SVGA.h */, 90A676F91D13A81F008A69F3 /* SVGA.m */, 90A676FB1D13A82A008A69F3 /* SVGAParser.h */, 90A676FC1D13A82A008A69F3 /* SVGAParser.m */, 90A677011D13AE19008A69F3 /* SVGAVideoEntity.h */, 90A677021D13AE19008A69F3 /* SVGAVideoEntity.m */, + 63712E6621787A45001AE014 /* SVGAAudioEntity.h */, + 63712E6721787A45001AE014 /* SVGAAudioEntity.m */, 90A364D51E5AECBD009347F1 /* SVGAVideoSpriteEntity.h */, 90A364D61E5AECBD009347F1 /* SVGAVideoSpriteEntity.m */, 90A364D81E5AED04009347F1 /* SVGAVideoSpriteFrameEntity.h */, @@ -188,8 +188,12 @@ 90A364D01E5AEC11009347F1 /* SVGABitmapLayer.m */, 90A364D21E5AEC1B009347F1 /* SVGAVectorLayer.h */, 90A364D31E5AEC1C009347F1 /* SVGAVectorLayer.m */, + 63E816FF2178809D001D2D62 /* SVGAAudioLayer.h */, + 63E817002178809D001D2D62 /* SVGAAudioLayer.m */, 90A677041D13BF77008A69F3 /* SVGAPlayer.h */, 90A677051D13BF77008A69F3 /* SVGAPlayer.m */, + 90DB59B31F96026E00894727 /* SVGAImageView.h */, + 90DB59B41F96026E00894727 /* SVGAImageView.m */, 9052FC611E6EB8D4007BC925 /* SVGAExporter.h */, 9052FC621E6EB8D4007BC925 /* SVGAExporter.m */, 904D41F61D223DD20085A21A /* SVGABezierPath.h */, @@ -198,20 +202,36 @@ path = Source; sourceTree = ""; }; - 90CB64C81EF290E600DAA382 /* React */ = { + 90D7C9FA1F7E2AA3006E74F0 /* Samples */ = { + isa = PBXGroup; + children = ( + E83A58D8247E0E6A00D9F404 /* audio_biling.svga */, + 718A146C235718E000FED5D3 /* Rocket.svga */, + 71DAA8A42355B3ED006608A1 /* Goddess.svga */, + 71A8679022B7785100176CD6 /* matteRect.svga */, + 71A8679222B7853600176CD6 /* matteBitmap.svga */, + 71418C92225E6F710029C69E /* mutiMatte.svga */, + 63712E6421787950001AE014 /* heartbeat.svga */, + 90D7CA1A1F7FB114006E74F0 /* rose_1.5.0.svga */, + 90D7CA191F7FB114006E74F0 /* rose_2.0.0.svga */, + ); + path = Samples; + sourceTree = ""; + }; + 90D7CA081F7E2D4D006E74F0 /* pbobjc */ = { isa = PBXGroup; children = ( - 90CB64F51EF2925000DAA382 /* SVGAPlayerManager.h */, - 90CB64F61EF2925000DAA382 /* SVGAPlayerManager.m */, + 90D7CA151F7FA079006E74F0 /* Svga.pbobjc.h */, + 90D7CA141F7FA079006E74F0 /* Svga.pbobjc.m */, ); - path = React; + path = pbobjc; sourceTree = ""; }; B8EE95EA56FFE89CDEC9D8C3 /* Frameworks */ = { isa = PBXGroup; children = ( + 90D7CA1D1F7FB34E006E74F0 /* libz.tbd */, 1DDA5FF396660C7C932DF9B8 /* libPods-SVGAPlayer.a */, - 92332F7A897BF4379D765B05 /* libPods-SVGAPlayer React.a */, ); name = Frameworks; sourceTree = ""; @@ -227,8 +247,6 @@ 90A676D91D13A6DF008A69F3 /* Sources */, 90A676DA1D13A6DF008A69F3 /* Frameworks */, 90A676DB1D13A6DF008A69F3 /* Resources */, - 90CFF6F7E27D61F7415658A8 /* [CP] Embed Pods Frameworks */, - 30824E0A5B95B78BA26133C9 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -239,26 +257,6 @@ productReference = 90A676DD1D13A6DF008A69F3 /* SVGAPlayer.app */; productType = "com.apple.product-type.application"; }; - 90CB64C91EF290F400DAA382 /* SVGAPlayer React */ = { - isa = PBXNativeTarget; - buildConfigurationList = 90CB64E21EF290F400DAA382 /* Build configuration list for PBXNativeTarget "SVGAPlayer React" */; - buildPhases = ( - 890FC763F2C82314110A5C8F /* [CP] Check Pods Manifest.lock */, - 90CB64CB1EF290F400DAA382 /* Sources */, - 90CB64DA1EF290F400DAA382 /* Frameworks */, - 90CB64DC1EF290F400DAA382 /* Resources */, - 97FF02AF76FF679B16FE6BE5 /* [CP] Embed Pods Frameworks */, - 954F7371F8B4658670CCA7D4 /* [CP] Copy Pods Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "SVGAPlayer React"; - productName = SVGAPlayer; - productReference = 90CB64E51EF290F400DAA382 /* SVGAPlayer React.app */; - productType = "com.apple.product-type.application"; - }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -270,10 +268,7 @@ TargetAttributes = { 90A676DC1D13A6DF008A69F3 = { CreatedOnToolsVersion = 7.3; - DevelopmentTeam = 8M2FQ87SLP; - }; - 90CB64C91EF290F400DAA382 = { - DevelopmentTeam = 8M2FQ87SLP; + DevelopmentTeam = S2RM275849; }; }; }; @@ -282,6 +277,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -291,7 +287,6 @@ projectRoot = ""; targets = ( 90A676DC1D13A6DF008A69F3 /* SVGAPlayer */, - 90CB64C91EF290F400DAA382 /* SVGAPlayer React */, ); }; /* End PBXProject section */ @@ -301,114 +296,41 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 71418C93225E6F710029C69E /* mutiMatte.svga in Resources */, 90A676F01D13A6DF008A69F3 /* LaunchScreen.storyboard in Resources */, + 718A146D235718E000FED5D3 /* Rocket.svga in Resources */, 90A676ED1D13A6DF008A69F3 /* Assets.xcassets in Resources */, + 63712E6521787950001AE014 /* heartbeat.svga in Resources */, 90A676EB1D13A6DF008A69F3 /* Main.storyboard in Resources */, 90CB64F91EF297E800DAA382 /* SVGAPlayer React-Info.plist in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 90CB64DC1EF290F400DAA382 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 90CB64DD1EF290F400DAA382 /* LaunchScreen.storyboard in Resources */, - 90CB64DE1EF290F400DAA382 /* Assets.xcassets in Resources */, - 90CB64DF1EF290F400DAA382 /* Main.storyboard in Resources */, + 71A8679122B7785100176CD6 /* matteRect.svga in Resources */, + 71A8679322B7853600176CD6 /* matteBitmap.svga in Resources */, + 90D7CA1C1F7FB114006E74F0 /* rose_1.5.0.svga in Resources */, + 90D7CA1B1F7FB114006E74F0 /* rose_2.0.0.svga in Resources */, + E83A58D9247E0E6A00D9F404 /* audio_biling.svga in Resources */, + 71DAA8A52355B3ED006608A1 /* Goddess.svga in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 30824E0A5B95B78BA26133C9 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SVGAPlayer/Pods-SVGAPlayer-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - 890FC763F2C82314110A5C8F /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Check Pods Manifest.lock"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - 90CFF6F7E27D61F7415658A8 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SVGAPlayer/Pods-SVGAPlayer-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - 954F7371F8B4658670CCA7D4 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SVGAPlayer React/Pods-SVGAPlayer React-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - 97FF02AF76FF679B16FE6BE5 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SVGAPlayer React/Pods-SVGAPlayer React-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; CD70B01EE331E392E355CD26 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-SVGAPlayer-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -422,41 +344,23 @@ 9052FC631E6EB8D4007BC925 /* SVGAExporter.m in Sources */, 90A677031D13AE19008A69F3 /* SVGAVideoEntity.m in Sources */, 90A364DA1E5AED04009347F1 /* SVGAVideoSpriteFrameEntity.m in Sources */, + 63712E6821787A45001AE014 /* SVGAAudioEntity.m in Sources */, + 63E817012178809D001D2D62 /* SVGAAudioLayer.m in Sources */, 90A364D11E5AEC11009347F1 /* SVGABitmapLayer.m in Sources */, 904D41F81D223DD20085A21A /* SVGABezierPath.m in Sources */, 90A364D71E5AECBD009347F1 /* SVGAVideoSpriteEntity.m in Sources */, 90A676E51D13A6DF008A69F3 /* AppDelegate.m in Sources */, 90A364DD1E5D33F8009347F1 /* SVGAContentLayer.m in Sources */, + 90DB59B51F96026E00894727 /* SVGAImageView.m in Sources */, 90A676FA1D13A81F008A69F3 /* SVGA.m in Sources */, 90A677061D13BF77008A69F3 /* SVGAPlayer.m in Sources */, 90A364D41E5AEC1C009347F1 /* SVGAVectorLayer.m in Sources */, + 90D7CA161F7FA07A006E74F0 /* Svga.pbobjc.m in Sources */, 90A676E21D13A6DF008A69F3 /* main.m in Sources */, 90A676FD1D13A82A008A69F3 /* SVGAParser.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; - 90CB64CB1EF290F400DAA382 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 90CB64F71EF2925000DAA382 /* SVGAPlayerManager.m in Sources */, - 90CB64CC1EF290F400DAA382 /* ViewController.m in Sources */, - 90CB64CD1EF290F400DAA382 /* SVGAExporter.m in Sources */, - 90CB64CE1EF290F400DAA382 /* SVGAVideoEntity.m in Sources */, - 90CB64CF1EF290F400DAA382 /* SVGAVideoSpriteFrameEntity.m in Sources */, - 90CB64D01EF290F400DAA382 /* SVGABitmapLayer.m in Sources */, - 90CB64D11EF290F400DAA382 /* SVGABezierPath.m in Sources */, - 90CB64D21EF290F400DAA382 /* SVGAVideoSpriteEntity.m in Sources */, - 90CB64D31EF290F400DAA382 /* AppDelegate.m in Sources */, - 90CB64D41EF290F400DAA382 /* SVGAContentLayer.m in Sources */, - 90CB64D51EF290F400DAA382 /* SVGA.m in Sources */, - 90CB64D61EF290F400DAA382 /* SVGAPlayer.m in Sources */, - 90CB64D71EF290F400DAA382 /* SVGAVectorLayer.m in Sources */, - 90CB64D81EF290F400DAA382 /* main.m in Sources */, - 90CB64D91EF290F400DAA382 /* SVGAParser.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ @@ -567,6 +471,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; + DEVELOPMENT_TEAM = S2RM275849; INFOPLIST_FILE = SVGAPlayer/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -583,6 +488,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; + DEVELOPMENT_TEAM = S2RM275849; INFOPLIST_FILE = SVGAPlayer/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -593,40 +499,6 @@ }; name = Release; }; - 90CB64E31EF290F400DAA382 /* Debug */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = 2EF4851C027B3C0E45E3C5C0 /* Pods-SVGAPlayer React.debug.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "iPhone Developer"; - DEVELOPMENT_TEAM = 8M2FQ87SLP; - INFOPLIST_FILE = "$(SRCROOT)/SVGAPlayer/SVGAPlayer React-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.opensource.SVGAPlayer; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE = ""; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - 90CB64E41EF290F400DAA382 /* Release */ = { - isa = XCBuildConfiguration; - baseConfigurationReference = FF89C40C3E9839DA5DE71191 /* Pods-SVGAPlayer React.release.xcconfig */; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "iPhone Developer"; - DEVELOPMENT_TEAM = 8M2FQ87SLP; - INFOPLIST_FILE = "$(SRCROOT)/SVGAPlayer/SVGAPlayer React-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.opensource.SVGAPlayer; - PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE = ""; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -648,15 +520,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 90CB64E21EF290F400DAA382 /* Build configuration list for PBXNativeTarget "SVGAPlayer React" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 90CB64E31EF290F400DAA382 /* Debug */, - 90CB64E41EF290F400DAA382 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; /* End XCConfigurationList section */ }; rootObject = 90A676D51D13A6DF008A69F3 /* Project object */; diff --git a/SVGAPlayer.xcodeproj/xcshareddata/xcschemes/SVGAPlayer.xcscheme b/SVGAPlayer.xcodeproj/xcshareddata/xcschemes/SVGAPlayer.xcscheme new file mode 100644 index 00000000..55f72e87 --- /dev/null +++ b/SVGAPlayer.xcodeproj/xcshareddata/xcschemes/SVGAPlayer.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SVGAPlayer.xcodeproj/xcuserdata/errnull.xcuserdatad/xcschemes/xcschememanagement.plist b/SVGAPlayer.xcodeproj/xcuserdata/errnull.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..d0671ccd --- /dev/null +++ b/SVGAPlayer.xcodeproj/xcuserdata/errnull.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + SVGAPlayer React.xcscheme_^#shared#^_ + + orderHint + 7 + + SVGAPlayer.xcscheme_^#shared#^_ + + orderHint + 5 + + + SuppressBuildableAutocreation + + 90A676DC1D13A6DF008A69F3 + + primary + + + + + diff --git a/SVGAPlayer.xcodeproj/xcuserdata/saiakirahui.xcuserdatad/xcschemes/xcschememanagement.plist b/SVGAPlayer.xcodeproj/xcuserdata/saiakirahui.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..ef983a68 --- /dev/null +++ b/SVGAPlayer.xcodeproj/xcuserdata/saiakirahui.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,29 @@ + + + + + SchemeUserState + + SVGAPlayer React.xcscheme + + orderHint + 7 + + SVGAPlayer React.xcscheme_^#shared#^_ + + orderHint + 4 + + SVGAPlayer.xcscheme + + orderHint + 6 + + SVGAPlayer.xcscheme_^#shared#^_ + + orderHint + 3 + + + + diff --git a/SVGAPlayer.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SVGAPlayer.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/SVGAPlayer.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SVGAPlayer.xcworkspace/xcuserdata/errnull.xcuserdatad/UserInterfaceState.xcuserstate b/SVGAPlayer.xcworkspace/xcuserdata/errnull.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..72f68972 Binary files /dev/null and b/SVGAPlayer.xcworkspace/xcuserdata/errnull.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SVGAPlayer.xcworkspace/xcuserdata/errnull.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/SVGAPlayer.xcworkspace/xcuserdata/errnull.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 00000000..ff2cec0e --- /dev/null +++ b/SVGAPlayer.xcworkspace/xcuserdata/errnull.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SVGAPlayer.xcworkspace/xcuserdata/saiakirahui.xcuserdatad/UserInterfaceState.xcuserstate b/SVGAPlayer.xcworkspace/xcuserdata/saiakirahui.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..bf9bfea7 Binary files /dev/null and b/SVGAPlayer.xcworkspace/xcuserdata/saiakirahui.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SVGAPlayer/Assets.xcassets/AppIcon.appiconset/Contents.json b/SVGAPlayer/Assets.xcassets/AppIcon.appiconset/Contents.json index 118c98f7..19882d56 100644 --- a/SVGAPlayer/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/SVGAPlayer/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -29,6 +39,11 @@ "idiom" : "iphone", "size" : "60x60", "scale" : "3x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/SVGAPlayer/Assets.xcassets/Contents.json b/SVGAPlayer/Assets.xcassets/Contents.json new file mode 100644 index 00000000..da4a164c --- /dev/null +++ b/SVGAPlayer/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/SVGAPlayer/Assets.xcassets/begin.imageset/Contents.json b/SVGAPlayer/Assets.xcassets/begin.imageset/Contents.json new file mode 100644 index 00000000..5851f27d --- /dev/null +++ b/SVGAPlayer/Assets.xcassets/begin.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "begin@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/SVGAPlayer/Assets.xcassets/begin.imageset/begin@2x.png b/SVGAPlayer/Assets.xcassets/begin.imageset/begin@2x.png new file mode 100644 index 00000000..9394c657 Binary files /dev/null and b/SVGAPlayer/Assets.xcassets/begin.imageset/begin@2x.png differ diff --git a/SVGAPlayer/Assets.xcassets/purse.imageset/Contents.json b/SVGAPlayer/Assets.xcassets/purse.imageset/Contents.json new file mode 100644 index 00000000..f94fde85 --- /dev/null +++ b/SVGAPlayer/Assets.xcassets/purse.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "purse@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/SVGAPlayer/Assets.xcassets/purse.imageset/purse@2x.png b/SVGAPlayer/Assets.xcassets/purse.imageset/purse@2x.png new file mode 100644 index 00000000..abddd43d Binary files /dev/null and b/SVGAPlayer/Assets.xcassets/purse.imageset/purse@2x.png differ diff --git a/SVGAPlayer/Base.lproj/Main.storyboard b/SVGAPlayer/Base.lproj/Main.storyboard index dd275422..3ffed2c3 100644 --- a/SVGAPlayer/Base.lproj/Main.storyboard +++ b/SVGAPlayer/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -20,7 +20,170 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -29,16 +192,22 @@ + + + + + + - + diff --git a/SVGAPlayer/Samples/Goddess.svga b/SVGAPlayer/Samples/Goddess.svga new file mode 100644 index 00000000..ae27052e Binary files /dev/null and b/SVGAPlayer/Samples/Goddess.svga differ diff --git a/SVGAPlayer/Samples/Rocket.svga b/SVGAPlayer/Samples/Rocket.svga new file mode 100644 index 00000000..9f134618 Binary files /dev/null and b/SVGAPlayer/Samples/Rocket.svga differ diff --git a/SVGAPlayer/Samples/audio_biling.svga b/SVGAPlayer/Samples/audio_biling.svga new file mode 100644 index 00000000..d9b71669 Binary files /dev/null and b/SVGAPlayer/Samples/audio_biling.svga differ diff --git a/SVGAPlayer/Samples/heartbeat.svga b/SVGAPlayer/Samples/heartbeat.svga new file mode 100644 index 00000000..64f010de Binary files /dev/null and b/SVGAPlayer/Samples/heartbeat.svga differ diff --git a/SVGAPlayer/Samples/matteBitmap.svga b/SVGAPlayer/Samples/matteBitmap.svga new file mode 100644 index 00000000..c73db699 Binary files /dev/null and b/SVGAPlayer/Samples/matteBitmap.svga differ diff --git a/SVGAPlayer/Samples/matteBitmap_1.x.svga b/SVGAPlayer/Samples/matteBitmap_1.x.svga new file mode 100644 index 00000000..f65e8aad Binary files /dev/null and b/SVGAPlayer/Samples/matteBitmap_1.x.svga differ diff --git a/SVGAPlayer/Samples/matteRect.svga b/SVGAPlayer/Samples/matteRect.svga new file mode 100644 index 00000000..c158c4b6 Binary files /dev/null and b/SVGAPlayer/Samples/matteRect.svga differ diff --git a/SVGAPlayer/Samples/mutiMatte.svga b/SVGAPlayer/Samples/mutiMatte.svga new file mode 100644 index 00000000..47f58117 Binary files /dev/null and b/SVGAPlayer/Samples/mutiMatte.svga differ diff --git a/SVGAPlayer/Samples/rose_1.5.0.svga b/SVGAPlayer/Samples/rose_1.5.0.svga new file mode 100644 index 00000000..6f5e7cee Binary files /dev/null and b/SVGAPlayer/Samples/rose_1.5.0.svga differ diff --git a/SVGAPlayer/Samples/rose_2.0.0.svga b/SVGAPlayer/Samples/rose_2.0.0.svga new file mode 100644 index 00000000..689f32fa Binary files /dev/null and b/SVGAPlayer/Samples/rose_2.0.0.svga differ diff --git a/SVGAPlayer/ViewController.m b/SVGAPlayer/ViewController.m index e2a316b3..97e52729 100644 --- a/SVGAPlayer/ViewController.m +++ b/SVGAPlayer/ViewController.m @@ -11,7 +11,9 @@ @interface ViewController () -@property (nonatomic, strong) SVGAPlayer *aPlayer; +@property (weak, nonatomic) IBOutlet SVGAPlayer *aPlayer; +@property (weak, nonatomic) IBOutlet UISlider *aSlider; +@property (weak, nonatomic) IBOutlet UIButton *onBeginButton; @end @@ -21,51 +23,107 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - - self.view.backgroundColor = [UIColor blackColor]; - [self.view addSubview:self.aPlayer]; self.aPlayer.delegate = self; - self.aPlayer.frame = CGRectMake(0, 0, 320, 320); - self.aPlayer.loops = 0; + self.aPlayer.loops = 1; self.aPlayer.clearsAfterStop = YES; parser = [[SVGAParser alloc] init]; [self onChange:nil]; } -- (void)viewWillLayoutSubviews { - [super viewWillLayoutSubviews]; - self.aPlayer.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height); +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { + [super touchesBegan:touches withEvent:event]; + [self onBeginButton:self.onBeginButton]; } - (IBAction)onChange:(id)sender { NSArray *items = @[ - @"https://github.com/yyued/SVGA-Samples/blob/master/EmptyState.svga?raw=true", - @"https://github.com/yyued/SVGA-Samples/blob/master/HamburgerArrow.svga?raw=true", - @"https://github.com/yyued/SVGA-Samples/blob/master/PinJump.svga?raw=true", - @"https://github.com/yyued/SVGA-Samples/blob/master/TwitterHeart.svga?raw=true", - @"https://github.com/yyued/SVGA-Samples/blob/master/Walkthrough.svga?raw=true", - @"https://github.com/yyued/SVGA-Samples/blob/master/angel.svga?raw=true", - @"https://github.com/yyued/SVGA-Samples/blob/master/halloween.svga?raw=true", - @"https://github.com/yyued/SVGA-Samples/blob/master/kingset.svga?raw=true", - @"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true", - @"https://github.com/yyued/SVGA-Samples/blob/master/rose.svga?raw=true", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/EmptyState.svga?raw=true", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/HamburgerArrow.svga?raw=true", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/PinJump.svga?raw=true", + @"https://github.com/svga/SVGA-Samples/raw/master/Rocket.svga", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/TwitterHeart.svga?raw=true", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/Walkthrough.svga?raw=true", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/angel.svga?raw=true", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/halloween.svga?raw=true", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/kingset.svga?raw=true", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/posche.svga?raw=true", + @"https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/rose.svga?raw=true", ]; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; - [parser parseWithURL:[NSURL URLWithString:items[arc4random() % 10]] +// parser.enabledMemoryCache = YES; + [parser parseWithURL:[NSURL URLWithString:items[arc4random() % items.count]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; - if (videoItem != nil) { - self.aPlayer.videoItem = videoItem; - [self.aPlayer startAnimation]; - } - } failureBlock:nil]; + if (videoItem != nil) { + self.aPlayer.videoItem = videoItem; + NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc] init]; + [para setLineBreakMode:NSLineBreakByTruncatingTail]; + [para setAlignment:NSTextAlignmentCenter]; + NSAttributedString *str = [[NSAttributedString alloc] + initWithString:@"Hello, World! Hello, World!" + attributes:@{ + NSFontAttributeName: [UIFont systemFontOfSize:28], + NSForegroundColorAttributeName: [UIColor whiteColor], + NSParagraphStyleAttributeName: para, + }]; + [self.aPlayer setAttributedText:str forKey:@"banner"]; + + [self.aPlayer startAnimation]; + +// [self.aPlayer startAnimationWithRange:NSMakeRange(10, 25) reverse:YES]; + } + } failureBlock:nil]; +// +// [parser parseWithURL:[NSURL URLWithString:@"https://github.com/svga/SVGA-Samples/raw/master_aep/BitmapColorArea1.svga"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { +// if (videoItem != nil) { +// self.aPlayer.videoItem = videoItem; +// [self.aPlayer setImageWithURL:[NSURL URLWithString: @"https://i.imgur.com/vd4GuUh.png"] forKey:@"matte_EEKdlEml.matte"]; +// [self.aPlayer startAnimation]; +// } +// } failureBlock:nil]; + +// [parser parseWithNamed:@"Rocket" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { +// self.aPlayer.videoItem = videoItem; +// [self.aPlayer startAnimation]; +// } failureBlock:nil]; +} + +- (IBAction)onSliderClick:(UISlider *)sender { + [self.aPlayer stepToPercentage:sender.value andPlay:NO]; +} + +- (IBAction)onSlide:(UISlider *)sender { + [self.aPlayer stepToPercentage:sender.value andPlay:NO]; +} + +- (IBAction)onChangeColor:(UIButton *)sender { + self.view.backgroundColor = sender.backgroundColor; } -- (SVGAPlayer *)aPlayer { - if (_aPlayer == nil) { - _aPlayer = [[SVGAPlayer alloc] init]; +- (IBAction)onBeginButton:(UIButton *)sender { + sender.selected = !sender.isSelected; + if (sender.selected) { + [self.aPlayer pauseAnimation]; + } else { + [self.aPlayer stepToPercentage:(self.aSlider.value == 1 ? 0 : self.aSlider.value) andPlay:YES]; } - return _aPlayer; } +- (IBAction)onRetreatButton:(UIButton *)sender { + +} + +- (IBAction)onForwardButton:(UIButton *)sender { + +} + + +#pragma - mark SVGAPlayer Delegate +- (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage { + self.aSlider.value = percentage; +} + +- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player { + self.onBeginButton.selected = YES; +} @end diff --git a/Source/SVGA.h b/Source/SVGA.h index 71c624a3..118ff4fd 100644 --- a/Source/SVGA.h +++ b/Source/SVGA.h @@ -9,6 +9,8 @@ #import #import "SVGAParser.h" #import "SVGAPlayer.h" +#import "SVGAImageView.h" +#import "SVGAVideoEntity.h" #import "SVGAExporter.h" @interface SVGA : NSObject diff --git a/Source/SVGAAudioEntity.h b/Source/SVGAAudioEntity.h new file mode 100644 index 00000000..2402dceb --- /dev/null +++ b/Source/SVGAAudioEntity.h @@ -0,0 +1,22 @@ +// +// SVGAAudioEntity.h +// SVGAPlayer +// +// Created by PonyCui on 2018/10/18. +// Copyright © 2018年 UED Center. All rights reserved. +// + +#import + +@class SVGAProtoAudioEntity; + +@interface SVGAAudioEntity : NSObject + +@property (nonatomic, readonly) NSString *audioKey; +@property (nonatomic, readonly) NSInteger startFrame; +@property (nonatomic, readonly) NSInteger endFrame; +@property (nonatomic, readonly) NSInteger startTime; + +- (instancetype)initWithProtoObject:(SVGAProtoAudioEntity *)protoObject; + +@end diff --git a/Source/SVGAAudioEntity.m b/Source/SVGAAudioEntity.m new file mode 100644 index 00000000..f44fc5ce --- /dev/null +++ b/Source/SVGAAudioEntity.m @@ -0,0 +1,34 @@ +// +// SVGAAudioEntity.m +// SVGAPlayer +// +// Created by PonyCui on 2018/10/18. +// Copyright © 2018年 UED Center. All rights reserved. +// + +#import "SVGAAudioEntity.h" +#import "Svga.pbobjc.h" + +@interface SVGAAudioEntity () + +@property (nonatomic, readwrite) NSString *audioKey; +@property (nonatomic, readwrite) NSInteger startFrame; +@property (nonatomic, readwrite) NSInteger endFrame; +@property (nonatomic, readwrite) NSInteger startTime; + +@end + +@implementation SVGAAudioEntity + +- (instancetype)initWithProtoObject:(SVGAProtoAudioEntity *)protoObject { + self = [super init]; + if (self) { + _audioKey = protoObject.audioKey; + _startFrame = protoObject.startFrame; + _endFrame = protoObject.endFrame; + _startTime = protoObject.startTime; + } + return self; +} + +@end diff --git a/Source/SVGAAudioLayer.h b/Source/SVGAAudioLayer.h new file mode 100644 index 00000000..97ee6f41 --- /dev/null +++ b/Source/SVGAAudioLayer.h @@ -0,0 +1,23 @@ +// +// SVGAAudioLayer.h +// SVGAPlayer +// +// Created by PonyCui on 2018/10/18. +// Copyright © 2018年 UED Center. All rights reserved. +// + +#import +#import + +@class SVGAAudioEntity, SVGAVideoEntity; + +@interface SVGAAudioLayer : NSObject + +@property (nonatomic, readonly) AVAudioPlayer *audioPlayer; +@property (nonatomic, readonly) SVGAAudioEntity *audioItem; +@property (nonatomic, assign) BOOL audioPlaying; + + +- (instancetype)initWithAudioItem:(SVGAAudioEntity *)audioItem videoItem:(SVGAVideoEntity *)videoItem; + +@end diff --git a/Source/SVGAAudioLayer.m b/Source/SVGAAudioLayer.m new file mode 100644 index 00000000..f6ec7f29 --- /dev/null +++ b/Source/SVGAAudioLayer.m @@ -0,0 +1,37 @@ +// +// SVGAAudioLayer.m +// SVGAPlayer +// +// Created by PonyCui on 2018/10/18. +// Copyright © 2018年 UED Center. All rights reserved. +// + +#import "SVGAAudioLayer.h" +#import "SVGAAudioEntity.h" +#import "SVGAVideoEntity.h" + +@interface SVGAAudioLayer () + +@property (nonatomic, readwrite) AVAudioPlayer *audioPlayer; +@property (nonatomic, readwrite) SVGAAudioEntity *audioItem; + +@end + +@implementation SVGAAudioLayer + +- (instancetype)initWithAudioItem:(SVGAAudioEntity *)audioItem videoItem:(SVGAVideoEntity *)videoItem +{ + self = [super init]; + if (self) { + _audioItem = audioItem; + if (audioItem.audioKey != nil && videoItem.audiosData[audioItem.audioKey] != nil) { + _audioPlayer = [[AVAudioPlayer alloc] initWithData:videoItem.audiosData[audioItem.audioKey] + fileTypeHint:@"mp3" + error:NULL]; + [_audioPlayer prepareToPlay]; + } + } + return self; +} + +@end diff --git a/Source/SVGABezierPath.m b/Source/SVGABezierPath.m index b5154dc0..f8f4ba5d 100644 --- a/Source/SVGABezierPath.m +++ b/Source/SVGABezierPath.m @@ -22,43 +22,24 @@ - (void)setValues:(nonnull NSString *)values { self.backValues = values; return; } - static NSArray *validMethods; + static NSSet *validMethods; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - validMethods = @[@"M",@"L",@"H",@"V",@"C",@"S",@"Q",@"R",@"A",@"Z",@"m",@"l",@"h",@"v",@"c",@"s",@"q",@"r",@"a",@"z"]; + validMethods = [NSSet setWithArray:@[@"M",@"L",@"H",@"V",@"C",@"S",@"Q",@"R",@"A",@"Z",@"m",@"l",@"h",@"v",@"c",@"s",@"q",@"r",@"a",@"z"]]; }); + values = [values stringByReplacingOccurrencesOfString:@"([a-zA-Z])" withString:@"|||$1 " options:NSRegularExpressionSearch range:NSMakeRange(0, values.length)]; values = [values stringByReplacingOccurrencesOfString:@"," withString:@" "]; - NSArray *items = [values componentsSeparatedByString:@" "]; - NSString *currentMethod = @""; - NSMutableArray *args = [NSMutableArray array]; - NSString *argLast = nil; - for (NSString *item in items) { - if (item.length < 1) { + NSArray *segments = [values componentsSeparatedByString:@"|||"]; + for (NSString *segment in segments) { + if (segment.length == 0) { continue; } - NSString *firstLetter = [item substringToIndex:1]; - if ([validMethods indexOfObject:firstLetter] != NSNotFound) { - if (argLast != nil) { - [args addObject:argLast]; - } - [self operate:currentMethod args:[args copy]]; - currentMethod = @""; - [args removeAllObjects]; - argLast = nil; - currentMethod = firstLetter; - argLast = [item substringFromIndex:1]; - } - else { - if (argLast != nil && [argLast stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length) { - [args addObject:[NSString stringWithFormat:@"%@,%@", argLast, item]]; - argLast = nil; - } - else { - argLast = item; - } + NSString *firstLetter = [segment substringToIndex:1]; + if ([validMethods containsObject:firstLetter]) { + NSArray *args = [[[segment substringFromIndex:1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] componentsSeparatedByString:@" "]; + [self operate:firstLetter args:args]; } } - [self operate:currentMethod args:[args copy]]; } - (nonnull CAShapeLayer *)createLayer { @@ -73,79 +54,64 @@ - (nonnull CAShapeLayer *)createLayer { } - (void)operate:(NSString *)method args:(NSArray *)args { - if (([method isEqualToString:@"M"] || [method isEqualToString:@"m"]) && args.count == 1) { - CGPoint iPoint = [self argPoint:args[0] relative:[method isEqualToString:@"m"]]; + if (([method isEqualToString:@"M"] || [method isEqualToString:@"m"]) && args.count == 2) { + CGPoint iPoint = [self argPoint:CGPointMake([args[0] floatValue], [args[1] floatValue]) relative:[method isEqualToString:@"m"]]; if (!CGPointEqualToPoint(iPoint, CGPointMake(CGFLOAT_MIN, CGFLOAT_MIN))) { [self moveToPoint:iPoint]; } } - else if (([method isEqualToString:@"L"] || [method isEqualToString:@"l"]) && args.count == 1) { - CGPoint iPoint = [self argPoint:args[0] relative:[method isEqualToString:@"l"]]; + else if (([method isEqualToString:@"L"] || [method isEqualToString:@"l"]) && args.count == 2) { + CGPoint iPoint = [self argPoint:CGPointMake([args[0] floatValue], [args[1] floatValue]) relative:[method isEqualToString:@"l"]]; if (!CGPointEqualToPoint(iPoint, CGPointMake(CGFLOAT_MIN, CGFLOAT_MIN))) { [self addLineToPoint:iPoint]; } } - else if (([method isEqualToString:@"C"] || [method isEqualToString:@"c"]) && args.count == 3) { - CGPoint iPoint = [self argPoint:args[0] relative:[method isEqualToString:@"c"]]; - CGPoint iiPoint = [self argPoint:args[1] relative:[method isEqualToString:@"c"]]; - CGPoint iiiPoint = [self argPoint:args[2] relative:[method isEqualToString:@"c"]]; + else if (([method isEqualToString:@"C"] || [method isEqualToString:@"c"]) && args.count == 6) { + CGPoint iPoint = [self argPoint:CGPointMake([args[0] floatValue], [args[1] floatValue]) relative:[method isEqualToString:@"c"]]; + CGPoint iiPoint = [self argPoint:CGPointMake([args[2] floatValue], [args[3] floatValue]) relative:[method isEqualToString:@"c"]]; + CGPoint iiiPoint = [self argPoint:CGPointMake([args[4] floatValue], [args[5] floatValue]) relative:[method isEqualToString:@"c"]]; if (!CGPointEqualToPoint(iPoint, CGPointMake(CGFLOAT_MIN, CGFLOAT_MIN)) && !CGPointEqualToPoint(iiPoint, CGPointMake(CGFLOAT_MIN, CGFLOAT_MIN)) && !CGPointEqualToPoint(iiiPoint, CGPointMake(CGFLOAT_MIN, CGFLOAT_MIN))) { [self addCurveToPoint:iiiPoint controlPoint1:iPoint controlPoint2:iiPoint]; } } - else if (([method isEqualToString:@"Q"] || [method isEqualToString:@"q"]) && args.count == 2) { - CGPoint iPoint = [self argPoint:args[0] relative:[method isEqualToString:@"q"]]; - CGPoint iiPoint = [self argPoint:args[1] relative:[method isEqualToString:@"q"]]; + else if (([method isEqualToString:@"Q"] || [method isEqualToString:@"q"]) && args.count == 4) { + CGPoint iPoint = [self argPoint:CGPointMake([args[0] floatValue], [args[1] floatValue]) relative:[method isEqualToString:@"q"]]; + CGPoint iiPoint = [self argPoint:CGPointMake([args[2] floatValue], [args[3] floatValue]) relative:[method isEqualToString:@"q"]]; if (!CGPointEqualToPoint(iPoint, CGPointMake(CGFLOAT_MIN, CGFLOAT_MIN)) && !CGPointEqualToPoint(iiPoint, CGPointMake(CGFLOAT_MIN, CGFLOAT_MIN))) { [self addQuadCurveToPoint:iiPoint controlPoint:iPoint]; } } else if (([method isEqualToString:@"H"] || [method isEqualToString:@"h"]) && args.count == 1) { - CGFloat iValue = [self argFloat:args[0] relativeValue:([method isEqualToString:@"h"] ? self.currentPoint.x : 0.0)]; + CGFloat iValue = [self argFloat:args[0].floatValue relativeValue:([method isEqualToString:@"h"] ? self.currentPoint.x : 0.0)]; if (iValue != CGFLOAT_MIN) { [self addLineToPoint:CGPointMake(iValue, self.currentPoint.y)]; } } else if (([method isEqualToString:@"V"] || [method isEqualToString:@"v"]) && args.count == 1) { - CGFloat iValue = [self argFloat:args[0] relativeValue:([method isEqualToString:@"v"] ? self.currentPoint.y : 0.0)]; + CGFloat iValue = [self argFloat:args[0].floatValue relativeValue:([method isEqualToString:@"v"] ? self.currentPoint.y : 0.0)]; if (iValue != CGFLOAT_MIN) { [self addLineToPoint:CGPointMake(self.currentPoint.x, iValue)]; } } - else if (([method isEqualToString:@"Z"] || [method isEqualToString:@"z"]) && args.count == 1) { + else if (([method isEqualToString:@"Z"] || [method isEqualToString:@"z"])) { [self closePath]; } } -- (CGFloat)argFloat:(NSString *)arg relativeValue:(CGFloat)relativeValue { - NSNumberFormatter *numberFotmatter = [[NSNumberFormatter alloc] init]; - NSNumber *x = [numberFotmatter numberFromString:arg]; - if (x != nil) { - return x.floatValue + relativeValue; - } - else { - return CGFLOAT_MIN; - } +- (CGFloat)argFloat:(CGFloat)value relativeValue:(CGFloat)relativeValue { + return value + relativeValue; } -- (CGPoint)argPoint:(NSString *)arg relative:(BOOL)relative { - if ([arg componentsSeparatedByString:@","].count == 2) { - NSNumberFormatter *numberFotmatter = [[NSNumberFormatter alloc] init]; - NSNumber *x = [numberFotmatter numberFromString:[arg componentsSeparatedByString:@","][0]]; - NSNumber *y = [numberFotmatter numberFromString:[arg componentsSeparatedByString:@","][1]]; - if (x != nil && y != nil) { - if (relative) { - return CGPointMake(x.floatValue + self.currentPoint.x, y.floatValue + self.currentPoint.y); - } - else { - return CGPointMake(x.floatValue, y.floatValue); - } - } +- (CGPoint)argPoint:(CGPoint)point relative:(BOOL)relative { + if (relative) { + return CGPointMake(point.x + self.currentPoint.x, point.y + self.currentPoint.y); + } + else { + return point; } - return CGPointMake(CGFLOAT_MIN, CGFLOAT_MIN); } @end diff --git a/Source/SVGAContentLayer.h b/Source/SVGAContentLayer.h index f56b3338..7343865f 100644 --- a/Source/SVGAContentLayer.h +++ b/Source/SVGAContentLayer.h @@ -7,16 +7,22 @@ // #import +#import "SVGAPlayer.h" @class SVGABitmapLayer, SVGAVectorLayer, SVGAVideoSpriteFrameEntity; @interface SVGAContentLayer : CALayer +@property (nonatomic, strong) NSString *imageKey; +@property (nonatomic, assign) BOOL dynamicHidden; +@property (nonatomic, copy) SVGAPlayerDynamicDrawingBlock dynamicDrawingBlock; @property (nonatomic, strong) SVGABitmapLayer *bitmapLayer; @property (nonatomic, strong) SVGAVectorLayer *vectorLayer; +@property (nonatomic, strong) CATextLayer *textLayer; - (instancetype)initWithFrames:(NSArray *)frames; - (void)stepToFrame:(NSInteger)frame; +- (void)resetTextLayerProperties:(NSAttributedString *)attributedString; @end diff --git a/Source/SVGAContentLayer.m b/Source/SVGAContentLayer.m index 512987a1..471a741e 100644 --- a/Source/SVGAContentLayer.m +++ b/Source/SVGAContentLayer.m @@ -14,6 +14,7 @@ @interface SVGAContentLayer () @property (nonatomic, strong) NSArray *frames; +@property (nonatomic, assign) NSTextAlignment textLayerAlignment; @end @@ -25,12 +26,16 @@ - (instancetype)initWithFrames:(NSArray *)frames { self.backgroundColor = [UIColor clearColor].CGColor; self.masksToBounds = NO; _frames = frames; + _textLayerAlignment = NSTextAlignmentCenter; [self stepToFrame:0]; } return self; } - (void)stepToFrame:(NSInteger)frame { + if (self.dynamicHidden) { + return; + } if (frame < self.frames.count) { SVGAVideoSpriteFrameEntity *frameItem = self.frames[frame]; if (frameItem.alpha > 0.0) { @@ -45,13 +50,26 @@ - (void)stepToFrame:(NSInteger)frame { CGFloat offsetX = self.frame.origin.x - nx; CGFloat offsetY = self.frame.origin.y - ny; self.position = CGPointMake(self.position.x - offsetX, self.position.y - offsetY); - self.mask = frameItem.maskLayer; + if (frameItem.maskLayer != nil) { + if ([frameItem.maskLayer isKindOfClass:[CAShapeLayer class]]) { + CAShapeLayer *cloneShapeLayer = [CAShapeLayer layer]; + cloneShapeLayer.path = [(CAShapeLayer *)frameItem.maskLayer path]; + cloneShapeLayer.fillColor = [(CAShapeLayer *)frameItem.maskLayer fillColor]; + self.mask = cloneShapeLayer; + } + } + else { + self.mask = nil; + } [self.bitmapLayer stepToFrame:frame]; [self.vectorLayer stepToFrame:frame]; } else { self.hidden = YES; } + if (self.dynamicDrawingBlock) { + self.dynamicDrawingBlock(self, frame); + } } } @@ -62,7 +80,20 @@ - (void)setFrame:(CGRect)frame { for (CALayer *sublayer in self.sublayers) { if ([sublayer isKindOfClass:[CATextLayer class]]) { CGRect frame = sublayer.frame; - frame.origin.x = (self.frame.size.width - sublayer.frame.size.width) / 2.0; + switch (self.textLayerAlignment) { + case NSTextAlignmentLeft: + frame.origin.x = 0.0; + break; + case NSTextAlignmentCenter: + frame.origin.x = (self.frame.size.width - sublayer.frame.size.width) / 2.0; + break; + case NSTextAlignmentRight: + frame.origin.x = self.frame.size.width - sublayer.frame.size.width; + break; + default: + frame.origin.x = (self.frame.size.width - sublayer.frame.size.width) / 2.0; + break; + } frame.origin.y = (self.frame.size.height - sublayer.frame.size.height) / 2.0; sublayer.frame = frame; } @@ -81,4 +112,39 @@ - (void)setVectorLayer:(SVGAVectorLayer *)vectorLayer { [self addSublayer:vectorLayer]; } +- (void)setDynamicHidden:(BOOL)dynamicHidden { + _dynamicHidden = dynamicHidden; + self.hidden = dynamicHidden; +} + +- (void)resetTextLayerProperties:(NSAttributedString *)attributedString { + NSDictionary *textAttrs = (id)[attributedString attributesAtIndex:0 effectiveRange:nil]; + NSParagraphStyle *paragraphStyle = textAttrs[NSParagraphStyleAttributeName]; + if (paragraphStyle == nil) { + return; + } + if (paragraphStyle.lineBreakMode == NSLineBreakByTruncatingTail) { + self.textLayer.truncationMode = kCATruncationEnd; + [self.textLayer setWrapped:NO]; + } + else if (paragraphStyle.lineBreakMode == NSLineBreakByTruncatingMiddle) { + self.textLayer.truncationMode = kCATruncationMiddle; + [self.textLayer setWrapped:NO]; + } + else if (paragraphStyle.lineBreakMode == NSLineBreakByTruncatingHead) { + self.textLayer.truncationMode = kCATruncationStart; + [self.textLayer setWrapped:NO]; + } + else { + self.textLayer.truncationMode = kCATruncationNone; + [self.textLayer setWrapped:YES]; + } + if (paragraphStyle.alignment == NSTextAlignmentNatural) { + self.textLayerAlignment = NSTextAlignmentCenter; + } + else { + self.textLayerAlignment = paragraphStyle.alignment; + } +} + @end diff --git a/Source/SVGAImageView.h b/Source/SVGAImageView.h new file mode 100644 index 00000000..adfd650f --- /dev/null +++ b/Source/SVGAImageView.h @@ -0,0 +1,16 @@ +// +// SVGAImageView.h +// SVGAPlayer +// +// Created by 崔明辉 on 2017/10/17. +// Copyright © 2017年 UED Center. All rights reserved. +// + +#import "SVGAPlayer.h" + +@interface SVGAImageView : SVGAPlayer + +@property (nonatomic, assign) IBInspectable BOOL autoPlay; +@property (nonatomic, strong) IBInspectable NSString *imageName; + +@end diff --git a/Source/SVGAImageView.m b/Source/SVGAImageView.m new file mode 100644 index 00000000..38e4123b --- /dev/null +++ b/Source/SVGAImageView.m @@ -0,0 +1,49 @@ +// +// SVGAImageView.m +// SVGAPlayer +// +// Created by 崔明辉 on 2017/10/17. +// Copyright © 2017年 UED Center. All rights reserved. +// + +#import "SVGAImageView.h" +#import "SVGAParser.h" + +static SVGAParser *sharedParser; + +@implementation SVGAImageView + ++ (void)load { + sharedParser = [SVGAParser new]; +} + +- (instancetype)initWithCoder:(NSCoder *)coder +{ + self = [super initWithCoder:coder]; + if (self) { + _autoPlay = YES; + } + return self; +} + +- (void)setImageName:(NSString *)imageName { + _imageName = imageName; + if ([imageName hasPrefix:@"http://"] || [imageName hasPrefix:@"https://"]) { + [sharedParser parseWithURL:[NSURL URLWithString:imageName] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { + [self setVideoItem:videoItem]; + if (self.autoPlay) { + [self startAnimation]; + } + } failureBlock:nil]; + } + else { + [sharedParser parseWithNamed:imageName inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { + [self setVideoItem:videoItem]; + if (self.autoPlay) { + [self startAnimation]; + } + } failureBlock:nil]; + } +} + +@end diff --git a/Source/SVGAParser.h b/Source/SVGAParser.h index 39e4bd12..91ea6726 100644 --- a/Source/SVGAParser.h +++ b/Source/SVGAParser.h @@ -12,10 +12,16 @@ @interface SVGAParser : NSObject +@property (nonatomic, assign) BOOL enabledMemoryCache; + - (void)parseWithURL:(nonnull NSURL *)URL completionBlock:(void ( ^ _Nonnull )(SVGAVideoEntity * _Nullable videoItem))completionBlock failureBlock:(void ( ^ _Nullable)(NSError * _Nullable error))failureBlock; +- (void)parseWithURLRequest:(nonnull NSURLRequest *)URLRequest + completionBlock:(void ( ^ _Nonnull )(SVGAVideoEntity * _Nullable videoItem))completionBlock + failureBlock:(void ( ^ _Nullable)(NSError * _Nullable error))failureBlock; + - (void)parseWithData:(nonnull NSData *)data cacheKey:(nonnull NSString *)cacheKey completionBlock:(void ( ^ _Nullable)(SVGAVideoEntity * _Nonnull videoItem))completionBlock diff --git a/Source/SVGAParser.m b/Source/SVGAParser.m index d3acaf9b..af7b07da 100644 --- a/Source/SVGAParser.m +++ b/Source/SVGAParser.m @@ -8,9 +8,13 @@ #import "SVGAParser.h" #import "SVGAVideoEntity.h" +#import "Svga.pbobjc.h" +#import #import #import +#define ZIP_MAGIC_NUMBER "PK" + @interface SVGAParser () @end @@ -18,44 +22,71 @@ @interface SVGAParser () @implementation SVGAParser static NSOperationQueue *parseQueue; +static NSOperationQueue *unzipQueue; + (void)load { parseQueue = [NSOperationQueue new]; - parseQueue.maxConcurrentOperationCount = 1; + parseQueue.maxConcurrentOperationCount = 8; + unzipQueue = [NSOperationQueue new]; + unzipQueue.maxConcurrentOperationCount = 1; } - (void)parseWithURL:(nonnull NSURL *)URL completionBlock:(void ( ^ _Nonnull )(SVGAVideoEntity * _Nullable videoItem))completionBlock failureBlock:(void ( ^ _Nullable)(NSError * _Nullable error))failureBlock { - if ([[NSFileManager defaultManager] fileExistsAtPath:[self cacheDirectory:[self cacheKey:URL]]]) { - [self parseWithCacheKey:[self cacheKey:URL] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { + [self parseWithURLRequest:[NSURLRequest requestWithURL:URL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:20.0] + completionBlock:completionBlock + failureBlock:failureBlock]; +} + +- (void)parseWithURLRequest:(NSURLRequest *)URLRequest completionBlock:(void (^)(SVGAVideoEntity * _Nullable))completionBlock failureBlock:(void (^)(NSError * _Nullable))failureBlock { + if (URLRequest.URL == nil) { + if (failureBlock) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock([NSError errorWithDomain:@"SVGAParser" code:411 userInfo:@{NSLocalizedDescriptionKey: @"URL cannot be nil."}]); + }]; + } + return; + } + if ([[NSFileManager defaultManager] fileExistsAtPath:[self cacheDirectory:[self cacheKey:URLRequest.URL]]]) { + [self parseWithCacheKey:[self cacheKey:URLRequest.URL] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { if (completionBlock) { - completionBlock(videoItem); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(videoItem); + }]; } } failureBlock:^(NSError * _Nonnull error) { - [self clearCache:[self cacheKey:URL]]; + [self clearCache:[self cacheKey:URLRequest.URL]]; if (failureBlock) { - failureBlock(error); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock(error); + }]; } }]; return; } - [[[NSURLSession sharedSession] dataTaskWithURL:URL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + [[[NSURLSession sharedSession] dataTaskWithRequest:URLRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { if (error == nil && data != nil) { - [self parseWithData:data cacheKey:[self cacheKey:URL] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { + [self parseWithData:data cacheKey:[self cacheKey:URLRequest.URL] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { if (completionBlock) { - completionBlock(videoItem); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(videoItem); + }]; } } failureBlock:^(NSError * _Nonnull error) { - [self clearCache:[self cacheKey:URL]]; + [self clearCache:[self cacheKey:URLRequest.URL]]; if (failureBlock) { - failureBlock(error); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock(error); + }]; } }]; } else { if (failureBlock) { - failureBlock(error); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock(error); + }]; } } }] resume]; @@ -66,47 +97,89 @@ - (void)parseWithNamed:(NSString *)named completionBlock:(void (^)(SVGAVideoEntity * _Nonnull))completionBlock failureBlock:(void (^)(NSError * _Nonnull))failureBlock { NSString *filePath = [(inBundle ?: [NSBundle mainBundle]) pathForResource:named ofType:@"svga"]; - if (filePath != nil) { - NSString *cacheKey = [self cacheKey:[NSURL fileURLWithPath:filePath]]; - [self parseWithData:[NSData dataWithContentsOfFile:filePath] - cacheKey:cacheKey - completionBlock:completionBlock - failureBlock:failureBlock]; - } - else { - failureBlock([NSError errorWithDomain:@"SVGAParser" code:404 userInfo:@{NSLocalizedDescriptionKey: @"File not exist."}]); + if (filePath == nil) { + if (failureBlock) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock([NSError errorWithDomain:@"SVGAParser" code:404 userInfo:@{NSLocalizedDescriptionKey: @"File not exist."}]); + }]; + } + return; } + [self parseWithData:[NSData dataWithContentsOfFile:filePath] + cacheKey:[self cacheKey:[NSURL fileURLWithPath:filePath]] + completionBlock:completionBlock + failureBlock:failureBlock]; } - (void)parseWithCacheKey:(nonnull NSString *)cacheKey completionBlock:(void ( ^ _Nullable)(SVGAVideoEntity * _Nonnull videoItem))completionBlock failureBlock:(void ( ^ _Nullable)(NSError * _Nonnull error))failureBlock { - [[NSOperationQueue new] addOperationWithBlock:^{ + [parseQueue addOperationWithBlock:^{ SVGAVideoEntity *cacheItem = [SVGAVideoEntity readCache:cacheKey]; if (cacheItem != nil) { if (completionBlock) { - completionBlock(cacheItem); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(cacheItem); + }]; } return; } NSString *cacheDir = [self cacheDirectory:cacheKey]; - NSError *err; - NSData *JSONData = [NSData dataWithContentsOfFile:[cacheDir stringByAppendingString:@"/movie.spec"]]; - if (JSONData != nil) { - NSDictionary *JSONObject = [NSJSONSerialization JSONObjectWithData:JSONData options:kNilOptions error:&err]; - if ([JSONObject isKindOfClass:[NSDictionary class]]) { - SVGAVideoEntity *videoItem = [[SVGAVideoEntity alloc] initWithJSONObject:JSONObject cacheDir:cacheDir]; - [videoItem resetImagesWithJSONObject:JSONObject]; - [videoItem resetSpritesWithJSONObject:JSONObject]; - [videoItem saveCache:cacheKey]; + if ([[NSFileManager defaultManager] fileExistsAtPath:[cacheDir stringByAppendingString:@"/movie.binary"]]) { + NSError *err; + NSData *protoData = [NSData dataWithContentsOfFile:[cacheDir stringByAppendingString:@"/movie.binary"]]; + SVGAProtoMovieEntity *protoObject = [SVGAProtoMovieEntity parseFromData:protoData error:&err]; + if (!err && [protoObject isKindOfClass:[SVGAProtoMovieEntity class]]) { + SVGAVideoEntity *videoItem = [[SVGAVideoEntity alloc] initWithProtoObject:protoObject cacheDir:cacheDir]; + [videoItem resetImagesWithProtoObject:protoObject]; + [videoItem resetSpritesWithProtoObject:protoObject]; + [videoItem resetAudiosWithProtoObject:protoObject]; + if (self.enabledMemoryCache) { + [videoItem saveCache:cacheKey]; + } else { + [videoItem saveWeakCache:cacheKey]; + } if (completionBlock) { - completionBlock(videoItem); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(videoItem); + }]; + } + } + else { + if (failureBlock) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock([NSError errorWithDomain:NSFilePathErrorKey code:-1 userInfo:nil]); + }]; } } } else { - if (failureBlock) { - failureBlock([NSError errorWithDomain:NSFilePathErrorKey code:-1 userInfo:nil]); + NSError *err; + NSData *JSONData = [NSData dataWithContentsOfFile:[cacheDir stringByAppendingString:@"/movie.spec"]]; + if (JSONData != nil) { + NSDictionary *JSONObject = [NSJSONSerialization JSONObjectWithData:JSONData options:kNilOptions error:&err]; + if ([JSONObject isKindOfClass:[NSDictionary class]]) { + SVGAVideoEntity *videoItem = [[SVGAVideoEntity alloc] initWithJSONObject:JSONObject cacheDir:cacheDir]; + [videoItem resetImagesWithJSONObject:JSONObject]; + [videoItem resetSpritesWithJSONObject:JSONObject]; + if (self.enabledMemoryCache) { + [videoItem saveCache:cacheKey]; + } else { + [videoItem saveWeakCache:cacheKey]; + } + if (completionBlock) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(videoItem); + }]; + } + } + } + else { + if (failureBlock) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock([NSError errorWithDomain:NSFilePathErrorKey code:-1 userInfo:nil]); + }]; + } } } }]; @@ -117,6 +190,14 @@ - (void)clearCache:(nonnull NSString *)cacheKey { [[NSFileManager defaultManager] removeItemAtPath:cacheDir error:NULL]; } ++ (BOOL)isZIPData:(NSData *)data { + BOOL result = NO; + if (!strncmp([data bytes], ZIP_MAGIC_NUMBER, strlen(ZIP_MAGIC_NUMBER))) { + result = YES; + } + return result; +} + - (void)parseWithData:(nonnull NSData *)data cacheKey:(nonnull NSString *)cacheKey completionBlock:(void ( ^ _Nullable)(SVGAVideoEntity * _Nonnull videoItem))completionBlock @@ -124,20 +205,54 @@ - (void)parseWithData:(nonnull NSData *)data SVGAVideoEntity *cacheItem = [SVGAVideoEntity readCache:cacheKey]; if (cacheItem != nil) { if (completionBlock) { - completionBlock(cacheItem); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(cacheItem); + }]; } return; } - [parseQueue addOperationWithBlock:^{ + if (!data || data.length < 4) { + return; + } + if (![SVGAParser isZIPData:data]) { + // Maybe is SVGA 2.0.0 + [parseQueue addOperationWithBlock:^{ + NSData *inflateData = [self zlibInflate:data]; + NSError *err; + SVGAProtoMovieEntity *protoObject = [SVGAProtoMovieEntity parseFromData:inflateData error:&err]; + if (!err && [protoObject isKindOfClass:[SVGAProtoMovieEntity class]]) { + SVGAVideoEntity *videoItem = [[SVGAVideoEntity alloc] initWithProtoObject:protoObject cacheDir:@""]; + [videoItem resetImagesWithProtoObject:protoObject]; + [videoItem resetSpritesWithProtoObject:protoObject]; + [videoItem resetAudiosWithProtoObject:protoObject]; + if (self.enabledMemoryCache) { + [videoItem saveCache:cacheKey]; + } else { + [videoItem saveWeakCache:cacheKey]; + } + if (completionBlock) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(videoItem); + }]; + } + } + }]; + return ; + } + [unzipQueue addOperationWithBlock:^{ if ([[NSFileManager defaultManager] fileExistsAtPath:[self cacheDirectory:cacheKey]]) { [self parseWithCacheKey:cacheKey completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { if (completionBlock) { - completionBlock(videoItem); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(videoItem); + }]; } } failureBlock:^(NSError * _Nonnull error) { [self clearCache:cacheKey]; if (failureBlock) { - failureBlock(error); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock(error); + }]; } }]; return; @@ -153,27 +268,66 @@ - (void)parseWithData:(nonnull NSData *)data } completionHandler:^(NSString *path, BOOL succeeded, NSError *error) { if (error != nil) { if (failureBlock) { - failureBlock(error); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock(error); + }]; } } else { - NSError *err; - NSData *JSONData = [NSData dataWithContentsOfFile:[cacheDir stringByAppendingString:@"/movie.spec"]]; - if (JSONData != nil) { - NSDictionary *JSONObject = [NSJSONSerialization JSONObjectWithData:JSONData options:kNilOptions error:&err]; - if ([JSONObject isKindOfClass:[NSDictionary class]]) { - SVGAVideoEntity *videoItem = [[SVGAVideoEntity alloc] initWithJSONObject:JSONObject cacheDir:cacheDir]; - [videoItem resetImagesWithJSONObject:JSONObject]; - [videoItem resetSpritesWithJSONObject:JSONObject]; - [videoItem saveCache:cacheKey]; + if ([[NSFileManager defaultManager] fileExistsAtPath:[cacheDir stringByAppendingString:@"/movie.binary"]]) { + NSError *err; + NSData *protoData = [NSData dataWithContentsOfFile:[cacheDir stringByAppendingString:@"/movie.binary"]]; + SVGAProtoMovieEntity *protoObject = [SVGAProtoMovieEntity parseFromData:protoData error:&err]; + if (!err) { + SVGAVideoEntity *videoItem = [[SVGAVideoEntity alloc] initWithProtoObject:protoObject cacheDir:cacheDir]; + [videoItem resetImagesWithProtoObject:protoObject]; + [videoItem resetSpritesWithProtoObject:protoObject]; + if (self.enabledMemoryCache) { + [videoItem saveCache:cacheKey]; + } else { + [videoItem saveWeakCache:cacheKey]; + } if (completionBlock) { - completionBlock(videoItem); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(videoItem); + }]; + } + } + else { + if (failureBlock) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock([NSError errorWithDomain:NSFilePathErrorKey code:-1 userInfo:nil]); + }]; } } } else { - if (failureBlock) { - failureBlock([NSError errorWithDomain:NSFilePathErrorKey code:-1 userInfo:nil]); + NSError *err; + NSData *JSONData = [NSData dataWithContentsOfFile:[cacheDir stringByAppendingString:@"/movie.spec"]]; + if (JSONData != nil) { + NSDictionary *JSONObject = [NSJSONSerialization JSONObjectWithData:JSONData options:kNilOptions error:&err]; + if ([JSONObject isKindOfClass:[NSDictionary class]]) { + SVGAVideoEntity *videoItem = [[SVGAVideoEntity alloc] initWithJSONObject:JSONObject cacheDir:cacheDir]; + [videoItem resetImagesWithJSONObject:JSONObject]; + [videoItem resetSpritesWithJSONObject:JSONObject]; + if (self.enabledMemoryCache) { + [videoItem saveCache:cacheKey]; + } else { + [videoItem saveWeakCache:cacheKey]; + } + if (completionBlock) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + completionBlock(videoItem); + }]; + } + } + } + else { + if (failureBlock) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock([NSError errorWithDomain:NSFilePathErrorKey code:-1 userInfo:nil]); + }]; + } } } } @@ -181,13 +335,17 @@ - (void)parseWithData:(nonnull NSData *)data } else { if (failureBlock) { - failureBlock([NSError errorWithDomain:NSFilePathErrorKey code:-1 userInfo:nil]); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock([NSError errorWithDomain:NSFilePathErrorKey code:-1 userInfo:nil]); + }]; } } } else { if (failureBlock) { - failureBlock([NSError errorWithDomain:@"Data Error" code:-1 userInfo:nil]); + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + failureBlock([NSError errorWithDomain:@"Data Error" code:-1 userInfo:nil]); + }]; } } }]; @@ -215,4 +373,48 @@ - (NSString *)MD5String:(NSString *)str { ]; } +- (NSData *)zlibInflate:(NSData *)data +{ + if ([data length] == 0) return data; + + unsigned full_length = (unsigned)[data length]; + unsigned half_length = (unsigned)[data length] / 2; + + NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length]; + BOOL done = NO; + int status; + + z_stream strm; + strm.next_in = (Bytef *)[data bytes]; + strm.avail_in = (unsigned)[data length]; + strm.total_out = 0; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + + if (inflateInit (&strm) != Z_OK) return nil; + + while (!done) + { + // Make sure we have enough room and reset the lengths. + if (strm.total_out >= [decompressed length]) + [decompressed increaseLengthBy: half_length]; + strm.next_out = [decompressed mutableBytes] + strm.total_out; + strm.avail_out = (uInt)([decompressed length] - strm.total_out); + + // Inflate another chunk. + status = inflate (&strm, Z_SYNC_FLUSH); + if (status == Z_STREAM_END) done = YES; + else if (status != Z_OK) break; + } + if (inflateEnd (&strm) != Z_OK) return nil; + + // Set real length. + if (done) + { + [decompressed setLength: strm.total_out]; + return [NSData dataWithData: decompressed]; + } + else return nil; +} + @end diff --git a/Source/SVGAPlayer.h b/Source/SVGAPlayer.h index c4a8e3f1..cdeb8ccf 100644 --- a/Source/SVGAPlayer.h +++ b/Source/SVGAPlayer.h @@ -13,20 +13,29 @@ @protocol SVGAPlayerDelegate @optional -- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player; -- (void)svgaPlayerDidAnimatedToFrame:(NSInteger)frame; -- (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage; +- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player ; + +- (void)svgaPlayer:(SVGAPlayer *)player didAnimatedToFrame:(NSInteger)frame; +- (void)svgaPlayer:(SVGAPlayer *)player didAnimatedToPercentage:(CGFloat)percentage; + +- (void)svgaPlayerDidAnimatedToFrame:(NSInteger)frame API_DEPRECATED("Use svgaPlayer:didAnimatedToFrame: instead", ios(7.0, API_TO_BE_DEPRECATED)); +- (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage API_DEPRECATED("Use svgaPlayer:didAnimatedToPercentage: instead", ios(7.0, API_TO_BE_DEPRECATED)); @end +typedef void(^SVGAPlayerDynamicDrawingBlock)(CALayer *contentLayer, NSInteger frameIndex); + @interface SVGAPlayer : UIView @property (nonatomic, weak) id delegate; @property (nonatomic, strong) SVGAVideoEntity *videoItem; -@property (nonatomic, assign) int loops; -@property (nonatomic, assign) BOOL clearsAfterStop; +@property (nonatomic, assign) IBInspectable int loops; +@property (nonatomic, assign) IBInspectable BOOL clearsAfterStop; +@property (nonatomic, copy) NSString *fillMode; +@property (nonatomic, copy) NSRunLoopMode mainRunLoopMode; - (void)startAnimation; +- (void)startAnimationWithRange:(NSRange)range reverse:(BOOL)reverse; - (void)pauseAnimation; - (void)stopAnimation; - (void)clear; @@ -35,8 +44,12 @@ #pragma mark - Dynamic Object -- (void)setImage:(UIImage *)image forKey:(NSString *)aKey referenceLayer:(CALayer *)referenceLayer; +- (void)setImage:(UIImage *)image forKey:(NSString *)aKey; +- (void)setImageWithURL:(NSURL *)URL forKey:(NSString *)aKey; +- (void)setImage:(UIImage *)image forKey:(NSString *)aKey referenceLayer:(CALayer *)referenceLayer; // deprecated from 2.0.1 - (void)setAttributedText:(NSAttributedString *)attributedText forKey:(NSString *)aKey; +- (void)setDrawingBlock:(SVGAPlayerDynamicDrawingBlock)drawingBlock forKey:(NSString *)aKey; +- (void)setHidden:(BOOL)hidden forKey:(NSString *)aKey; - (void)clearDynamicObjects; @end diff --git a/Source/SVGAPlayer.m b/Source/SVGAPlayer.m index 73c4eb66..289e09f0 100644 --- a/Source/SVGAPlayer.m +++ b/Source/SVGAPlayer.m @@ -11,23 +11,57 @@ #import "SVGAVideoSpriteEntity.h" #import "SVGAVideoSpriteFrameEntity.h" #import "SVGAContentLayer.h" +#import "SVGABitmapLayer.h" #import "SVGAVectorLayer.h" +#import "SVGAAudioLayer.h" +#import "SVGAAudioEntity.h" -@interface SVGAPlayer () { - int _loopCount; -} +@interface SVGAPlayer () @property (nonatomic, strong) CALayer *drawLayer; +@property (nonatomic, strong) NSArray *audioLayers; @property (nonatomic, strong) CADisplayLink *displayLink; @property (nonatomic, assign) NSInteger currentFrame; -@property (nonatomic, copy) NSDictionary *dynamicObjects; -@property (nonatomic, copy) NSDictionary *dynamicLayers; -@property (nonatomic, copy) NSDictionary *dynamicTexts; +@property (nonatomic, copy) NSArray *contentLayers; +@property (nonatomic, copy) NSDictionary *dynamicObjects; +@property (nonatomic, copy) NSDictionary *dynamicTexts; +@property (nonatomic, copy) NSDictionary *dynamicDrawings; +@property (nonatomic, copy) NSDictionary *dynamicHiddens; +@property (nonatomic, assign) int loopCount; +@property (nonatomic, assign) NSRange currentRange; +@property (nonatomic, assign) BOOL forwardAnimating; +@property (nonatomic, assign) BOOL reversing; -@end +@end @implementation SVGAPlayer +- (instancetype)init { + if (self = [super init]) { + [self initPlayer]; + } + return self; +} + +- (instancetype)initWithFrame:(CGRect)frame { + if (self = [super initWithFrame:frame]) { + [self initPlayer]; + } + return self; +} + +- (instancetype)initWithCoder:(NSCoder *)aDecoder { + if (self = [super initWithCoder:aDecoder]) { + [self initPlayer]; + } + return self; +} + +- (void)initPlayer { + self.contentMode = UIViewContentModeTop; + self.clearsAfterStop = YES; +} + - (void)willMoveToSuperview:(UIView *)newSuperview { [super willMoveToSuperview:newSuperview]; if (newSuperview == nil) { @@ -36,11 +70,50 @@ - (void)willMoveToSuperview:(UIView *)newSuperview { } - (void)startAnimation { + if (self.videoItem == nil) { + NSLog(@"videoItem could not be nil!"); + return; + } else if (self.drawLayer == nil) { + self.videoItem = _videoItem; + } [self stopAnimation:NO]; - _loopCount = 0; + self.loopCount = 0; + if (self.videoItem.FPS == 0) { + NSLog(@"videoItem FPS could not be 0!"); + return; + } self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(next)]; self.displayLink.frameInterval = 60 / self.videoItem.FPS; - [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; + [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.mainRunLoopMode]; + self.forwardAnimating = !self.reversing; +} + +- (void)startAnimationWithRange:(NSRange)range reverse:(BOOL)reverse { + if (self.videoItem == nil) { + NSLog(@"videoItem could not be nil!"); + return; + } else if (self.drawLayer == nil) { + self.videoItem = _videoItem; + } + [self stopAnimation:NO]; + self.loopCount = 0; + if (self.videoItem.FPS == 0) { + NSLog(@"videoItem FPS could not be 0!"); + return; + } + + self.currentRange = range; + self.reversing = reverse; + if (reverse) { + self.currentFrame = MIN(self.videoItem.frames - 1, range.location + range.length - 1); + } + else { + self.currentFrame = MAX(0, range.location); + } + self.forwardAnimating = !self.reversing; + self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(next)]; + self.displayLink.frameInterval = 60 / self.videoItem.FPS; + [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.mainRunLoopMode]; } - (void)pauseAnimation { @@ -52,21 +125,39 @@ - (void)stopAnimation { } - (void)stopAnimation:(BOOL)clear { - if (![self.displayLink isPaused]) { - [self.displayLink setPaused:YES]; - [self.displayLink removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; + self.forwardAnimating = NO; + if (self.displayLink != nil) { + [self.displayLink invalidate]; } if (clear) { [self clear]; } + [self clearAudios]; self.displayLink = nil; } - (void)clear { + self.contentLayers = nil; [self.drawLayer removeFromSuperlayer]; + self.drawLayer = nil; +} + +- (void)clearAudios { + for (SVGAAudioLayer *layer in self.audioLayers) { + if (layer.audioPlaying) { + [layer.audioPlayer stop]; + layer.audioPlaying = NO; + } + } } - (void)stepToFrame:(NSInteger)frame andPlay:(BOOL)andPlay { + if (self.videoItem == nil) { + NSLog(@"videoItem could not be nil!"); + return; + } else if (self.drawLayer == nil) { + self.videoItem = _videoItem; + } if (frame >= self.videoItem.frames || frame < 0) { return; } @@ -74,9 +165,14 @@ - (void)stepToFrame:(NSInteger)frame andPlay:(BOOL)andPlay { self.currentFrame = frame; [self update]; if (andPlay) { + self.forwardAnimating = YES; + if (self.videoItem.FPS == 0) { + NSLog(@"videoItem FPS could not be 0!"); + return; + } self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(next)]; self.displayLink.frameInterval = 60 / self.videoItem.FPS; - [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; + [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.mainRunLoopMode]; } } @@ -92,37 +188,71 @@ - (void)draw { self.drawLayer = [[CALayer alloc] init]; self.drawLayer.frame = CGRectMake(0, 0, self.videoItem.videoSize.width, self.videoItem.videoSize.height); self.drawLayer.masksToBounds = true; + NSMutableDictionary *tempHostLayers = [NSMutableDictionary dictionary]; + NSMutableArray *tempContentLayers = [NSMutableArray array]; + [self.videoItem.sprites enumerateObjectsUsingBlock:^(SVGAVideoSpriteEntity * _Nonnull sprite, NSUInteger idx, BOOL * _Nonnull stop) { UIImage *bitmap; if (sprite.imageKey != nil) { - if (self.dynamicObjects[sprite.imageKey] != nil) { - bitmap = self.dynamicObjects[sprite.imageKey]; + NSString *bitmapKey = [sprite.imageKey stringByDeletingPathExtension]; + if (self.dynamicObjects[bitmapKey] != nil) { + bitmap = self.dynamicObjects[bitmapKey]; } else { - bitmap = self.videoItem.images[sprite.imageKey]; + bitmap = self.videoItem.images[bitmapKey]; } } SVGAContentLayer *contentLayer = [sprite requestLayerWithBitmap:bitmap]; - [self.drawLayer addSublayer:contentLayer]; - if (sprite.imageKey != nil) { - if (self.dynamicLayers[sprite.imageKey] != nil) { - CALayer *dynamicLayer = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:self.dynamicLayers[sprite.imageKey]]]; - dynamicLayer.contentsGravity = kCAGravityResizeAspect; - [contentLayer addSublayer:dynamicLayer]; + contentLayer.imageKey = sprite.imageKey; + [tempContentLayers addObject:contentLayer]; + if ([sprite.imageKey hasSuffix:@".matte"]) { + CALayer *hostLayer = [[CALayer alloc] init]; + hostLayer.mask = contentLayer; + tempHostLayers[sprite.imageKey] = hostLayer; + } else { + if (sprite.matteKey && sprite.matteKey.length > 0) { + CALayer *hostLayer = tempHostLayers[sprite.matteKey]; + [hostLayer addSublayer:contentLayer]; + if (![sprite.matteKey isEqualToString:self.videoItem.sprites[idx - 1].matteKey]) { + [self.drawLayer addSublayer:hostLayer]; + } + } else { + [self.drawLayer addSublayer:contentLayer]; } + } + if (sprite.imageKey != nil) { if (self.dynamicTexts[sprite.imageKey] != nil) { NSAttributedString *text = self.dynamicTexts[sprite.imageKey]; - CGSize size = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:NULL].size; + CGSize bitmapSize = CGSizeMake(self.videoItem.images[sprite.imageKey].size.width * self.videoItem.images[sprite.imageKey].scale, self.videoItem.images[sprite.imageKey].size.height * self.videoItem.images[sprite.imageKey].scale); + CGSize size = [text boundingRectWithSize:bitmapSize + options:NSStringDrawingUsesLineFragmentOrigin + context:NULL].size; CATextLayer *textLayer = [CATextLayer layer]; textLayer.contentsScale = [[UIScreen mainScreen] scale]; [textLayer setString:self.dynamicTexts[sprite.imageKey]]; textLayer.frame = CGRectMake(0, 0, size.width, size.height); [contentLayer addSublayer:textLayer]; + contentLayer.textLayer = textLayer; + [contentLayer resetTextLayerProperties:text]; + } + if (self.dynamicHiddens[sprite.imageKey] != nil && + [self.dynamicHiddens[sprite.imageKey] boolValue] == YES) { + contentLayer.dynamicHidden = YES; + } + if (self.dynamicDrawings[sprite.imageKey] != nil) { + contentLayer.dynamicDrawingBlock = self.dynamicDrawings[sprite.imageKey]; } } }]; + self.contentLayers = tempContentLayers; + [self.layer addSublayer:self.drawLayer]; - self.currentFrame = 0; + NSMutableArray *audioLayers = [NSMutableArray array]; + [self.videoItem.audios enumerateObjectsUsingBlock:^(SVGAAudioEntity * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + SVGAAudioLayer *audioLayer = [[SVGAAudioLayer alloc] initWithAudioItem:obj videoItem:self.videoItem]; + [audioLayers addObject:audioLayer]; + }]; + self.audioLayers = audioLayers; [self update]; [self resize]; } @@ -168,10 +298,35 @@ - (void)resize { self.drawLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMake(ratio, 0, 0, ratio, -offset.x, -offset.y)); } } + else if (self.contentMode == UIViewContentModeTop) { + CGFloat scaleX = self.frame.size.width / self.videoItem.videoSize.width; + CGPoint offset = CGPointMake((1.0 - scaleX) / 2.0 * self.videoItem.videoSize.width, (1 - scaleX) / 2.0 * self.videoItem.videoSize.height); + self.drawLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMake(scaleX, 0, 0, scaleX, -offset.x, -offset.y)); + } + else if (self.contentMode == UIViewContentModeBottom) { + CGFloat scaleX = self.frame.size.width / self.videoItem.videoSize.width; + CGPoint offset = CGPointMake( + (1.0 - scaleX) / 2.0 * self.videoItem.videoSize.width, + (1.0 - scaleX) / 2.0 * self.videoItem.videoSize.height); + self.drawLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMake(scaleX, 0, 0, scaleX, -offset.x, -offset.y + self.frame.size.height - self.videoItem.videoSize.height * scaleX)); + } + else if (self.contentMode == UIViewContentModeLeft) { + CGFloat scaleY = self.frame.size.height / self.videoItem.videoSize.height; + CGPoint offset = CGPointMake((1.0 - scaleY) / 2.0 * self.videoItem.videoSize.width, (1 - scaleY) / 2.0 * self.videoItem.videoSize.height); + self.drawLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMake(scaleY, 0, 0, scaleY, -offset.x, -offset.y)); + } + else if (self.contentMode == UIViewContentModeRight) { + CGFloat scaleY = self.frame.size.height / self.videoItem.videoSize.height; + CGPoint offset = CGPointMake( + (1.0 - scaleY) / 2.0 * self.videoItem.videoSize.width, + (1.0 - scaleY) / 2.0 * self.videoItem.videoSize.height); + self.drawLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMake(scaleY, 0, 0, scaleY, -offset.x + self.frame.size.width - self.videoItem.videoSize.width * scaleY, -offset.y)); + } else { - CGFloat ratio = self.frame.size.width / self.videoItem.videoSize.width; - CGPoint offset = CGPointMake((1.0 - ratio) / 2.0 * self.videoItem.videoSize.width, (1 - ratio) / 2.0 * self.videoItem.videoSize.height); - self.drawLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMake(ratio, 0, 0, ratio, -offset.x, -offset.y)); + CGFloat scaleX = self.frame.size.width / self.videoItem.videoSize.width; + CGFloat scaleY = self.frame.size.height / self.videoItem.videoSize.height; + CGPoint offset = CGPointMake((1.0 - scaleX) / 2.0 * self.videoItem.videoSize.width, (1 - scaleY) / 2.0 * self.videoItem.videoSize.height); + self.drawLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMake(scaleX, 0, 0, scaleY, -offset.x, -offset.y)); } } @@ -182,39 +337,82 @@ - (void)layoutSubviews { - (void)update { [CATransaction setDisableActions:YES]; - for (SVGAContentLayer *layer in self.drawLayer.sublayers) { + for (SVGAContentLayer *layer in self.contentLayers) { if ([layer isKindOfClass:[SVGAContentLayer class]]) { [layer stepToFrame:self.currentFrame]; } } [CATransaction setDisableActions:NO]; + if (self.forwardAnimating && self.audioLayers.count > 0) { + for (SVGAAudioLayer *layer in self.audioLayers) { + if (!layer.audioPlaying && layer.audioItem.startFrame <= self.currentFrame && self.currentFrame <= layer.audioItem.endFrame) { + [layer.audioPlayer setCurrentTime:(NSTimeInterval)(layer.audioItem.startTime / 1000)]; + [layer.audioPlayer play]; + layer.audioPlaying = YES; + } + if (layer.audioPlaying && layer.audioItem.endFrame <= self.currentFrame) { + [layer.audioPlayer stop]; + layer.audioPlaying = NO; + } + } + } } - (void)next { - self.currentFrame++; - if (self.currentFrame >= self.videoItem.frames) { - self.currentFrame = 0; - _loopCount++; - if (self.loops > 0 && _loopCount >= self.loops) { - [self stopAnimation]; - id delegate = self.delegate; - if (delegate != nil && [delegate respondsToSelector:@selector(svgaPlayerDidFinishedAnimation:)]) { - [delegate svgaPlayerDidFinishedAnimation:self]; - } + if (self.reversing) { + self.currentFrame--; + if (self.currentFrame < (NSInteger)MAX(0, self.currentRange.location)) { + self.currentFrame = MIN(self.videoItem.frames - 1, self.currentRange.location + self.currentRange.length - 1); + self.loopCount++; + } + } + else { + self.currentFrame++; + if (self.currentFrame >= MIN(self.videoItem.frames, self.currentRange.location + self.currentRange.length)) { + self.currentFrame = MAX(0, self.currentRange.location); + [self clearAudios]; + self.loopCount++; } } + if (self.loops > 0 && self.loopCount >= self.loops) { + [self stopAnimation]; + if (!self.clearsAfterStop && [self.fillMode isEqualToString:@"Backward"]) { + [self stepToFrame:MAX(0, self.currentRange.location) andPlay:NO]; + } + else if (!self.clearsAfterStop && [self.fillMode isEqualToString:@"Forward"]) { + [self stepToFrame:MIN(self.videoItem.frames - 1, self.currentRange.location + self.currentRange.length - 1) andPlay:NO]; + } + id delegate = self.delegate; + if (delegate != nil && [delegate respondsToSelector:@selector(svgaPlayerDidFinishedAnimation:)]) { + [delegate svgaPlayerDidFinishedAnimation:self]; + } + return; + } [self update]; id delegate = self.delegate; - if (delegate != nil && [delegate respondsToSelector:@selector(svgaPlayerDidAnimatedToFrame:)]) { - [delegate svgaPlayerDidAnimatedToFrame:self.currentFrame]; - } - if (delegate != nil && [delegate respondsToSelector:@selector(svgaPlayerDidAnimatedToPercentage:)] && self.videoItem.frames > 0) { - [delegate svgaPlayerDidAnimatedToPercentage:(CGFloat)(self.currentFrame + 1) / (CGFloat)self.videoItem.frames]; + if (delegate != nil) { + if ([delegate respondsToSelector:@selector(svgaPlayer:didAnimatedToFrame:)]) { + [delegate svgaPlayer:self didAnimatedToFrame:self.currentFrame]; + } else if ([delegate respondsToSelector:@selector(svgaPlayerDidAnimatedToFrame:)]){ + [delegate svgaPlayerDidAnimatedToFrame:self.currentFrame]; + } + + if (self.videoItem.frames > 0) { + if ([delegate respondsToSelector:@selector(svgaPlayer:didAnimatedToPercentage:)]) { + [delegate svgaPlayer:self didAnimatedToPercentage:(CGFloat)(self.currentFrame + 1) / (CGFloat)self.videoItem.frames]; + } else if ([delegate respondsToSelector:@selector(svgaPlayerDidAnimatedToPercentage:)]) { + [delegate svgaPlayerDidAnimatedToPercentage:(CGFloat)(self.currentFrame + 1) / (CGFloat)self.videoItem.frames]; + } + } } } - (void)setVideoItem:(SVGAVideoEntity *)videoItem { _videoItem = videoItem; + _currentRange = NSMakeRange(0, videoItem.frames); + _reversing = NO; + _currentFrame = 0; + _loopCount = 0; [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [self clear]; [self draw]; @@ -223,20 +421,39 @@ - (void)setVideoItem:(SVGAVideoEntity *)videoItem { #pragma mark - Dynamic Object -- (void)setImage:(UIImage *)image forKey:(NSString *)aKey referenceLayer:(CALayer *)referenceLayer { +- (void)setImage:(UIImage *)image forKey:(NSString *)aKey { if (image == nil) { return; } NSMutableDictionary *mutableDynamicObjects = [self.dynamicObjects mutableCopy]; [mutableDynamicObjects setObject:image forKey:aKey]; self.dynamicObjects = mutableDynamicObjects; - if (referenceLayer != nil) { - NSMutableDictionary *mutableDynamicLayers = [self.dynamicLayers mutableCopy]; - [mutableDynamicLayers setObject:referenceLayer forKey:aKey]; - self.dynamicLayers = mutableDynamicLayers; + if (self.contentLayers.count > 0) { + for (SVGAContentLayer *layer in self.contentLayers) { + if ([layer isKindOfClass:[SVGAContentLayer class]] && [layer.imageKey isEqualToString:aKey]) { + layer.bitmapLayer.contents = (__bridge id _Nullable)([image CGImage]); + } + } } } +- (void)setImageWithURL:(NSURL *)URL forKey:(NSString *)aKey { + [[[NSURLSession sharedSession] dataTaskWithURL:URL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + if (error == nil && data != nil) { + UIImage *image = [UIImage imageWithData:data]; + if (image != nil) { + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + [self setImage:image forKey:aKey]; + }]; + } + } + }] resume]; +} + +- (void)setImage:(UIImage *)image forKey:(NSString *)aKey referenceLayer:(CALayer *)referenceLayer { + [self setImage:image forKey:aKey]; +} + - (void)setAttributedText:(NSAttributedString *)attributedText forKey:(NSString *)aKey { if (attributedText == nil) { return; @@ -244,11 +461,63 @@ - (void)setAttributedText:(NSAttributedString *)attributedText forKey:(NSString NSMutableDictionary *mutableDynamicTexts = [self.dynamicTexts mutableCopy]; [mutableDynamicTexts setObject:attributedText forKey:aKey]; self.dynamicTexts = mutableDynamicTexts; + if (self.contentLayers.count > 0) { + CGSize bitmapSize = CGSizeMake(self.videoItem.images[aKey].size.width * self.videoItem.images[aKey].scale, self.videoItem.images[aKey].size.height * self.videoItem.images[aKey].scale); + CGSize size = [attributedText boundingRectWithSize:bitmapSize + options:NSStringDrawingUsesLineFragmentOrigin context:NULL].size; + CATextLayer *textLayer; + for (SVGAContentLayer *layer in self.contentLayers) { + if ([layer isKindOfClass:[SVGAContentLayer class]] && [layer.imageKey isEqualToString:aKey]) { + textLayer = layer.textLayer; + if (textLayer == nil) { + textLayer = [CATextLayer layer]; + [layer addSublayer:textLayer]; + layer.textLayer = textLayer; + [layer resetTextLayerProperties:attributedText]; + } + } + } + if (textLayer != nil) { + textLayer.contentsScale = [[UIScreen mainScreen] scale]; + [textLayer setString:attributedText]; + textLayer.frame = CGRectMake(0, 0, size.width, size.height); + } + } +} + +- (void)setDrawingBlock:(SVGAPlayerDynamicDrawingBlock)drawingBlock forKey:(NSString *)aKey { + NSMutableDictionary *mutableDynamicDrawings = [self.dynamicDrawings mutableCopy]; + [mutableDynamicDrawings setObject:drawingBlock forKey:aKey]; + self.dynamicDrawings = mutableDynamicDrawings; + if (self.contentLayers.count > 0) { + for (SVGAContentLayer *layer in self.contentLayers) { + if ([layer isKindOfClass:[SVGAContentLayer class]] && + [layer.imageKey isEqualToString:aKey]) { + layer.dynamicDrawingBlock = drawingBlock; + } + } + } +} + +- (void)setHidden:(BOOL)hidden forKey:(NSString *)aKey { + NSMutableDictionary *mutableDynamicHiddens = [self.dynamicHiddens mutableCopy]; + [mutableDynamicHiddens setObject:@(hidden) forKey:aKey]; + self.dynamicHiddens = mutableDynamicHiddens; + if (self.contentLayers.count > 0) { + for (SVGAContentLayer *layer in self.contentLayers) { + if ([layer isKindOfClass:[SVGAContentLayer class]] && + [layer.imageKey isEqualToString:aKey]) { + layer.dynamicHidden = hidden; + } + } + } } - (void)clearDynamicObjects { self.dynamicObjects = nil; - self.dynamicLayers = nil; + self.dynamicTexts = nil; + self.dynamicHiddens = nil; + self.dynamicDrawings = nil; } - (NSDictionary *)dynamicObjects { @@ -258,13 +527,6 @@ - (NSDictionary *)dynamicObjects { return _dynamicObjects; } -- (NSDictionary *)dynamicLayers { - if (_dynamicLayers == nil) { - _dynamicLayers = @{}; - } - return _dynamicLayers; -} - - (NSDictionary *)dynamicTexts { if (_dynamicTexts == nil) { _dynamicTexts = @{}; @@ -272,4 +534,25 @@ - (NSDictionary *)dynamicTexts { return _dynamicTexts; } +- (NSDictionary *)dynamicHiddens { + if (_dynamicHiddens == nil) { + _dynamicHiddens = @{}; + } + return _dynamicHiddens; +} + +- (NSDictionary *)dynamicDrawings { + if (_dynamicDrawings == nil) { + _dynamicDrawings = @{}; + } + return _dynamicDrawings; +} + +- (NSRunLoopMode)mainRunLoopMode { + if (!_mainRunLoopMode) { + _mainRunLoopMode = NSRunLoopCommonModes; + } + return _mainRunLoopMode; +} + @end diff --git a/Source/SVGAVectorLayer.m b/Source/SVGAVectorLayer.m index bd549463..153411f9 100644 --- a/Source/SVGAVectorLayer.m +++ b/Source/SVGAVectorLayer.m @@ -9,6 +9,7 @@ #import "SVGAVectorLayer.h" #import "SVGABezierPath.h" #import "SVGAVideoSpriteFrameEntity.h" +#import "Svga.pbobjc.h" @interface SVGAVectorLayer () @@ -54,10 +55,19 @@ - (void)stepToFrame:(NSInteger)frame { } - (BOOL)isKeepFrame:(SVGAVideoSpriteFrameEntity *)frameItem { - return frameItem.shapes.firstObject != nil && - [frameItem.shapes.firstObject isKindOfClass:[NSDictionary class]] && - [frameItem.shapes.firstObject[@"type"] isKindOfClass:[NSString class]] && - [frameItem.shapes.firstObject[@"type"] isEqualToString:@"keep"]; + if (frameItem.shapes.count == 0) { + return NO; + } + else if ([frameItem.shapes.firstObject isKindOfClass:[NSDictionary class]]) { + return [frameItem.shapes.firstObject[@"type"] isKindOfClass:[NSString class]] && + [frameItem.shapes.firstObject[@"type"] isEqualToString:@"keep"]; + } + else if ([frameItem.shapes.firstObject isKindOfClass:[SVGAProtoShapeEntity class]]) { + return [(SVGAProtoShapeEntity *)frameItem.shapes.firstObject type] == SVGAProtoShapeEntity_ShapeType_Keep; + } + else { + return NO; + } } - (NSInteger)requestKeepFrame:(NSInteger)frame { @@ -75,7 +85,7 @@ - (void)drawFrame:(NSInteger)frame { return; } } - [self.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)]; + while(self.sublayers.count) [self.sublayers.firstObject removeFromSuperlayer]; for (NSDictionary *shape in frameItem.shapes) { if ([shape isKindOfClass:[NSDictionary class]]) { if ([shape[@"type"] isKindOfClass:[NSString class]]) { @@ -90,6 +100,18 @@ - (void)drawFrame:(NSInteger)frame { } } } + else if ([shape isKindOfClass:[SVGAProtoShapeEntity class]]) { + SVGAProtoShapeEntity *shapeItem = (id)shape; + if (shapeItem.type == SVGAProtoShapeEntity_ShapeType_Shape) { + [self addSublayer:[self createCurveLayerWithProto:shapeItem]]; + } + else if (shapeItem.type == SVGAProtoShapeEntity_ShapeType_Ellipse) { + [self addSublayer:[self createEllipseLayerWithProto:shapeItem]]; + } + else if (shapeItem.type == SVGAProtoShapeEntity_ShapeType_Rect) { + [self addSublayer:[self createRectLayerWithProto:shapeItem]]; + } + } } self.drawedFrame = frame; } @@ -108,6 +130,19 @@ - (CALayer *)createCurveLayer:(NSDictionary *)shape { return shapeLayer; } +- (CALayer *)createCurveLayerWithProto:(SVGAProtoShapeEntity *)shape { + SVGABezierPath *bezierPath = [SVGABezierPath new]; + if (shape.argsOneOfCase == SVGAProtoShapeEntity_Args_OneOfCase_Shape) { + if ([shape.shape.d isKindOfClass:[NSString class]] && shape.shape.d.length > 0) { + [bezierPath setValues:shape.shape.d]; + } + } + CAShapeLayer *shapeLayer = [bezierPath createLayer]; + [self resetStyles:shapeLayer protoShape:shape]; + [self resetTransform:shapeLayer protoShape:shape]; + return shapeLayer; +} + - (CALayer *)createEllipseLayer:(NSDictionary *)shape { UIBezierPath *bezierPath; if ([shape[@"args"] isKindOfClass:[NSDictionary class]]) { @@ -134,6 +169,26 @@ - (CALayer *)createEllipseLayer:(NSDictionary *)shape { } } +- (CALayer *)createEllipseLayerWithProto:(SVGAProtoShapeEntity *)shape { + UIBezierPath *bezierPath; + if (shape.argsOneOfCase == SVGAProtoShapeEntity_Args_OneOfCase_Ellipse) { + bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(shape.ellipse.x - shape.ellipse.radiusX, + shape.ellipse.y - shape.ellipse.radiusY, + shape.ellipse.radiusX * 2, + shape.ellipse.radiusY * 2)]; + } + if (bezierPath != nil) { + CAShapeLayer *shapeLayer = [CAShapeLayer layer]; + [shapeLayer setPath:[bezierPath CGPath]]; + [self resetStyles:shapeLayer protoShape:shape]; + [self resetTransform:shapeLayer protoShape:shape]; + return shapeLayer; + } + else { + return [CALayer layer]; + } +} + - (CALayer *)createRectLayer:(NSDictionary *)shape { UIBezierPath *bezierPath; if ([shape[@"args"] isKindOfClass:[NSDictionary class]]) { @@ -162,6 +217,24 @@ - (CALayer *)createRectLayer:(NSDictionary *)shape { } } +- (CALayer *)createRectLayerWithProto:(SVGAProtoShapeEntity *)shape { + UIBezierPath *bezierPath; + if (shape.argsOneOfCase == SVGAProtoShapeEntity_Args_OneOfCase_Rect) { + bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(shape.rect.x, shape.rect.y, shape.rect.width, shape.rect.height) + cornerRadius:shape.rect.cornerRadius]; + } + if (bezierPath != nil) { + CAShapeLayer *shapeLayer = [CAShapeLayer layer]; + [shapeLayer setPath:[bezierPath CGPath]]; + [self resetStyles:shapeLayer protoShape:shape]; + [self resetTransform:shapeLayer protoShape:shape]; + return shapeLayer; + } + else { + return [CALayer layer]; + } +} + - (void)resetStyles:(CAShapeLayer *)shapeLayer shape:(NSDictionary *)shape { shapeLayer.masksToBounds = NO; shapeLayer.backgroundColor = [UIColor clearColor].CGColor; @@ -227,6 +300,63 @@ - (void)resetStyles:(CAShapeLayer *)shapeLayer shape:(NSDictionary *)shape { } } +- (void)resetStyles:(CAShapeLayer *)shapeLayer protoShape:(SVGAProtoShapeEntity *)protoShape { + shapeLayer.masksToBounds = NO; + shapeLayer.backgroundColor = [UIColor clearColor].CGColor; + if (protoShape.hasStyles) { + if (protoShape.styles.hasFill) { + shapeLayer.fillColor = [UIColor colorWithRed:protoShape.styles.fill.r + green:protoShape.styles.fill.g + blue:protoShape.styles.fill.b + alpha:protoShape.styles.fill.a].CGColor; + } + else { + shapeLayer.fillColor = [UIColor clearColor].CGColor; + } + if (protoShape.styles.hasStroke) { + shapeLayer.strokeColor = [UIColor colorWithRed:protoShape.styles.stroke.r + green:protoShape.styles.stroke.g + blue:protoShape.styles.stroke.b + alpha:protoShape.styles.stroke.a].CGColor; + } + shapeLayer.lineWidth = protoShape.styles.strokeWidth; + switch (protoShape.styles.lineCap) { + case SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapButt: + shapeLayer.lineCap = @"butt"; + break; + case SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapRound: + shapeLayer.lineCap = @"round"; + break; + case SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapSquare: + shapeLayer.lineCap = @"square"; + break; + default: + break; + } + switch (protoShape.styles.lineJoin) { + case SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinRound: + shapeLayer.lineJoin = @"round"; + break; + case SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinMiter: + shapeLayer.lineJoin = @"miter"; + break; + case SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinBevel: + shapeLayer.lineJoin = @"bevel"; + break; + default: + break; + } + shapeLayer.lineDashPhase = protoShape.styles.lineDashIii; + if (protoShape.styles.lineDashI > 0.0 || protoShape.styles.lineDashIi > 0.0) { + shapeLayer.lineDashPattern = @[ + (protoShape.styles.lineDashI < 1.0 ? @(1.0) : @(protoShape.styles.lineDashI)), + (protoShape.styles.lineDashIi < 0.1 ? @(0.1) : @(protoShape.styles.lineDashIi)) + ]; + } + shapeLayer.miterLimit = protoShape.styles.miterLimit; + } +} + - (void)resetTransform:(CAShapeLayer *)shapeLayer shape:(NSDictionary *)shape { if ([shape[@"transform"] isKindOfClass:[NSDictionary class]]) { if ([shape[@"transform"][@"a"] isKindOfClass:[NSNumber class]] && @@ -246,4 +376,16 @@ - (void)resetTransform:(CAShapeLayer *)shapeLayer shape:(NSDictionary *)shape { } } +- (void)resetTransform:(CAShapeLayer *)shapeLayer protoShape:(SVGAProtoShapeEntity *)protoShape { + if (protoShape.hasTransform) { + shapeLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMake((CGFloat)protoShape.transform.a, + (CGFloat)protoShape.transform.b, + (CGFloat)protoShape.transform.c, + (CGFloat)protoShape.transform.d, + (CGFloat)protoShape.transform.tx, + (CGFloat)protoShape.transform.ty) + ); + } +} + @end diff --git a/Source/SVGAVideoEntity.h b/Source/SVGAVideoEntity.h index 160e4d29..77498206 100644 --- a/Source/SVGAVideoEntity.h +++ b/Source/SVGAVideoEntity.h @@ -9,7 +9,8 @@ #import #import -@class SVGAVideoEntity, SVGAVideoSpriteEntity, SVGAVideoSpriteFrameEntity, SVGABitmapLayer, SVGAVectorLayer; +@class SVGAVideoEntity, SVGAVideoSpriteEntity, SVGAVideoSpriteFrameEntity, SVGABitmapLayer, SVGAVectorLayer, SVGAAudioEntity; +@class SVGAProtoMovieEntity; @interface SVGAVideoEntity : NSObject @@ -17,15 +18,24 @@ @property (nonatomic, readonly) int FPS; @property (nonatomic, readonly) int frames; @property (nonatomic, readonly) NSDictionary *images; +@property (nonatomic, readonly) NSDictionary *audiosData; @property (nonatomic, readonly) NSArray *sprites; +@property (nonatomic, readonly) NSArray *audios; - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject cacheDir:(NSString *)cacheDir; - (void)resetImagesWithJSONObject:(NSDictionary *)JSONObject; - (void)resetSpritesWithJSONObject:(NSDictionary *)JSONObject; +- (instancetype)initWithProtoObject:(SVGAProtoMovieEntity *)protoObject cacheDir:(NSString *)cacheDir; +- (void)resetImagesWithProtoObject:(SVGAProtoMovieEntity *)protoObject; +- (void)resetSpritesWithProtoObject:(SVGAProtoMovieEntity *)protoObject; +- (void)resetAudiosWithProtoObject:(SVGAProtoMovieEntity *)protoObject; + + (SVGAVideoEntity *)readCache:(NSString *)cacheKey; +// NSCache缓存 - (void)saveCache:(NSString *)cacheKey; - +// NSMapTable弱缓存 +- (void)saveWeakCache:(NSString *)cacheKey; @end diff --git a/Source/SVGAVideoEntity.m b/Source/SVGAVideoEntity.m index a6465b1d..cd63400a 100644 --- a/Source/SVGAVideoEntity.m +++ b/Source/SVGAVideoEntity.m @@ -6,9 +6,14 @@ // Copyright © 2016年 UED Center. All rights reserved. // +#import #import "SVGAVideoEntity.h" #import "SVGABezierPath.h" #import "SVGAVideoSpriteEntity.h" +#import "SVGAAudioEntity.h" +#import "Svga.pbobjc.h" + +#define MP3_MAGIC_NUMBER "ID3" @interface SVGAVideoEntity () @@ -16,7 +21,9 @@ @interface SVGAVideoEntity () @property (nonatomic, assign) int FPS; @property (nonatomic, assign) int frames; @property (nonatomic, copy) NSDictionary *images; +@property (nonatomic, copy) NSDictionary *audiosData; @property (nonatomic, copy) NSArray *sprites; +@property (nonatomic, copy) NSArray *audios; @property (nonatomic, copy) NSString *cacheDir; @end @@ -24,11 +31,17 @@ @interface SVGAVideoEntity () @implementation SVGAVideoEntity static NSCache *videoCache; +static NSMapTable * weakCache; +static dispatch_semaphore_t videoSemaphore; + (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ videoCache = [[NSCache alloc] init]; + weakCache = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory + valueOptions:NSPointerFunctionsWeakMemory + capacity:64]; + videoSemaphore = dispatch_semaphore_create(1); }); } @@ -76,11 +89,12 @@ - (void)resetImagesWithJSONObject:(NSDictionary *)JSONObject { [JSONImages enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull obj, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[NSString class]]) { NSString *filePath = [self.cacheDir stringByAppendingFormat:@"/%@.png", obj]; - NSData *imageData = [NSData dataWithContentsOfFile:filePath]; +// NSData *imageData = [NSData dataWithContentsOfFile:filePath]; + NSData *imageData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:NULL]; if (imageData != nil) { UIImage *image = [[UIImage alloc] initWithData:imageData scale:2.0]; if (image != nil) { - [images setObject:image forKey:key]; + [images setObject:image forKey:[key stringByDeletingPathExtension]]; } } } @@ -106,12 +120,117 @@ - (void)resetSpritesWithJSONObject:(NSDictionary *)JSONObject { } } +- (instancetype)initWithProtoObject:(SVGAProtoMovieEntity *)protoObject cacheDir:(NSString *)cacheDir { + self = [super init]; + if (self) { + _videoSize = CGSizeMake(100, 100); + _FPS = 20; + _images = @{}; + _cacheDir = cacheDir; + [self resetMovieWithProtoObject:protoObject]; + } + return self; +} + +- (void)resetMovieWithProtoObject:(SVGAProtoMovieEntity *)protoObject { + if (protoObject.hasParams) { + self.videoSize = CGSizeMake((CGFloat)protoObject.params.viewBoxWidth, (CGFloat)protoObject.params.viewBoxHeight); + self.FPS = (int)protoObject.params.fps; + self.frames = (int)protoObject.params.frames; + } +} + ++ (BOOL)isMP3Data:(NSData *)data { + BOOL result = NO; + if (!strncmp([data bytes], MP3_MAGIC_NUMBER, strlen(MP3_MAGIC_NUMBER))) { + result = YES; + } + return result; +} + +- (void)resetImagesWithProtoObject:(SVGAProtoMovieEntity *)protoObject { + NSMutableDictionary *images = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *audiosData = [[NSMutableDictionary alloc] init]; + NSDictionary *protoImages = [protoObject.images copy]; + for (NSString *key in protoImages) { + NSString *fileName = [[NSString alloc] initWithData:protoImages[key] encoding:NSUTF8StringEncoding]; + if (fileName != nil) { + NSString *filePath = [self.cacheDir stringByAppendingFormat:@"/%@.png", fileName]; + if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { + filePath = [self.cacheDir stringByAppendingFormat:@"/%@", fileName]; + } + if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { +// NSData *imageData = [NSData dataWithContentsOfFile:filePath]; + NSData *imageData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:NULL]; + if (imageData != nil) { + UIImage *image = [[UIImage alloc] initWithData:imageData scale:2.0]; + if (image != nil) { + [images setObject:image forKey:key]; + } + } + } + } + else if ([protoImages[key] isKindOfClass:[NSData class]]) { + if ([SVGAVideoEntity isMP3Data:protoImages[key]]) { + // mp3 + [audiosData setObject:protoImages[key] forKey:key]; + } else { + UIImage *image = [[UIImage alloc] initWithData:protoImages[key] scale:2.0]; + if (image != nil) { + [images setObject:image forKey:key]; + } + } + } + } + self.images = images; + self.audiosData = audiosData; +} + +- (void)resetSpritesWithProtoObject:(SVGAProtoMovieEntity *)protoObject { + NSMutableArray *sprites = [[NSMutableArray alloc] init]; + NSArray *protoSprites = [protoObject.spritesArray copy]; + [protoSprites enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + if ([obj isKindOfClass:[SVGAProtoSpriteEntity class]]) { + SVGAVideoSpriteEntity *spriteItem = [[SVGAVideoSpriteEntity alloc] initWithProtoObject:obj]; + [sprites addObject:spriteItem]; + } + }]; + self.sprites = sprites; +} + +- (void)resetAudiosWithProtoObject:(SVGAProtoMovieEntity *)protoObject { + NSMutableArray *audios = [[NSMutableArray alloc] init]; + NSArray *protoAudios = [protoObject.audiosArray copy]; + [protoAudios enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + if ([obj isKindOfClass:[SVGAProtoAudioEntity class]]) { + SVGAAudioEntity *audioItem = [[SVGAAudioEntity alloc] initWithProtoObject:obj]; + [audios addObject:audioItem]; + } + }]; + self.audios = audios; +} + + (SVGAVideoEntity *)readCache:(NSString *)cacheKey { - return [videoCache objectForKey:cacheKey]; + dispatch_semaphore_wait(videoSemaphore, DISPATCH_TIME_FOREVER); + SVGAVideoEntity * object = [videoCache objectForKey:cacheKey]; + if (!object) { + object = [weakCache objectForKey:cacheKey]; + } + dispatch_semaphore_signal(videoSemaphore); + + return object; } - (void)saveCache:(NSString *)cacheKey { + dispatch_semaphore_wait(videoSemaphore, DISPATCH_TIME_FOREVER); [videoCache setObject:self forKey:cacheKey]; + dispatch_semaphore_signal(videoSemaphore); +} + +- (void)saveWeakCache:(NSString *)cacheKey { + dispatch_semaphore_wait(videoSemaphore, DISPATCH_TIME_FOREVER); + [weakCache setObject:self forKey:cacheKey]; + dispatch_semaphore_signal(videoSemaphore); } @end @@ -120,6 +239,7 @@ @interface SVGAVideoSpriteEntity() @property (nonatomic, copy) NSString *imageKey; @property (nonatomic, copy) NSArray *frames; +@property (nonatomic, copy) NSString *matteKey; @end diff --git a/Source/SVGAVideoSpriteEntity.h b/Source/SVGAVideoSpriteEntity.h index 665d65e0..aad7093e 100644 --- a/Source/SVGAVideoSpriteEntity.h +++ b/Source/SVGAVideoSpriteEntity.h @@ -10,13 +10,16 @@ #import @class SVGAVideoSpriteFrameEntity, SVGAContentLayer; +@class SVGAProtoSpriteEntity; @interface SVGAVideoSpriteEntity : NSObject @property (nonatomic, readonly) NSString *imageKey; @property (nonatomic, readonly) NSArray *frames; +@property (nonatomic, readonly) NSString *matteKey; - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject; +- (instancetype)initWithProtoObject:(SVGAProtoSpriteEntity *)protoObject; - (SVGAContentLayer *)requestLayerWithBitmap:(UIImage *)bitmap; diff --git a/Source/SVGAVideoSpriteEntity.m b/Source/SVGAVideoSpriteEntity.m index 9809e635..37b9036e 100644 --- a/Source/SVGAVideoSpriteEntity.m +++ b/Source/SVGAVideoSpriteEntity.m @@ -11,6 +11,7 @@ #import "SVGABitmapLayer.h" #import "SVGAContentLayer.h" #import "SVGAVectorLayer.h" +#import "Svga.pbobjc.h" @implementation SVGAVideoSpriteEntity @@ -19,6 +20,7 @@ - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject { if (self) { if ([JSONObject isKindOfClass:[NSDictionary class]]) { NSString *imageKey = JSONObject[@"imageKey"]; + NSString *matteKey = JSONObject[@"matteKey"]; NSArray *JSONFrames = JSONObject[@"frames"]; if ([imageKey isKindOfClass:[NSString class]] && [JSONFrames isKindOfClass:[NSArray class]]) { NSMutableArray *frames = [[NSMutableArray alloc] init]; @@ -29,6 +31,30 @@ - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject { }]; _imageKey = imageKey; _frames = frames; + _matteKey = matteKey; + } + } + } + return self; +} + +- (instancetype)initWithProtoObject:(SVGAProtoSpriteEntity *)protoObject { + self = [super init]; + if (self) { + if ([protoObject isKindOfClass:[SVGAProtoSpriteEntity class]]) { + NSString *imageKey = protoObject.imageKey; + NSString *matteKey = protoObject.matteKey; + NSArray *protoFrames = [protoObject.framesArray copy]; + if ([imageKey isKindOfClass:[NSString class]] && [protoFrames isKindOfClass:[NSArray class]]) { + NSMutableArray *frames = [[NSMutableArray alloc] init]; + [protoFrames enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + if ([obj isKindOfClass:[SVGAProtoFrameEntity class]]) { + [frames addObject:[[SVGAVideoSpriteFrameEntity alloc] initWithProtoObject:obj]]; + } + }]; + _imageKey = imageKey; + _frames = frames; + _matteKey = matteKey; } } } diff --git a/Source/SVGAVideoSpriteFrameEntity.h b/Source/SVGAVideoSpriteFrameEntity.h index 17af8dac..858e7679 100644 --- a/Source/SVGAVideoSpriteFrameEntity.h +++ b/Source/SVGAVideoSpriteFrameEntity.h @@ -10,6 +10,7 @@ #import @class SVGAVectorLayer; +@class SVGAProtoFrameEntity; @interface SVGAVideoSpriteFrameEntity : NSObject @@ -22,5 +23,6 @@ @property (nonatomic, readonly) NSArray *shapes; - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject; +- (instancetype)initWithProtoObject:(SVGAProtoFrameEntity *)protoObject; @end diff --git a/Source/SVGAVideoSpriteFrameEntity.m b/Source/SVGAVideoSpriteFrameEntity.m index 62108139..74f2dc00 100644 --- a/Source/SVGAVideoSpriteFrameEntity.m +++ b/Source/SVGAVideoSpriteFrameEntity.m @@ -9,6 +9,7 @@ #import "SVGAVideoSpriteFrameEntity.h" #import "SVGAVectorLayer.h" #import "SVGABezierPath.h" +#import "Svga.pbobjc.h" @interface SVGAVideoSpriteFrameEntity () @@ -18,6 +19,7 @@ @interface SVGAVideoSpriteFrameEntity () @property (nonatomic, assign) CGRect layout; @property (nonatomic, assign) CGFloat nx; @property (nonatomic, assign) CGFloat ny; +@property (nonatomic, strong) NSString *clipPath; @property (nonatomic, strong) CALayer *maskLayer; @property (nonatomic, strong) NSArray *shapes; @@ -60,9 +62,7 @@ - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject { } NSString *clipPath = JSONObject[@"clipPath"]; if ([clipPath isKindOfClass:[NSString class]]) { - SVGABezierPath *bezierPath = [[SVGABezierPath alloc] init]; - [bezierPath setValues:clipPath]; - self.maskLayer = [bezierPath createLayer]; + self.clipPath = clipPath; } NSArray *shapes = JSONObject[@"shapes"]; if ([shapes isKindOfClass:[NSArray class]]) { @@ -83,4 +83,56 @@ - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject { return self; } +- (instancetype)initWithProtoObject:(SVGAProtoFrameEntity *)protoObject { + self = [super init]; + if (self) { + _alpha = 0.0; + _layout = CGRectZero; + _transform = CGAffineTransformMake(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + if ([protoObject isKindOfClass:[SVGAProtoFrameEntity class]]) { + _alpha = protoObject.alpha; + if (protoObject.hasLayout) { + _layout = CGRectMake((CGFloat)protoObject.layout.x, + (CGFloat)protoObject.layout.y, + (CGFloat)protoObject.layout.width, + (CGFloat)protoObject.layout.height); + } + if (protoObject.hasTransform) { + _transform = CGAffineTransformMake((CGFloat)protoObject.transform.a, + (CGFloat)protoObject.transform.b, + (CGFloat)protoObject.transform.c, + (CGFloat)protoObject.transform.d, + (CGFloat)protoObject.transform.tx, + (CGFloat)protoObject.transform.ty); + } + if ([protoObject.clipPath isKindOfClass:[NSString class]] && protoObject.clipPath.length > 0) { + self.clipPath = protoObject.clipPath; + } + if ([protoObject.shapesArray isKindOfClass:[NSArray class]]) { + _shapes = [protoObject.shapesArray copy]; + } + } + CGFloat llx = _transform.a * _layout.origin.x + _transform.c * _layout.origin.y + _transform.tx; + CGFloat lrx = _transform.a * (_layout.origin.x + _layout.size.width) + _transform.c * _layout.origin.y + _transform.tx; + CGFloat lbx = _transform.a * _layout.origin.x + _transform.c * (_layout.origin.y + _layout.size.height) + _transform.tx; + CGFloat rbx = _transform.a * (_layout.origin.x + _layout.size.width) + _transform.c * (_layout.origin.y + _layout.size.height) + _transform.tx; + CGFloat lly = _transform.b * _layout.origin.x + _transform.d * _layout.origin.y + _transform.ty; + CGFloat lry = _transform.b * (_layout.origin.x + _layout.size.width) + _transform.d * _layout.origin.y + _transform.ty; + CGFloat lby = _transform.b * _layout.origin.x + _transform.d * (_layout.origin.y + _layout.size.height) + _transform.ty; + CGFloat rby = _transform.b * (_layout.origin.x + _layout.size.width) + _transform.d * (_layout.origin.y + _layout.size.height) + _transform.ty; + _nx = MIN(MIN(lbx, rbx), MIN(llx, lrx)); + _ny = MIN(MIN(lby, rby), MIN(lly, lry)); + } + return self; +} + +- (CALayer *)maskLayer { + if (_maskLayer == nil && self.clipPath != nil) { + SVGABezierPath *bezierPath = [[SVGABezierPath alloc] init]; + [bezierPath setValues:self.clipPath]; + _maskLayer = [bezierPath createLayer]; + } + return _maskLayer; +} + @end diff --git a/Source/pbobjc/Svga.pbobjc.h b/Source/pbobjc/Svga.pbobjc.h new file mode 100644 index 00000000..9c3b8c69 --- /dev/null +++ b/Source/pbobjc/Svga.pbobjc.h @@ -0,0 +1,554 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: svga.proto + +// This CPP symbol can be defined to use imports that match up to the framework +// imports needed when using CocoaPods. +#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) +#define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 +#endif + +#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS +#import +#else +#import "GPBProtocolBuffers.h" +#endif + +#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 +#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. +#endif +#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION +#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. +#endif + +// @@protoc_insertion_point(imports) + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + +CF_EXTERN_C_BEGIN + +@class SVGAProtoAudioEntity; +@class SVGAProtoFrameEntity; +@class SVGAProtoLayout; +@class SVGAProtoMovieParams; +@class SVGAProtoShapeEntity; +@class SVGAProtoShapeEntity_EllipseArgs; +@class SVGAProtoShapeEntity_RectArgs; +@class SVGAProtoShapeEntity_ShapeArgs; +@class SVGAProtoShapeEntity_ShapeStyle; +@class SVGAProtoShapeEntity_ShapeStyle_RGBAColor; +@class SVGAProtoSpriteEntity; +@class SVGAProtoTransform; + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark - Enum SVGAProtoShapeEntity_ShapeType + +typedef GPB_ENUM(SVGAProtoShapeEntity_ShapeType) { + /** + * Value used if any message's field encounters a value that is not defined + * by this enum. The message will also have C functions to get/set the rawValue + * of the field. + **/ + SVGAProtoShapeEntity_ShapeType_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue, + /** 路径 */ + SVGAProtoShapeEntity_ShapeType_Shape = 0, + + /** 矩形 */ + SVGAProtoShapeEntity_ShapeType_Rect = 1, + + /** 圆形 */ + SVGAProtoShapeEntity_ShapeType_Ellipse = 2, + + /** 与前帧一致 */ + SVGAProtoShapeEntity_ShapeType_Keep = 3, +}; + +GPBEnumDescriptor *SVGAProtoShapeEntity_ShapeType_EnumDescriptor(void); + +/** + * Checks to see if the given value is defined by the enum or was not known at + * the time this source was generated. + **/ +BOOL SVGAProtoShapeEntity_ShapeType_IsValidValue(int32_t value); + +#pragma mark - Enum SVGAProtoShapeEntity_ShapeStyle_LineCap + +typedef GPB_ENUM(SVGAProtoShapeEntity_ShapeStyle_LineCap) { + /** + * Value used if any message's field encounters a value that is not defined + * by this enum. The message will also have C functions to get/set the rawValue + * of the field. + **/ + SVGAProtoShapeEntity_ShapeStyle_LineCap_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue, + SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapButt = 0, + SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapRound = 1, + SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapSquare = 2, +}; + +GPBEnumDescriptor *SVGAProtoShapeEntity_ShapeStyle_LineCap_EnumDescriptor(void); + +/** + * Checks to see if the given value is defined by the enum or was not known at + * the time this source was generated. + **/ +BOOL SVGAProtoShapeEntity_ShapeStyle_LineCap_IsValidValue(int32_t value); + +#pragma mark - Enum SVGAProtoShapeEntity_ShapeStyle_LineJoin + +typedef GPB_ENUM(SVGAProtoShapeEntity_ShapeStyle_LineJoin) { + /** + * Value used if any message's field encounters a value that is not defined + * by this enum. The message will also have C functions to get/set the rawValue + * of the field. + **/ + SVGAProtoShapeEntity_ShapeStyle_LineJoin_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue, + SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinMiter = 0, + SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinRound = 1, + SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinBevel = 2, +}; + +GPBEnumDescriptor *SVGAProtoShapeEntity_ShapeStyle_LineJoin_EnumDescriptor(void); + +/** + * Checks to see if the given value is defined by the enum or was not known at + * the time this source was generated. + **/ +BOOL SVGAProtoShapeEntity_ShapeStyle_LineJoin_IsValidValue(int32_t value); + +#pragma mark - SVGAProtoSvgaRoot + +/** + * Exposes the extension registry for this file. + * + * The base class provides: + * @code + * + (GPBExtensionRegistry *)extensionRegistry; + * @endcode + * which is a @c GPBExtensionRegistry that includes all the extensions defined by + * this file and all files that it depends on. + **/ +@interface SVGAProtoSvgaRoot : GPBRootObject +@end + +#pragma mark - SVGAProtoMovieParams + +typedef GPB_ENUM(SVGAProtoMovieParams_FieldNumber) { + SVGAProtoMovieParams_FieldNumber_ViewBoxWidth = 1, + SVGAProtoMovieParams_FieldNumber_ViewBoxHeight = 2, + SVGAProtoMovieParams_FieldNumber_Fps = 3, + SVGAProtoMovieParams_FieldNumber_Frames = 4, +}; + +@interface SVGAProtoMovieParams : GPBMessage + +/** 画布宽 */ +@property(nonatomic, readwrite) float viewBoxWidth; + +/** 画布高 */ +@property(nonatomic, readwrite) float viewBoxHeight; + +/** 动画每秒播放帧数,合法值是 [1, 2, 3, 5, 6, 10, 12, 15, 20, 30, 60] 中的任意一个。 */ +@property(nonatomic, readwrite) int32_t fps; + +/** 动画总帧数 */ +@property(nonatomic, readwrite) int32_t frames; + +@end + +#pragma mark - SVGAProtoSpriteEntity + +typedef GPB_ENUM(SVGAProtoSpriteEntity_FieldNumber) { + SVGAProtoSpriteEntity_FieldNumber_ImageKey = 1, + SVGAProtoSpriteEntity_FieldNumber_FramesArray = 2, + SVGAProtoSpriteEntity_FieldNumber_MatteKey = 3, +}; + +@interface SVGAProtoSpriteEntity : GPBMessage + +/** 元件所对应的位图键名, 如果 imageKey 含有 .vector 后缀,该 sprite 为矢量图层 含有 .matte 后缀,该 sprite 为遮罩图层。 */ +@property(nonatomic, readwrite, copy, null_resettable) NSString *imageKey; + +/** 帧列表 */ +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *framesArray; +/** The number of items in @c framesArray without causing the array to be created. */ +@property(nonatomic, readonly) NSUInteger framesArray_Count; + +/** 被遮罩图层的 matteKey 对应的是其遮罩图层的 imageKey. */ +@property(nonatomic, readwrite, copy, null_resettable) NSString *matteKey; + +@end + +#pragma mark - SVGAProtoAudioEntity + +typedef GPB_ENUM(SVGAProtoAudioEntity_FieldNumber) { + SVGAProtoAudioEntity_FieldNumber_AudioKey = 1, + SVGAProtoAudioEntity_FieldNumber_StartFrame = 2, + SVGAProtoAudioEntity_FieldNumber_EndFrame = 3, + SVGAProtoAudioEntity_FieldNumber_StartTime = 4, + SVGAProtoAudioEntity_FieldNumber_TotalTime = 5, +}; + +@interface SVGAProtoAudioEntity : GPBMessage + +/** 音频文件名 */ +@property(nonatomic, readwrite, copy, null_resettable) NSString *audioKey; + +/** 音频播放起始帧 */ +@property(nonatomic, readwrite) int32_t startFrame; + +/** 音频播放结束帧 */ +@property(nonatomic, readwrite) int32_t endFrame; + +/** 音频播放起始时间(相对音频长度) */ +@property(nonatomic, readwrite) int32_t startTime; + +/** 音频总长度 */ +@property(nonatomic, readwrite) int32_t totalTime; + +@end + +#pragma mark - SVGAProtoLayout + +typedef GPB_ENUM(SVGAProtoLayout_FieldNumber) { + SVGAProtoLayout_FieldNumber_X = 1, + SVGAProtoLayout_FieldNumber_Y = 2, + SVGAProtoLayout_FieldNumber_Width = 3, + SVGAProtoLayout_FieldNumber_Height = 4, +}; + +@interface SVGAProtoLayout : GPBMessage + +@property(nonatomic, readwrite) float x; + +@property(nonatomic, readwrite) float y; + +@property(nonatomic, readwrite) float width; + +@property(nonatomic, readwrite) float height; + +@end + +#pragma mark - SVGAProtoTransform + +typedef GPB_ENUM(SVGAProtoTransform_FieldNumber) { + SVGAProtoTransform_FieldNumber_A = 1, + SVGAProtoTransform_FieldNumber_B = 2, + SVGAProtoTransform_FieldNumber_C = 3, + SVGAProtoTransform_FieldNumber_D = 4, + SVGAProtoTransform_FieldNumber_Tx = 5, + SVGAProtoTransform_FieldNumber_Ty = 6, +}; + +@interface SVGAProtoTransform : GPBMessage + +@property(nonatomic, readwrite) float a; + +@property(nonatomic, readwrite) float b; + +@property(nonatomic, readwrite) float c; + +@property(nonatomic, readwrite) float d; + +@property(nonatomic, readwrite) float tx; + +@property(nonatomic, readwrite) float ty; + +@end + +#pragma mark - SVGAProtoShapeEntity + +typedef GPB_ENUM(SVGAProtoShapeEntity_FieldNumber) { + SVGAProtoShapeEntity_FieldNumber_Type = 1, + SVGAProtoShapeEntity_FieldNumber_Shape = 2, + SVGAProtoShapeEntity_FieldNumber_Rect = 3, + SVGAProtoShapeEntity_FieldNumber_Ellipse = 4, + SVGAProtoShapeEntity_FieldNumber_Styles = 10, + SVGAProtoShapeEntity_FieldNumber_Transform = 11, +}; + +typedef GPB_ENUM(SVGAProtoShapeEntity_Args_OneOfCase) { + SVGAProtoShapeEntity_Args_OneOfCase_GPBUnsetOneOfCase = 0, + SVGAProtoShapeEntity_Args_OneOfCase_Shape = 2, + SVGAProtoShapeEntity_Args_OneOfCase_Rect = 3, + SVGAProtoShapeEntity_Args_OneOfCase_Ellipse = 4, +}; + +@interface SVGAProtoShapeEntity : GPBMessage + +/** 矢量类型 */ +@property(nonatomic, readwrite) SVGAProtoShapeEntity_ShapeType type; + +@property(nonatomic, readonly) SVGAProtoShapeEntity_Args_OneOfCase argsOneOfCase; + +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoShapeEntity_ShapeArgs *shape; + +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoShapeEntity_RectArgs *rect; + +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoShapeEntity_EllipseArgs *ellipse; + +/** 渲染参数 */ +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoShapeEntity_ShapeStyle *styles; +/** Test to see if @c styles has been set. */ +@property(nonatomic, readwrite) BOOL hasStyles; + +/** 矢量图层 2D 变换矩阵 */ +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoTransform *transform; +/** Test to see if @c transform has been set. */ +@property(nonatomic, readwrite) BOOL hasTransform; + +@end + +/** + * Fetches the raw value of a @c SVGAProtoShapeEntity's @c type property, even + * if the value was not defined by the enum at the time the code was generated. + **/ +int32_t SVGAProtoShapeEntity_Type_RawValue(SVGAProtoShapeEntity *message); +/** + * Sets the raw value of an @c SVGAProtoShapeEntity's @c type property, allowing + * it to be set to a value that was not defined by the enum at the time the code + * was generated. + **/ +void SetSVGAProtoShapeEntity_Type_RawValue(SVGAProtoShapeEntity *message, int32_t value); + +/** + * Clears whatever value was set for the oneof 'args'. + **/ +void SVGAProtoShapeEntity_ClearArgsOneOfCase(SVGAProtoShapeEntity *message); + +#pragma mark - SVGAProtoShapeEntity_ShapeArgs + +typedef GPB_ENUM(SVGAProtoShapeEntity_ShapeArgs_FieldNumber) { + SVGAProtoShapeEntity_ShapeArgs_FieldNumber_D = 1, +}; + +@interface SVGAProtoShapeEntity_ShapeArgs : GPBMessage + +/** SVG 路径 */ +@property(nonatomic, readwrite, copy, null_resettable) NSString *d; + +@end + +#pragma mark - SVGAProtoShapeEntity_RectArgs + +typedef GPB_ENUM(SVGAProtoShapeEntity_RectArgs_FieldNumber) { + SVGAProtoShapeEntity_RectArgs_FieldNumber_X = 1, + SVGAProtoShapeEntity_RectArgs_FieldNumber_Y = 2, + SVGAProtoShapeEntity_RectArgs_FieldNumber_Width = 3, + SVGAProtoShapeEntity_RectArgs_FieldNumber_Height = 4, + SVGAProtoShapeEntity_RectArgs_FieldNumber_CornerRadius = 5, +}; + +@interface SVGAProtoShapeEntity_RectArgs : GPBMessage + +@property(nonatomic, readwrite) float x; + +@property(nonatomic, readwrite) float y; + +@property(nonatomic, readwrite) float width; + +@property(nonatomic, readwrite) float height; + +/** 圆角半径 */ +@property(nonatomic, readwrite) float cornerRadius; + +@end + +#pragma mark - SVGAProtoShapeEntity_EllipseArgs + +typedef GPB_ENUM(SVGAProtoShapeEntity_EllipseArgs_FieldNumber) { + SVGAProtoShapeEntity_EllipseArgs_FieldNumber_X = 1, + SVGAProtoShapeEntity_EllipseArgs_FieldNumber_Y = 2, + SVGAProtoShapeEntity_EllipseArgs_FieldNumber_RadiusX = 3, + SVGAProtoShapeEntity_EllipseArgs_FieldNumber_RadiusY = 4, +}; + +@interface SVGAProtoShapeEntity_EllipseArgs : GPBMessage + +/** 圆中心点 X */ +@property(nonatomic, readwrite) float x; + +/** 圆中心点 Y */ +@property(nonatomic, readwrite) float y; + +/** 横向半径 */ +@property(nonatomic, readwrite) float radiusX; + +/** 纵向半径 */ +@property(nonatomic, readwrite) float radiusY; + +@end + +#pragma mark - SVGAProtoShapeEntity_ShapeStyle + +typedef GPB_ENUM(SVGAProtoShapeEntity_ShapeStyle_FieldNumber) { + SVGAProtoShapeEntity_ShapeStyle_FieldNumber_Fill = 1, + SVGAProtoShapeEntity_ShapeStyle_FieldNumber_Stroke = 2, + SVGAProtoShapeEntity_ShapeStyle_FieldNumber_StrokeWidth = 3, + SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineCap = 4, + SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineJoin = 5, + SVGAProtoShapeEntity_ShapeStyle_FieldNumber_MiterLimit = 6, + SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineDashI = 7, + SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineDashIi = 8, + SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineDashIii = 9, +}; + +@interface SVGAProtoShapeEntity_ShapeStyle : GPBMessage + +/** 填充色 */ +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoShapeEntity_ShapeStyle_RGBAColor *fill; +/** Test to see if @c fill has been set. */ +@property(nonatomic, readwrite) BOOL hasFill; + +/** 描边色 */ +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoShapeEntity_ShapeStyle_RGBAColor *stroke; +/** Test to see if @c stroke has been set. */ +@property(nonatomic, readwrite) BOOL hasStroke; + +/** 描边宽 */ +@property(nonatomic, readwrite) float strokeWidth; + +/** 线段端点样式 */ +@property(nonatomic, readwrite) SVGAProtoShapeEntity_ShapeStyle_LineCap lineCap; + +/** 线段连接样式 */ +@property(nonatomic, readwrite) SVGAProtoShapeEntity_ShapeStyle_LineJoin lineJoin; + +/** 尖角限制 */ +@property(nonatomic, readwrite) float miterLimit; + +/** 虚线参数 Dash */ +@property(nonatomic, readwrite) float lineDashI; + +/** 虚线参数 Gap */ +@property(nonatomic, readwrite) float lineDashIi; + +/** 虚线参数 Offset */ +@property(nonatomic, readwrite) float lineDashIii; + +@end + +/** + * Fetches the raw value of a @c SVGAProtoShapeEntity_ShapeStyle's @c lineCap property, even + * if the value was not defined by the enum at the time the code was generated. + **/ +int32_t SVGAProtoShapeEntity_ShapeStyle_LineCap_RawValue(SVGAProtoShapeEntity_ShapeStyle *message); +/** + * Sets the raw value of an @c SVGAProtoShapeEntity_ShapeStyle's @c lineCap property, allowing + * it to be set to a value that was not defined by the enum at the time the code + * was generated. + **/ +void SetSVGAProtoShapeEntity_ShapeStyle_LineCap_RawValue(SVGAProtoShapeEntity_ShapeStyle *message, int32_t value); + +/** + * Fetches the raw value of a @c SVGAProtoShapeEntity_ShapeStyle's @c lineJoin property, even + * if the value was not defined by the enum at the time the code was generated. + **/ +int32_t SVGAProtoShapeEntity_ShapeStyle_LineJoin_RawValue(SVGAProtoShapeEntity_ShapeStyle *message); +/** + * Sets the raw value of an @c SVGAProtoShapeEntity_ShapeStyle's @c lineJoin property, allowing + * it to be set to a value that was not defined by the enum at the time the code + * was generated. + **/ +void SetSVGAProtoShapeEntity_ShapeStyle_LineJoin_RawValue(SVGAProtoShapeEntity_ShapeStyle *message, int32_t value); + +#pragma mark - SVGAProtoShapeEntity_ShapeStyle_RGBAColor + +typedef GPB_ENUM(SVGAProtoShapeEntity_ShapeStyle_RGBAColor_FieldNumber) { + SVGAProtoShapeEntity_ShapeStyle_RGBAColor_FieldNumber_R = 1, + SVGAProtoShapeEntity_ShapeStyle_RGBAColor_FieldNumber_G = 2, + SVGAProtoShapeEntity_ShapeStyle_RGBAColor_FieldNumber_B = 3, + SVGAProtoShapeEntity_ShapeStyle_RGBAColor_FieldNumber_A = 4, +}; + +@interface SVGAProtoShapeEntity_ShapeStyle_RGBAColor : GPBMessage + +@property(nonatomic, readwrite) float r; + +@property(nonatomic, readwrite) float g; + +@property(nonatomic, readwrite) float b; + +@property(nonatomic, readwrite) float a; + +@end + +#pragma mark - SVGAProtoFrameEntity + +typedef GPB_ENUM(SVGAProtoFrameEntity_FieldNumber) { + SVGAProtoFrameEntity_FieldNumber_Alpha = 1, + SVGAProtoFrameEntity_FieldNumber_Layout = 2, + SVGAProtoFrameEntity_FieldNumber_Transform = 3, + SVGAProtoFrameEntity_FieldNumber_ClipPath = 4, + SVGAProtoFrameEntity_FieldNumber_ShapesArray = 5, +}; + +@interface SVGAProtoFrameEntity : GPBMessage + +/** 透明度 */ +@property(nonatomic, readwrite) float alpha; + +/** 初始约束大小 */ +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoLayout *layout; +/** Test to see if @c layout has been set. */ +@property(nonatomic, readwrite) BOOL hasLayout; + +/** 2D 变换矩阵 */ +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoTransform *transform; +/** Test to see if @c transform has been set. */ +@property(nonatomic, readwrite) BOOL hasTransform; + +/** 遮罩路径,使用 SVG 标准 Path 绘制图案进行 Mask 遮罩。 */ +@property(nonatomic, readwrite, copy, null_resettable) NSString *clipPath; + +/** 矢量元素列表 */ +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *shapesArray; +/** The number of items in @c shapesArray without causing the array to be created. */ +@property(nonatomic, readonly) NSUInteger shapesArray_Count; + +@end + +#pragma mark - SVGAProtoMovieEntity + +typedef GPB_ENUM(SVGAProtoMovieEntity_FieldNumber) { + SVGAProtoMovieEntity_FieldNumber_Version = 1, + SVGAProtoMovieEntity_FieldNumber_Params = 2, + SVGAProtoMovieEntity_FieldNumber_Images = 3, + SVGAProtoMovieEntity_FieldNumber_SpritesArray = 4, + SVGAProtoMovieEntity_FieldNumber_AudiosArray = 5, +}; + +@interface SVGAProtoMovieEntity : GPBMessage + +/** SVGA 格式版本号 */ +@property(nonatomic, readwrite, copy, null_resettable) NSString *version; + +/** 动画参数 */ +@property(nonatomic, readwrite, strong, null_resettable) SVGAProtoMovieParams *params; +/** Test to see if @c params has been set. */ +@property(nonatomic, readwrite) BOOL hasParams; + +/** Key 是位图键名,Value 是位图文件名或二进制 PNG 数据。 */ +@property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *images; +/** The number of items in @c images without causing the array to be created. */ +@property(nonatomic, readonly) NSUInteger images_Count; + +/** 元素列表 */ +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *spritesArray; +/** The number of items in @c spritesArray without causing the array to be created. */ +@property(nonatomic, readonly) NSUInteger spritesArray_Count; + +/** 音频列表 */ +@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *audiosArray; +/** The number of items in @c audiosArray without causing the array to be created. */ +@property(nonatomic, readonly) NSUInteger audiosArray_Count; + +@end + +NS_ASSUME_NONNULL_END + +CF_EXTERN_C_END + +#pragma clang diagnostic pop + +// @@protoc_insertion_point(global_scope) diff --git a/Source/pbobjc/Svga.pbobjc.m b/Source/pbobjc/Svga.pbobjc.m new file mode 100644 index 00000000..3fd8e4d7 --- /dev/null +++ b/Source/pbobjc/Svga.pbobjc.m @@ -0,0 +1,1340 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: svga.proto + +// This CPP symbol can be defined to use imports that match up to the framework +// imports needed when using CocoaPods. +#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) +#define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 +#endif + +#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS +#import +#else +#import "GPBProtocolBuffers_RuntimeSupport.h" +#endif + +#import "Svga.pbobjc.h" +// @@protoc_insertion_point(imports) + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#pragma clang diagnostic ignored "-Wdirect-ivar-access" + +#pragma mark - SVGAProtoSvgaRoot + +@implementation SVGAProtoSvgaRoot + +// No extensions in the file and no imports, so no need to generate +// +extensionRegistry. + +@end + +#pragma mark - SVGAProtoSvgaRoot_FileDescriptor + +static GPBFileDescriptor *SVGAProtoSvgaRoot_FileDescriptor(void) { + // This is called by +initialize so there is no need to worry + // about thread safety of the singleton. + static GPBFileDescriptor *descriptor = NULL; + if (!descriptor) { + GPB_DEBUG_CHECK_RUNTIME_VERSIONS(); + descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"com.opensource.svga" + objcPrefix:@"SVGAProto" + syntax:GPBFileSyntaxProto3]; + } + return descriptor; +} + +#pragma mark - SVGAProtoMovieParams + +@implementation SVGAProtoMovieParams + +@dynamic viewBoxWidth; +@dynamic viewBoxHeight; +@dynamic fps; +@dynamic frames; + +typedef struct SVGAProtoMovieParams__storage_ { + uint32_t _has_storage_[1]; + float viewBoxWidth; + float viewBoxHeight; + int32_t fps; + int32_t frames; +} SVGAProtoMovieParams__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "viewBoxWidth", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoMovieParams_FieldNumber_ViewBoxWidth, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoMovieParams__storage_, viewBoxWidth), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + { + .name = "viewBoxHeight", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoMovieParams_FieldNumber_ViewBoxHeight, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoMovieParams__storage_, viewBoxHeight), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + { + .name = "fps", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoMovieParams_FieldNumber_Fps, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoMovieParams__storage_, fps), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeInt32, + }, + { + .name = "frames", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoMovieParams_FieldNumber_Frames, + .hasIndex = 3, + .offset = (uint32_t)offsetof(SVGAProtoMovieParams__storage_, frames), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeInt32, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoMovieParams class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoMovieParams__storage_) + flags:GPBDescriptorInitializationFlag_None]; +#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + static const char *extraTextFormatInfo = + "\002\001\014\000\002\r\000"; + [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; +#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoSpriteEntity + +@implementation SVGAProtoSpriteEntity + +@dynamic imageKey; +@dynamic framesArray, framesArray_Count; +@dynamic matteKey; + +typedef struct SVGAProtoSpriteEntity__storage_ { + uint32_t _has_storage_[1]; + NSString *imageKey; + NSMutableArray *framesArray; + NSString *matteKey; +} SVGAProtoSpriteEntity__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "imageKey", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoSpriteEntity_FieldNumber_ImageKey, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoSpriteEntity__storage_, imageKey), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeString, + }, + { + .name = "framesArray", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoFrameEntity), + .number = SVGAProtoSpriteEntity_FieldNumber_FramesArray, + .hasIndex = GPBNoHasBit, + .offset = (uint32_t)offsetof(SVGAProtoSpriteEntity__storage_, framesArray), + .flags = GPBFieldRepeated, + .dataType = GPBDataTypeMessage, + }, + { + .name = "matteKey", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoSpriteEntity_FieldNumber_MatteKey, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoSpriteEntity__storage_, matteKey), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeString, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoSpriteEntity class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoSpriteEntity__storage_) + flags:GPBDescriptorInitializationFlag_None]; +#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + static const char *extraTextFormatInfo = + "\002\001\010\000\003\010\000"; + [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; +#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoAudioEntity + +@implementation SVGAProtoAudioEntity + +@dynamic audioKey; +@dynamic startFrame; +@dynamic endFrame; +@dynamic startTime; +@dynamic totalTime; + +typedef struct SVGAProtoAudioEntity__storage_ { + uint32_t _has_storage_[1]; + int32_t startFrame; + int32_t endFrame; + int32_t startTime; + int32_t totalTime; + NSString *audioKey; +} SVGAProtoAudioEntity__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "audioKey", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoAudioEntity_FieldNumber_AudioKey, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoAudioEntity__storage_, audioKey), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeString, + }, + { + .name = "startFrame", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoAudioEntity_FieldNumber_StartFrame, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoAudioEntity__storage_, startFrame), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeInt32, + }, + { + .name = "endFrame", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoAudioEntity_FieldNumber_EndFrame, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoAudioEntity__storage_, endFrame), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeInt32, + }, + { + .name = "startTime", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoAudioEntity_FieldNumber_StartTime, + .hasIndex = 3, + .offset = (uint32_t)offsetof(SVGAProtoAudioEntity__storage_, startTime), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeInt32, + }, + { + .name = "totalTime", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoAudioEntity_FieldNumber_TotalTime, + .hasIndex = 4, + .offset = (uint32_t)offsetof(SVGAProtoAudioEntity__storage_, totalTime), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeInt32, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoAudioEntity class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoAudioEntity__storage_) + flags:GPBDescriptorInitializationFlag_None]; +#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + static const char *extraTextFormatInfo = + "\005\001\010\000\002\n\000\003\010\000\004\t\000\005\t\000"; + [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; +#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoLayout + +@implementation SVGAProtoLayout + +@dynamic x; +@dynamic y; +@dynamic width; +@dynamic height; + +typedef struct SVGAProtoLayout__storage_ { + uint32_t _has_storage_[1]; + float x; + float y; + float width; + float height; +} SVGAProtoLayout__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "x", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoLayout_FieldNumber_X, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoLayout__storage_, x), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "y", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoLayout_FieldNumber_Y, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoLayout__storage_, y), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "width", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoLayout_FieldNumber_Width, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoLayout__storage_, width), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "height", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoLayout_FieldNumber_Height, + .hasIndex = 3, + .offset = (uint32_t)offsetof(SVGAProtoLayout__storage_, height), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoLayout class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoLayout__storage_) + flags:GPBDescriptorInitializationFlag_None]; + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoTransform + +@implementation SVGAProtoTransform + +@dynamic a; +@dynamic b; +@dynamic c; +@dynamic d; +@dynamic tx; +@dynamic ty; + +typedef struct SVGAProtoTransform__storage_ { + uint32_t _has_storage_[1]; + float a; + float b; + float c; + float d; + float tx; + float ty; +} SVGAProtoTransform__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "a", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoTransform_FieldNumber_A, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoTransform__storage_, a), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "b", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoTransform_FieldNumber_B, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoTransform__storage_, b), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "c", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoTransform_FieldNumber_C, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoTransform__storage_, c), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "d", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoTransform_FieldNumber_D, + .hasIndex = 3, + .offset = (uint32_t)offsetof(SVGAProtoTransform__storage_, d), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "tx", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoTransform_FieldNumber_Tx, + .hasIndex = 4, + .offset = (uint32_t)offsetof(SVGAProtoTransform__storage_, tx), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "ty", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoTransform_FieldNumber_Ty, + .hasIndex = 5, + .offset = (uint32_t)offsetof(SVGAProtoTransform__storage_, ty), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoTransform class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoTransform__storage_) + flags:GPBDescriptorInitializationFlag_None]; + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoShapeEntity + +@implementation SVGAProtoShapeEntity + +@dynamic argsOneOfCase; +@dynamic type; +@dynamic shape; +@dynamic rect; +@dynamic ellipse; +@dynamic hasStyles, styles; +@dynamic hasTransform, transform; + +typedef struct SVGAProtoShapeEntity__storage_ { + uint32_t _has_storage_[2]; + SVGAProtoShapeEntity_ShapeType type; + SVGAProtoShapeEntity_ShapeArgs *shape; + SVGAProtoShapeEntity_RectArgs *rect; + SVGAProtoShapeEntity_EllipseArgs *ellipse; + SVGAProtoShapeEntity_ShapeStyle *styles; + SVGAProtoTransform *transform; +} SVGAProtoShapeEntity__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "type", + .dataTypeSpecific.enumDescFunc = SVGAProtoShapeEntity_ShapeType_EnumDescriptor, + .number = SVGAProtoShapeEntity_FieldNumber_Type, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity__storage_, type), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor), + .dataType = GPBDataTypeEnum, + }, + { + .name = "shape", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoShapeEntity_ShapeArgs), + .number = SVGAProtoShapeEntity_FieldNumber_Shape, + .hasIndex = -1, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity__storage_, shape), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + { + .name = "rect", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoShapeEntity_RectArgs), + .number = SVGAProtoShapeEntity_FieldNumber_Rect, + .hasIndex = -1, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity__storage_, rect), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + { + .name = "ellipse", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoShapeEntity_EllipseArgs), + .number = SVGAProtoShapeEntity_FieldNumber_Ellipse, + .hasIndex = -1, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity__storage_, ellipse), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + { + .name = "styles", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoShapeEntity_ShapeStyle), + .number = SVGAProtoShapeEntity_FieldNumber_Styles, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity__storage_, styles), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + { + .name = "transform", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoTransform), + .number = SVGAProtoShapeEntity_FieldNumber_Transform, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity__storage_, transform), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoShapeEntity class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoShapeEntity__storage_) + flags:GPBDescriptorInitializationFlag_None]; + static const char *oneofs[] = { + "args", + }; + [localDescriptor setupOneofs:oneofs + count:(uint32_t)(sizeof(oneofs) / sizeof(char*)) + firstHasIndex:-1]; + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +int32_t SVGAProtoShapeEntity_Type_RawValue(SVGAProtoShapeEntity *message) { + GPBDescriptor *descriptor = [SVGAProtoShapeEntity descriptor]; + GPBFieldDescriptor *field = [descriptor fieldWithNumber:SVGAProtoShapeEntity_FieldNumber_Type]; + return GPBGetMessageInt32Field(message, field); +} + +void SetSVGAProtoShapeEntity_Type_RawValue(SVGAProtoShapeEntity *message, int32_t value) { + GPBDescriptor *descriptor = [SVGAProtoShapeEntity descriptor]; + GPBFieldDescriptor *field = [descriptor fieldWithNumber:SVGAProtoShapeEntity_FieldNumber_Type]; + GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax); +} + +void SVGAProtoShapeEntity_ClearArgsOneOfCase(SVGAProtoShapeEntity *message) { + GPBDescriptor *descriptor = [message descriptor]; + GPBOneofDescriptor *oneof = [descriptor.oneofs objectAtIndex:0]; + GPBMaybeClearOneof(message, oneof, -1, 0); +} +#pragma mark - Enum SVGAProtoShapeEntity_ShapeType + +GPBEnumDescriptor *SVGAProtoShapeEntity_ShapeType_EnumDescriptor(void) { + static GPBEnumDescriptor *descriptor = NULL; + if (!descriptor) { + static const char *valueNames = + "Shape\000Rect\000Ellipse\000Keep\000"; + static const int32_t values[] = { + SVGAProtoShapeEntity_ShapeType_Shape, + SVGAProtoShapeEntity_ShapeType_Rect, + SVGAProtoShapeEntity_ShapeType_Ellipse, + SVGAProtoShapeEntity_ShapeType_Keep, + }; + GPBEnumDescriptor *worker = + [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(SVGAProtoShapeEntity_ShapeType) + valueNames:valueNames + values:values + count:(uint32_t)(sizeof(values) / sizeof(int32_t)) + enumVerifier:SVGAProtoShapeEntity_ShapeType_IsValidValue]; + if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { + [worker release]; + } + } + return descriptor; +} + +BOOL SVGAProtoShapeEntity_ShapeType_IsValidValue(int32_t value__) { + switch (value__) { + case SVGAProtoShapeEntity_ShapeType_Shape: + case SVGAProtoShapeEntity_ShapeType_Rect: + case SVGAProtoShapeEntity_ShapeType_Ellipse: + case SVGAProtoShapeEntity_ShapeType_Keep: + return YES; + default: + return NO; + } +} + +#pragma mark - SVGAProtoShapeEntity_ShapeArgs + +@implementation SVGAProtoShapeEntity_ShapeArgs + +@dynamic d; + +typedef struct SVGAProtoShapeEntity_ShapeArgs__storage_ { + uint32_t _has_storage_[1]; + NSString *d; +} SVGAProtoShapeEntity_ShapeArgs__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "d", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeArgs_FieldNumber_D, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeArgs__storage_, d), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeString, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoShapeEntity_ShapeArgs class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoShapeEntity_ShapeArgs__storage_) + flags:GPBDescriptorInitializationFlag_None]; + [localDescriptor setupContainingMessageClassName:GPBStringifySymbol(SVGAProtoShapeEntity)]; + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoShapeEntity_RectArgs + +@implementation SVGAProtoShapeEntity_RectArgs + +@dynamic x; +@dynamic y; +@dynamic width; +@dynamic height; +@dynamic cornerRadius; + +typedef struct SVGAProtoShapeEntity_RectArgs__storage_ { + uint32_t _has_storage_[1]; + float x; + float y; + float width; + float height; + float cornerRadius; +} SVGAProtoShapeEntity_RectArgs__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "x", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_RectArgs_FieldNumber_X, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_RectArgs__storage_, x), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "y", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_RectArgs_FieldNumber_Y, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_RectArgs__storage_, y), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "width", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_RectArgs_FieldNumber_Width, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_RectArgs__storage_, width), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "height", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_RectArgs_FieldNumber_Height, + .hasIndex = 3, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_RectArgs__storage_, height), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "cornerRadius", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_RectArgs_FieldNumber_CornerRadius, + .hasIndex = 4, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_RectArgs__storage_, cornerRadius), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoShapeEntity_RectArgs class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoShapeEntity_RectArgs__storage_) + flags:GPBDescriptorInitializationFlag_None]; +#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + static const char *extraTextFormatInfo = + "\001\005\014\000"; + [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; +#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + [localDescriptor setupContainingMessageClassName:GPBStringifySymbol(SVGAProtoShapeEntity)]; + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoShapeEntity_EllipseArgs + +@implementation SVGAProtoShapeEntity_EllipseArgs + +@dynamic x; +@dynamic y; +@dynamic radiusX; +@dynamic radiusY; + +typedef struct SVGAProtoShapeEntity_EllipseArgs__storage_ { + uint32_t _has_storage_[1]; + float x; + float y; + float radiusX; + float radiusY; +} SVGAProtoShapeEntity_EllipseArgs__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "x", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_EllipseArgs_FieldNumber_X, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_EllipseArgs__storage_, x), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "y", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_EllipseArgs_FieldNumber_Y, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_EllipseArgs__storage_, y), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "radiusX", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_EllipseArgs_FieldNumber_RadiusX, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_EllipseArgs__storage_, radiusX), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + { + .name = "radiusY", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_EllipseArgs_FieldNumber_RadiusY, + .hasIndex = 3, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_EllipseArgs__storage_, radiusY), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoShapeEntity_EllipseArgs class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoShapeEntity_EllipseArgs__storage_) + flags:GPBDescriptorInitializationFlag_None]; +#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + static const char *extraTextFormatInfo = + "\002\003\007\000\004\007\000"; + [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; +#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + [localDescriptor setupContainingMessageClassName:GPBStringifySymbol(SVGAProtoShapeEntity)]; + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoShapeEntity_ShapeStyle + +@implementation SVGAProtoShapeEntity_ShapeStyle + +@dynamic hasFill, fill; +@dynamic hasStroke, stroke; +@dynamic strokeWidth; +@dynamic lineCap; +@dynamic lineJoin; +@dynamic miterLimit; +@dynamic lineDashI; +@dynamic lineDashIi; +@dynamic lineDashIii; + +typedef struct SVGAProtoShapeEntity_ShapeStyle__storage_ { + uint32_t _has_storage_[1]; + float strokeWidth; + SVGAProtoShapeEntity_ShapeStyle_LineCap lineCap; + SVGAProtoShapeEntity_ShapeStyle_LineJoin lineJoin; + float miterLimit; + float lineDashI; + float lineDashIi; + float lineDashIii; + SVGAProtoShapeEntity_ShapeStyle_RGBAColor *fill; + SVGAProtoShapeEntity_ShapeStyle_RGBAColor *stroke; +} SVGAProtoShapeEntity_ShapeStyle__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "fill", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoShapeEntity_ShapeStyle_RGBAColor), + .number = SVGAProtoShapeEntity_ShapeStyle_FieldNumber_Fill, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle__storage_, fill), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + { + .name = "stroke", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoShapeEntity_ShapeStyle_RGBAColor), + .number = SVGAProtoShapeEntity_ShapeStyle_FieldNumber_Stroke, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle__storage_, stroke), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + { + .name = "strokeWidth", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeStyle_FieldNumber_StrokeWidth, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle__storage_, strokeWidth), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + { + .name = "lineCap", + .dataTypeSpecific.enumDescFunc = SVGAProtoShapeEntity_ShapeStyle_LineCap_EnumDescriptor, + .number = SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineCap, + .hasIndex = 3, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle__storage_, lineCap), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom | GPBFieldHasEnumDescriptor), + .dataType = GPBDataTypeEnum, + }, + { + .name = "lineJoin", + .dataTypeSpecific.enumDescFunc = SVGAProtoShapeEntity_ShapeStyle_LineJoin_EnumDescriptor, + .number = SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineJoin, + .hasIndex = 4, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle__storage_, lineJoin), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom | GPBFieldHasEnumDescriptor), + .dataType = GPBDataTypeEnum, + }, + { + .name = "miterLimit", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeStyle_FieldNumber_MiterLimit, + .hasIndex = 5, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle__storage_, miterLimit), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + { + .name = "lineDashI", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineDashI, + .hasIndex = 6, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle__storage_, lineDashI), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + { + .name = "lineDashIi", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineDashIi, + .hasIndex = 7, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle__storage_, lineDashIi), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + { + .name = "lineDashIii", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineDashIii, + .hasIndex = 8, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle__storage_, lineDashIii), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeFloat, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoShapeEntity_ShapeStyle class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoShapeEntity_ShapeStyle__storage_) + flags:GPBDescriptorInitializationFlag_None]; +#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + static const char *extraTextFormatInfo = + "\007\003\013\000\004\007\000\005\010\000\006\n\000\007\t\000\010\tA\000\t\tb\000"; + [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; +#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + [localDescriptor setupContainingMessageClassName:GPBStringifySymbol(SVGAProtoShapeEntity)]; + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +int32_t SVGAProtoShapeEntity_ShapeStyle_LineCap_RawValue(SVGAProtoShapeEntity_ShapeStyle *message) { + GPBDescriptor *descriptor = [SVGAProtoShapeEntity_ShapeStyle descriptor]; + GPBFieldDescriptor *field = [descriptor fieldWithNumber:SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineCap]; + return GPBGetMessageInt32Field(message, field); +} + +void SetSVGAProtoShapeEntity_ShapeStyle_LineCap_RawValue(SVGAProtoShapeEntity_ShapeStyle *message, int32_t value) { + GPBDescriptor *descriptor = [SVGAProtoShapeEntity_ShapeStyle descriptor]; + GPBFieldDescriptor *field = [descriptor fieldWithNumber:SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineCap]; + GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax); +} + +int32_t SVGAProtoShapeEntity_ShapeStyle_LineJoin_RawValue(SVGAProtoShapeEntity_ShapeStyle *message) { + GPBDescriptor *descriptor = [SVGAProtoShapeEntity_ShapeStyle descriptor]; + GPBFieldDescriptor *field = [descriptor fieldWithNumber:SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineJoin]; + return GPBGetMessageInt32Field(message, field); +} + +void SetSVGAProtoShapeEntity_ShapeStyle_LineJoin_RawValue(SVGAProtoShapeEntity_ShapeStyle *message, int32_t value) { + GPBDescriptor *descriptor = [SVGAProtoShapeEntity_ShapeStyle descriptor]; + GPBFieldDescriptor *field = [descriptor fieldWithNumber:SVGAProtoShapeEntity_ShapeStyle_FieldNumber_LineJoin]; + GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax); +} + +#pragma mark - Enum SVGAProtoShapeEntity_ShapeStyle_LineCap + +GPBEnumDescriptor *SVGAProtoShapeEntity_ShapeStyle_LineCap_EnumDescriptor(void) { + static GPBEnumDescriptor *descriptor = NULL; + if (!descriptor) { + static const char *valueNames = + "LineCapButt\000LineCapRound\000LineCapSquare\000"; + static const int32_t values[] = { + SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapButt, + SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapRound, + SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapSquare, + }; + static const char *extraTextFormatInfo = "\003\000\007\344\000\001\007\345\000\002\007\346\000"; + GPBEnumDescriptor *worker = + [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(SVGAProtoShapeEntity_ShapeStyle_LineCap) + valueNames:valueNames + values:values + count:(uint32_t)(sizeof(values) / sizeof(int32_t)) + enumVerifier:SVGAProtoShapeEntity_ShapeStyle_LineCap_IsValidValue + extraTextFormatInfo:extraTextFormatInfo]; + if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { + [worker release]; + } + } + return descriptor; +} + +BOOL SVGAProtoShapeEntity_ShapeStyle_LineCap_IsValidValue(int32_t value__) { + switch (value__) { + case SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapButt: + case SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapRound: + case SVGAProtoShapeEntity_ShapeStyle_LineCap_LineCapSquare: + return YES; + default: + return NO; + } +} + +#pragma mark - Enum SVGAProtoShapeEntity_ShapeStyle_LineJoin + +GPBEnumDescriptor *SVGAProtoShapeEntity_ShapeStyle_LineJoin_EnumDescriptor(void) { + static GPBEnumDescriptor *descriptor = NULL; + if (!descriptor) { + static const char *valueNames = + "LineJoinMiter\000LineJoinRound\000LineJoinBeve" + "l\000"; + static const int32_t values[] = { + SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinMiter, + SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinRound, + SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinBevel, + }; + static const char *extraTextFormatInfo = "\003\000\010\345\000\001\010\345\000\002\010\345\000"; + GPBEnumDescriptor *worker = + [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(SVGAProtoShapeEntity_ShapeStyle_LineJoin) + valueNames:valueNames + values:values + count:(uint32_t)(sizeof(values) / sizeof(int32_t)) + enumVerifier:SVGAProtoShapeEntity_ShapeStyle_LineJoin_IsValidValue + extraTextFormatInfo:extraTextFormatInfo]; + if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { + [worker release]; + } + } + return descriptor; +} + +BOOL SVGAProtoShapeEntity_ShapeStyle_LineJoin_IsValidValue(int32_t value__) { + switch (value__) { + case SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinMiter: + case SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinRound: + case SVGAProtoShapeEntity_ShapeStyle_LineJoin_LineJoinBevel: + return YES; + default: + return NO; + } +} + +#pragma mark - SVGAProtoShapeEntity_ShapeStyle_RGBAColor + +@implementation SVGAProtoShapeEntity_ShapeStyle_RGBAColor + +@dynamic r; +@dynamic g; +@dynamic b; +@dynamic a; + +typedef struct SVGAProtoShapeEntity_ShapeStyle_RGBAColor__storage_ { + uint32_t _has_storage_[1]; + float r; + float g; + float b; + float a; +} SVGAProtoShapeEntity_ShapeStyle_RGBAColor__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "r", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeStyle_RGBAColor_FieldNumber_R, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle_RGBAColor__storage_, r), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "g", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeStyle_RGBAColor_FieldNumber_G, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle_RGBAColor__storage_, g), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "b", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeStyle_RGBAColor_FieldNumber_B, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle_RGBAColor__storage_, b), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "a", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoShapeEntity_ShapeStyle_RGBAColor_FieldNumber_A, + .hasIndex = 3, + .offset = (uint32_t)offsetof(SVGAProtoShapeEntity_ShapeStyle_RGBAColor__storage_, a), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoShapeEntity_ShapeStyle_RGBAColor class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoShapeEntity_ShapeStyle_RGBAColor__storage_) + flags:GPBDescriptorInitializationFlag_None]; + [localDescriptor setupContainingMessageClassName:GPBStringifySymbol(SVGAProtoShapeEntity_ShapeStyle)]; + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoFrameEntity + +@implementation SVGAProtoFrameEntity + +@dynamic alpha; +@dynamic hasLayout, layout; +@dynamic hasTransform, transform; +@dynamic clipPath; +@dynamic shapesArray, shapesArray_Count; + +typedef struct SVGAProtoFrameEntity__storage_ { + uint32_t _has_storage_[1]; + float alpha; + SVGAProtoLayout *layout; + SVGAProtoTransform *transform; + NSString *clipPath; + NSMutableArray *shapesArray; +} SVGAProtoFrameEntity__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "alpha", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoFrameEntity_FieldNumber_Alpha, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoFrameEntity__storage_, alpha), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeFloat, + }, + { + .name = "layout", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoLayout), + .number = SVGAProtoFrameEntity_FieldNumber_Layout, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoFrameEntity__storage_, layout), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + { + .name = "transform", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoTransform), + .number = SVGAProtoFrameEntity_FieldNumber_Transform, + .hasIndex = 2, + .offset = (uint32_t)offsetof(SVGAProtoFrameEntity__storage_, transform), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + { + .name = "clipPath", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoFrameEntity_FieldNumber_ClipPath, + .hasIndex = 3, + .offset = (uint32_t)offsetof(SVGAProtoFrameEntity__storage_, clipPath), + .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom), + .dataType = GPBDataTypeString, + }, + { + .name = "shapesArray", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoShapeEntity), + .number = SVGAProtoFrameEntity_FieldNumber_ShapesArray, + .hasIndex = GPBNoHasBit, + .offset = (uint32_t)offsetof(SVGAProtoFrameEntity__storage_, shapesArray), + .flags = GPBFieldRepeated, + .dataType = GPBDataTypeMessage, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoFrameEntity class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoFrameEntity__storage_) + flags:GPBDescriptorInitializationFlag_None]; +#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + static const char *extraTextFormatInfo = + "\001\004\010\000"; + [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; +#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + +#pragma mark - SVGAProtoMovieEntity + +@implementation SVGAProtoMovieEntity + +@dynamic version; +@dynamic hasParams, params; +@dynamic images, images_Count; +@dynamic spritesArray, spritesArray_Count; +@dynamic audiosArray, audiosArray_Count; + +typedef struct SVGAProtoMovieEntity__storage_ { + uint32_t _has_storage_[1]; + NSString *version; + SVGAProtoMovieParams *params; + NSMutableDictionary *images; + NSMutableArray *spritesArray; + NSMutableArray *audiosArray; +} SVGAProtoMovieEntity__storage_; + +// This method is threadsafe because it is initially called +// in +initialize for each subclass. ++ (GPBDescriptor *)descriptor { + static GPBDescriptor *descriptor = nil; + if (!descriptor) { + static GPBMessageFieldDescription fields[] = { + { + .name = "version", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoMovieEntity_FieldNumber_Version, + .hasIndex = 0, + .offset = (uint32_t)offsetof(SVGAProtoMovieEntity__storage_, version), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeString, + }, + { + .name = "params", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoMovieParams), + .number = SVGAProtoMovieEntity_FieldNumber_Params, + .hasIndex = 1, + .offset = (uint32_t)offsetof(SVGAProtoMovieEntity__storage_, params), + .flags = GPBFieldOptional, + .dataType = GPBDataTypeMessage, + }, + { + .name = "images", + .dataTypeSpecific.className = NULL, + .number = SVGAProtoMovieEntity_FieldNumber_Images, + .hasIndex = GPBNoHasBit, + .offset = (uint32_t)offsetof(SVGAProtoMovieEntity__storage_, images), + .flags = GPBFieldMapKeyString, + .dataType = GPBDataTypeBytes, + }, + { + .name = "spritesArray", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoSpriteEntity), + .number = SVGAProtoMovieEntity_FieldNumber_SpritesArray, + .hasIndex = GPBNoHasBit, + .offset = (uint32_t)offsetof(SVGAProtoMovieEntity__storage_, spritesArray), + .flags = GPBFieldRepeated, + .dataType = GPBDataTypeMessage, + }, + { + .name = "audiosArray", + .dataTypeSpecific.className = GPBStringifySymbol(SVGAProtoAudioEntity), + .number = SVGAProtoMovieEntity_FieldNumber_AudiosArray, + .hasIndex = GPBNoHasBit, + .offset = (uint32_t)offsetof(SVGAProtoMovieEntity__storage_, audiosArray), + .flags = GPBFieldRepeated, + .dataType = GPBDataTypeMessage, + }, + }; + GPBDescriptor *localDescriptor = + [GPBDescriptor allocDescriptorForClass:[SVGAProtoMovieEntity class] + rootClass:[SVGAProtoSvgaRoot class] + file:SVGAProtoSvgaRoot_FileDescriptor() + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(SVGAProtoMovieEntity__storage_) + flags:GPBDescriptorInitializationFlag_None]; + NSAssert(descriptor == nil, @"Startup recursed!"); + descriptor = localDescriptor; + } + return descriptor; +} + +@end + + +#pragma clang diagnostic pop + +// @@protoc_insertion_point(global_scope) diff --git a/readme.md b/readme.md index dbca59c3..5c4d0b56 100644 --- a/readme.md +++ b/readme.md @@ -1,114 +1,119 @@ +# Archived +本仓库已经停止维护,你仍然继续阅读源码及创建分叉,但本仓库不会继续更新,也不会回答任何 issue。 + +This repo has stopped maintenance, you can still continue to read the source code and create forks, but this repo will not continue to be updated, nor will it answer any issues. + # SVGAPlayer -## Version +[简体中文](./readme.zh.md) -### 1.1.6 +## 支持本项目 -Change CADisplayLink mode to NSRunLoopCommonModes, SVGAPlayer will not pause while ScrollView tracking. +1. 轻点 GitHub Star,让更多人看到该项目。 -### 1.1.4 +## 2.5.0 Released -Improve SVGAParser under multi-thread. +This version add Support for matte layer and dynamic matte bitmap.
+Head on over to [Dynamic · Matte Layer](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-%C2%B7-Matte-Layer) -## SVGA Format +This version add Support for audio step to frame & percentage. -* SVGA is an opensource animation library, develop by YY UED. -* SVGA base on SVG's concept, but not compatible to SVG. -* SVGA can play on iOS/Android/Web. +## 2.3.5 Released -@see https://github.com/yyued/SVGA-Format +This version fixed SVGAPlayer `clearsAfterStop defaults too YES`, Please check your player when it doesn't need to be cleared. -## Install +This version fixed SVGAPlayer render issue on iOS 13.1, upgrade to this version ASAP. -### CocoaPods +## Introduce -Add following dependency to Podfile -``` -pod 'SVGAPlayer' -``` +SVGAPlayer is a light-weight animation renderer. You use [tools](http://svga.io/designer.html) to export `svga` file from `Adobe Animate CC` or `Adobe After Effects`, and then use SVGAPlayer to render animation on mobile application. + +`SVGAPlayer-iOS` render animation natively via iOS CoreAnimation Framework, brings you a high-performance, low-cost animation experience. + +If wonder more information, go to this [website](http://svga.io/). ## Usage -### Init Player +Here introduce `SVGAPlayer-iOS` usage. Wonder exporting usage? Click [here](http://svga.io/designer.html). + +### Install Via CocoaPods + +You want to add pod 'SVGAPlayer', '~> 2.3' similar to the following to your Podfile: + +target 'MyApp' do + pod 'SVGAPlayer', '~> 2.3' +end + +Then run a `pod install` inside your terminal, or from CocoaPods.app. + +### Locate files + +SVGAPlayer could load svga file from application bundle or remote server. + +### Using code + +#### Create a `SVGAPlayer` instance. +```objectivec +SVGAPlayer *player = [[SVGAPlayer alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; +[self.view addSubview:player]; // Add subview by yourself. ``` -@interface XXX() -@property (nonatomic, strong) SVGAPlayer *aPlayer; // Init SVGAPlayer by yourself. -@end + +#### Create a `SVGAParser` instance, parse from bundle like this. +```objectivec +SVGAParser *parser = [[SVGAParser alloc] init]; +[parser parseWithNamed:@"posche" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { + +} failureBlock:nil]; ``` -### Init Parser, Load Resource +#### Create a `SVGAParser` instance, parse from remote server like this. -``` +```objectivec SVGAParser *parser = [[SVGAParser alloc] init]; -[parser parseWithURL:[NSURL URLWithString:@"http://uedfe.yypm.com/assets/svga-samples/angel.svga"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { +[parser parseWithURL:[NSURL URLWithString:@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { + +} failureBlock:nil]; +``` + +#### Set videoItem to `SVGAPlayer`, play it as you want. + +```objectivec +[parser parseWithURL:[NSURL URLWithString:@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { if (videoItem != nil) { - self.aPlayer.videoItem = videoItem; - [self.aPlayer startAnimation]; + player.videoItem = videoItem; + [player startAnimation]; } } failureBlock:nil]; - ``` -## API +### Cache -### Properties -* id delegate; - Callbacks -* SVGAVideoEntity *videoItem; - Animation Instance -* int loops; - Loop Count,0 = Infinity Loop -* BOOL clearsAfterStop; - Clears Canvas After Animation Stop +`SVGAParser` use `NSURLSession` request remote data via network. You may use following ways to control cache. -### Methods +#### Response Header -* (void)startAnimation; - Play Animation from 0 frame. -* (void)pauseAnimation; - Pause Animation and keep on current frame. -* (void)stopAnimation; - Stop Animation,Clears Canvas while clearsAfterStop == YES. -* (void)clear; - Clear Canvas force. -* (void)stepToFrame:(NSInteger)frame andPlay:(BOOL)andPlay; - Step to N frame, and then Play Animation if andPlay === true. -* (void)stepToPercentage:(CGFloat)percentage andPlay:(BOOL)andPlay; - Step to x%, and then Play Animation if andPlay === true. -* (void)setImage:(UIImage *)image forKey:(NSString *)aKey referenceLayer:(CALayer *)referenceLayer; - Set Dynamic Image. -* (void)setAttributedText:(NSAttributedString *)attributedText forKey:(NSString *)aKey; - Set Dynamic Text. -* (void)clearDynamicObjects; - Clear all dynamic Images and Texts. +Server response SVGA files in Body, and response header either. response header has cache-control / etag / expired keys, all these keys telling NSURLSession how to handle cache. -### SVGAPlayerDelegate +#### Request NSData By Yourself -* @optional -* - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player; - Call after animation finished. -* - (void)svgaPlayerDidAnimatedToFrame:(NSInteger)frame; - Call after animation play to specific frame. -* - (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage; - Call after animation play to specific percentage. +If you couldn't fix Server Response Header, You should build NSURLRequest with CachePolicy by yourself, and fetch NSData. -### Dynamic Object +Deliver NSData to SVGAParser, as usual. -Use this way to replace specific image, or add text to it. (可以通过以下方式,替换动画文件中的指定图像,以及动态添加富文本。) +## Features -* Must set before startAnimation method call. (必须在 startAnimation 方法执行前进行配置) +Here are many feature samples. -#### Dynamic Image +* [Replace an element with Bitmap.](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Image) +* [Add text above an element.](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Text) +* [Hides an element dynamicaly.](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Hidden) +* [Use a custom drawer for element.](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Drawer) -``` -CALayer *iconLayer = [CALayer layer]; -iconLayer.cornerRadius = 84.0; -iconLayer.masksToBounds = YES; -iconLayer.borderWidth = 4.0; -iconLayer.borderColor = [UIColor colorWithRed:0xea/255.0 green:0xb3/255.0 blue:0x7d/255.0 alpha:1.0].CGColor; -[self.aPlayer setImage:iconImage forKey:@"99" referenceLayer:iconLayer]; -``` +## APIs -* Ask designer tell you the imageKey(or unzip the svga file, find it). +Head on over to [https://github.com/yyued/SVGAPlayer-iOS/wiki/APIs](https://github.com/yyued/SVGAPlayer-iOS/wiki/APIs) -#### Dynamic Text - -``` -NSShadow *shadow = [NSShadow new]; -shadow.shadowColor = [UIColor blackColor]; -shadow.shadowOffset = CGSizeMake(0, 1); -NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"崔小姐不吃鱼 送了魔法奇缘" - attributes:@{ - NSForegroundColorAttributeName: [UIColor colorWithRed:0xff/255.0 green:0xe0/255.0 blue:0xa4/255.0 alpha:1.0], - NSFontAttributeName: [UIFont boldSystemFontOfSize:30.0], - NSShadowAttributeName: shadow, - }]; -[self.aPlayer setAttributedText:text forKey:@"banner"]; -``` +## CHANGELOG -* Ask designer tell you the imageKey(or unzip the svga file, find it). +Head on over to [CHANGELOG](./CHANGELOG.md) diff --git a/readme.zh.md b/readme.zh.md new file mode 100644 index 00000000..68248412 --- /dev/null +++ b/readme.zh.md @@ -0,0 +1,104 @@ +# SVGAPlayer + +## 2.5.0 版本 + +该版本增加了对遮罩图层和遮罩图片动态替换的支持。
+请参阅此处 [Dynamic · Matte Layer](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-%C2%B7-Matte-Layer) + +该版本增加了对音频进度切换的支持。 + +## 2.3.5 版本 + +该版本修正了 SVGAPlayer `clearsAfterStop 默认值为 YES`,请检查代码,修正不需要 clear 的 SVGAPlayer。 + +该版本修正了 SVGAPlayer 无法在 iOS 13.1 上播放异常的问题,请尽快升级。 + +## 介绍 + +`SVGAPlayer` 是一个轻量的动画渲染库。你可以使用[工具](http://svga.io/designer.html)从 `Adobe Animate CC` 或者 `Adobe After Effects` 中导出动画文件,然后使用 `SVGAPlayer` 在移动设备上渲染并播放。 + +`SVGAPlayer-iOS` 使用原生 CoreAnimation 库渲染动画,为你提供高性能、低开销的动画体验。 + +如果你想要了解更多细节,请访问[官方网站](http://svga.io/)。 + +## 用法 + +我们在这里介绍 `SVGAPlayer-iOS` 的用法。想要知道如何导出动画,点击[这里](http://svga.io/designer.html)。 + +### 使用 CocoaPods 安装依赖 + +添加依赖 'SVGAPlayer', '~> 2.3' 到 Podfile 文件中: + +target 'MyApp' do + pod 'SVGAPlayer', '~> 2.3' +end + +然后在终端执行 `pod install`。 + +### 放置 svga 文件 + +SVGAPlayer 可以从应用包,或者远端服务器上加载动画文件。 + +### 代码 + +#### 创建一个 `SVGAPlayer` 实例 + +```objectivec +SVGAPlayer *player = [[SVGAPlayer alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; +[self.view addSubview:player]; // Add subview by yourself. +``` + +#### 创建一个 `SVGAParser` 实例,使用以下方法从应用包中加载动画。 +```objectivec +SVGAParser *parser = [[SVGAParser alloc] init]; +[parser parseWithNamed:@"posche" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { + +} failureBlock:nil]; +``` + +#### 创建一个 `SVGAParser` 实例,使用以下方法从远端服务器中加载动画。 + +```objectivec +SVGAParser *parser = [[SVGAParser alloc] init]; +[parser parseWithURL:[NSURL URLWithString:@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { + +} failureBlock:nil]; +``` + +#### 将 videoItem 赋值给 `SVGAPlayer`,然后播放动画。 + +```objectivec +[parser parseWithURL:[NSURL URLWithString:@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { + if (videoItem != nil) { + player.videoItem = videoItem; + [player startAnimation]; + } +} failureBlock:nil]; +``` + +### 缓存 + +`SVGAParser` 使用 `NSURLSession` 请求远端数据,你需要通过以下方式缓存动画文件。 + +#### HTTP 结果头部信息 + +如果服务器返回的头部信息包含 cache-control / etag / expired 这些键值,这个请求会被合理地缓存到本地。 + +#### 自行缓存 NSData + +如果你没有办法控制服务器返回的头部信息,你可以自行获取对应的 svga 文件 `NSData` 数据,然后使用 `SVGAParser` 解析这些数据。 + +## 功能示例 + +* [使用位图替换指定元素。](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Image) +* [在指定元素上绘制文本。](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Text) +* [隐藏指定元素。](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Hidden) +* [在指定元素上自由绘制。](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Drawer) + +## APIs + +请参阅此处 [https://github.com/yyued/SVGAPlayer-iOS/wiki/APIs](https://github.com/yyued/SVGAPlayer-iOS/wiki/APIs) + +## CHANGELOG + +请参阅此处 [CHANGELOG](./CHANGELOG.md)