Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* [ios] bugfix iconfont load, support woff #1804

Merged
merged 2 commits into from
Dec 5, 2016
Merged

* [ios] bugfix iconfont load, support woff #1804

merged 2 commits into from
Dec 5, 2016

Conversation

acton393
Copy link
Contributor

@acton393 acton393 commented Dec 2, 2016

bugfix iconfont load, support woff

url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

WXBaseViewController *vc = [[WXBaseViewController alloc]initWithSourceURL:[NSURL URLWithString:url]];
WXBaseViewController *vc = [[WXBaseViewController alloc]initWithSourceURL:[NSURL URLWithString:param[@"url"]]];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

取消 对 url 的utf-8 编码, 这个控制由前端同学来做,

@@ -84,34 +84,20 @@ - (void)addRule:(NSString*)type rule:(NSDictionary *)rule
return;
}
[fontFamily setObject:fontSrc forKey:@"src"];
if ([fontURL isFileURL]) {
// local font file will be added directly if existed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对fileURL 的处理逻辑加到了下载fontURL中 getIconfont:

// remote font file
NSString *fontfile = [NSString stringWithFormat:@"%@/%@",WX_FONT_DOWNLOAD_DIR,[WXUtility md5:fontURL.path]];
if ([WXUtility isFileExist:fontfile]) {
// if has been cached, load directly
[fontFamily setObject:[NSURL fileURLWithPath:fontfile] forKey:@"localSrc"];
[_fontStorage setObject:fontFamily forKey:rule[@"fontFamily"]];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused

__weak typeof(self) weakSelf = self;
[WXUtility getIconfont:fontURL completion:^(NSURL * _Nonnull url, NSError * _Nullable error) {
if (!error && url) {
// load success
NSMutableDictionary * dictForFontFamily = [weakSelf.fontStorage objectForKey:rule[@"fontFamily"]];
[dictForFontFamily setObject:url forKey:@"localSrc"];
[weakSelf.fontStorage setObject:url forKey: dictForFontFamily];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused

@@ -350,19 +350,15 @@ + (UIFont *)fontWithSize:(CGFloat)size textWeight:(WXTextWeight)textWeight textS
if (fontFamilyDic[@"localSrc"]){
NSString *fpath = [((NSURL*)fontFamilyDic[@"localSrc"]) path];
if ([self isFileExist:fpath]) {
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename([fpath UTF8String]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种加载font 的方式不支持,woff 字体格式,换成 CoreText支持

@@ -396,12 +392,23 @@ + (UIFont *)fontWithSize:(CGFloat)size textWeight:(WXTextWeight)textWeight textS

+ (void)getIconfont:(NSURL *)url completion:(void(^)(NSURL *url, NSError *error))completionBlock
{
if ([url isFileURL]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加FileURL 处理

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDownloadTask *task = [session downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSURL * downloadPath = nil;
if (!error && location) {
NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse*)response;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remote url is 404 , the error is nil , so add httpResponse status process

@codecov-io
Copy link

codecov-io commented Dec 2, 2016

Current coverage is 88.44% (diff: 100%)

Merging #1804 into ios-feature-20161208 will not change coverage

@@           ios-feature-20161208      #1804   diff @@
======================================================
  Files                        41         41          
  Lines                      2233       2233          
  Methods                     354        354          
  Messages                      0          0          
  Branches                    500        500          
======================================================
  Hits                       1975       1975          
  Misses                      258        258          
  Partials                      0          0          

Powered by Codecov. Last update ca3d2f8...17b43df

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDownloadTask *task = [session downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSURL * downloadPath = nil;
if (!error && location) {
NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse*)response;
if (200 == httpResponse.statusCode && !error && location) {
NSString *file = [NSString stringWithFormat:@"%@/%@",WX_FONT_DOWNLOAD_DIR,[WXUtility md5:[url path]]];
Copy link
Contributor

@kfeagle kfeagle Dec 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方是不是要改为 [url absoluteString]更好点,这个是完整的地址
[url path]是相对地址,假如两个服务器不同的字体用了相同的名字会出现bug
假如改的话,WXRuleManager.h 也同步更改


NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse*)response;
if (200 == httpResponse.statusCode && !error && location) {
NSString *file = [NSString stringWithFormat:@"%@/%@",WX_FONT_DOWNLOAD_DIR,[WXUtility md5:[url absoluteString]]];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kfeagle 更新为 使用 url absoluteString

// remote font file
NSString *fontfile = [NSString stringWithFormat:@"%@/%@",WX_FONT_DOWNLOAD_DIR,[WXUtility md5:fontURL.path]];
NSString *fontfile = [NSString stringWithFormat:@"%@/%@",WX_FONT_DOWNLOAD_DIR,[WXUtility md5:[fontURL absoluteString]]];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kfeagle 更新为使用 url absoluteString

@kfeagle kfeagle merged commit 7f7aca9 into alibaba:ios-feature-20161208 Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants