Stupid Newbie Font/Glyph Questions
Stupid Newbie Font/Glyph Questions
- Subject: Stupid Newbie Font/Glyph Questions
- From: Tom Gray <email@hidden>
- Date: Fri, 1 Nov 2002 10:54:21 -0500
I beg your forgiveness for my stunningly naive and ignorant questions.
I have been programming for years and have worked in Cocoa for about a
year, but I just have never done any extensive work with fonts.
My problem is that the on screen width of a lines of text (80
characters) in a monospaced font (Courier) seems to vary from machine
to machine. As a result sometimes the text fits on one line, sometimes
it doesn't. This is a BIG problem for me.
Here is what I am doing.
I create a NSMutableParagraphStyle
// Create a paragraph style.
paragraph = [[NSMutableParagraphStyle alloc] init];
[paragraph setMinimumLineHeight:14.0];
[paragraph setMaximumLineHeight:14.0];
[paragraph setLineSpacing:0];
I create a NSMutableDictionary containing the font traits I want.
// Initialize the terminal character attributes.
terminalcharAttributes = [[NSMutableDictionary
dictionaryWithCapacity:3] retain];
// NSUnderlineStyleAttributeName
[terminalcharAttributes setObject:[NSNumber numberWithInt:0] forKey:
NSUnderlineStyleAttributeName];
// NSForegroundColorAttributeName
[terminalcharAttributes setObject:[NSColor blackColor]
forKey:NSForegroundColorAttributeName];
// NSFontAttributeName
[terminalcharAttributes setObject: [NSFont fontWithName:@"Courier"
size:12] forKey:NSFontAttributeName];
// NSKernAttributeName
[terminalcharAttributes setObject:kerning forKey:NSKernAttributeName];
// NSParagraphStyleAttributeName
[terminalcharAttributes setObject:paragraph
forKey:NSParagraphStyleAttributeName];
I create a NSMutableAttributedString with a 80 "space" characters.
// Create (and retain) a "blank" or "empty" line (80 spaces and a
c/r) using the default attributes.
tString = [[[ NSMutableAttributedString alloc]
initWithString:emptyLine] retain];
I set the attributes of this NSMutableAttributedString.
[tString setAttributes: terminalcharAttributes range:NSMakeRange(0,
[tString length])];
I convert my mutable attributed string to an immutable attributed
string.
blankLine = [[[NSAttributedString alloc]
initWithAttributedString:tString] retain];
On most of the machines my program runs on, this string fits just fine
in the space in the NSTextView subclass I created in IB. On some
machines it wraps to the next line.
Dumb, stupid question number 1.
How do I get the glyph of a particular character for this attributed
string? I want to look at the bounding rectangles for a "space"
character. how do i get the glyph?
Dumb, stupid question number 2.
How can my NSTextView with a bounds width of 352 show my my attributed
string which has a width of 559?
testRect = [terminalView bounds];
NSLog(@"- bounds width: %.0f", testRect.size.width);
Terminal Values: - bounds width: 579
NSLog(@"Attributed String Values: (expected values)");
testSize = [blankLine size];
NSLog(@"- size: w:%0.f h:%0.f (29)", testSize.width,
testSize.height);
Attributed String Values: - size: w:559
Thanks for help.
Tom Gray
-------------
email@hidden
or
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.