2012-04-03 68 views
21

我有一個可創建PDF的Cocoa OS X應用程序用於打印。我遇到一個問題,當我使用小字號時,字距似乎都是錯誤的。這是一個屏幕截圖。這是我的應用程序通過使用Helvetica在6個點輸出的PDF擴大。 Horrible Kerning Output可可(OS X)的小字體-kerning看起來很糟糕

正如您所看到的,字距很可怕,有些字符觸及其他字符太遠。

我使用的基本代碼如下所示(這是能重現問題對我來說是簡單的例子):

NSString* dateStr = @"Printed 04/03/2012"; 
NSFont* detailsFont = [NSFont fontWithName:@"Helvetica" size:6]; 
NSMutableAttributedString* printedDate = [[NSMutableAttributedString alloc] initWithString:dateStr]; 
[printedDate addAttribute:NSFontAttributeName value:detailsFont range:NSMakeRange(0, [dateStr length])]; 
NSRect printedDateRect = NSMakeRect(0, 0, theWidth, 10); 
[printedDate drawInRect:printedDateRect]; 

這是不是唯一的Helvetica字體,它發生在我的所有字體已經嘗試過,儘管它比其他一些更明顯。如果我使用更大的尺寸,比如10,它看起來很好。從其他應用程序,如文本編輯6點Helvetica看起來不錯。我需要做些什麼才能正確呈現6點文字?

編輯補充:我剛剛注意到,對於TrueType字體而言,這比使用PostScript字體更糟糕。可悲的是,我沒有我想要使用的許多字體的PostScript版本,所以避免使用TrueType並不是一個真正的選擇。

我正在運行OS X 10.7.3和XCode 4.2.1。

+3

男人,這是一些嚴重的[keming](http://www.ironicsans.com/2008/02/idea_a_new_typography_term.html)。 – blahdiblah 2012-04-03 23:13:41

+0

我在我的電腦上測試了你的代碼。我無法得到任何不好的東西,但我確實注意到它受到了我用於'theWidth'的值的影響,所以你可能想嘗試改變它。此外,對於這樣的簡單繪圖,您可能想要使用[NSString的'drawInRect:withAttributes:'](http://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSString_AppKitAdditions/Reference /Reference.html#//apple_ref/occ/instm/NSString/drawInRect:withAttributes :),而不是讓代碼更簡單。 – ughoavgfhw 2012-04-03 23:46:42

+0

謝謝。使寬度太小肯定會導致問題,但在我的代碼中,它被設置爲紙張的整個寬度。我可以將它設置爲一個龐大的數字,但它仍然存在同樣的問題。 – Wouldchux 2012-04-04 00:05:29

回答

1

我認爲printedDateRect的大小不正確。要檢查這一點,請嘗試使用- (void)drawAtPoint:(NSPoint)point

只是一個提示...

0

如果你得到這個你可能想嘗試的字體大小的變化,並返回在細胞內多餘的線條在單元格中。嘗試這種方法。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    cell.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    cell.textLabel.font = [UIFont boldSystemFontOfSize:11]; 
    cell.textLabel.numberOfLines = 13; 
相關問題