On 20 Aug, 2013, at 4:23 PM, Graham Cox <graham....@bigpond.com> wrote:
> On 20/08/2013, at 8:38 AM, Peter C <peterchan...@gmail.com> wrote: > >> Yes, it is possible to pass values with NSParagraphStyleAttributeName for >> NSString drawInRect:withAttributes. However by default line spacing or gap >> between lines is different compare to CoreText functions (CTFramesetter and >> etc). The gap is taller for NSString, perhaps the calculation is based on >> round up values rather than fraction values of the font height. > > I'm not sure but I think because the purpose of the NSString convenience > method is for UI labelling, there is an additional border added to the > bounding rect needed. However, this shouldn't affect the spacing of multiple > lines if the text wraps. If you are trying to draw each line yourself then > you are not going to see the same line spacing and you're doing unnecessary > work. I do not intend to draw line by line. The app would auto flow line of text in a text box. It is a simple variable text length, one to few lines text for label printing (printer and display). >> I believe the user would be probably happy with CoreText compare to NSString >> by default values. Print people, they are sensitive to typography >> measurements. According to the user, it's a common feature for apps like MS >> Word (line spacing) or Adobe Indesign (font leading). Putting some controls >> for line spacing and kern width will make them happy. > > You can do all of that with NSString + attributes, or alternatively > NSAttributedString. You can also use Core Text, but it's generally harder to > use than NSAttributedString and in this case doesn't give you anything you > don't already have. Core Text is harder. I would prefer NSString but line spacing by default is bad for NSString. Check this URL out, especially the picture. http://stackoverflow.com/questions/10587606/core-text-a-bit-smaller-than-nsstring-drawinrect?lq=1 When bigger font size is use, the line spacing is worse for NSString. >> The question is how to get maximum value of maximumLineHeight of a >> particular font ? > > I think that question is meaningless because there's no inherent "maximum" > for a line height for any font or font size. There is a minimum, which is > easily calculated from the NSFont - the simplest is probably to use > -boundingRectForFont.size.height. > > But you are taking about line SPACING, not line height. This is additional > space inserted between each line of wrapped text. It is a property of the > paragraph style and is implemented by the NSLayoutManager. For your purposes, > the [NSParagraphStyle lineHeightMultiple] is probably what you want - you can > just set it to 1, 1.5, 2 etc and it will perform all the calculations for > you. This is the property that the line spacing control in NSTextView affects. > > > --Graham OK, I will investigate NSParagraphStyle lineHeightMultiple. NSParagraphStyle lineSpacing would have work if negative value is allow. -- Peter Chan _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com