Skip to content

Commit

Permalink
Modify to return nil if empty text is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
ikait committed May 31, 2016
1 parent 99278f8 commit d5e7d9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion KernLabel/KernLabel/KernLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public class KernLabel: UIView {
truncateText: self.truncateText,
kerningRegexp: self.kerningMode.regexp)
type.createDrawedImage()
return CGRect(origin: CGPointZero, size: type.intrinsicTextSize!)
return CGRect(origin: CGPointZero, size: type.intrinsicTextSize)
}

/**
Expand Down
8 changes: 6 additions & 2 deletions KernLabel/KernLabel/Type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct Type {
var typesetter: CTTypesetter

/// 実際のテキストサイズ
var intrinsicTextSize: CGSize?
var intrinsicTextSize = CGSizeZero

// フォントの半分の大きさ
var fontHalfWidth: CGFloat {
Expand Down Expand Up @@ -305,7 +305,7 @@ struct Type {
canvasContext,
CGRectMake(
0, // ↓ Int で切り捨ててピクセルまたぎでボヤけないようにする
CGFloat(Int((self.height - self.intrinsicTextSize!.height) / 2)),
CGFloat(Int((self.height - self.intrinsicTextSize.height) / 2)),
self.width,
self.height),
CGBitmapContextCreateImage(context)
Expand All @@ -320,6 +320,10 @@ struct Type {
*/
private mutating func process(canvasContext: CGContext? = nil) -> CGContext? {

if self.attributedText.string.isEmpty {
return nil
}

let context = self.createEmptyContext()

while self.location < self.length {
Expand Down

0 comments on commit d5e7d9d

Please sign in to comment.