Re: Replacing Font/Size of NSMutableAttributedString, but not styles
Re: Replacing Font/Size of NSMutableAttributedString, but not styles
- Subject: Re: Replacing Font/Size of NSMutableAttributedString, but not styles
- From: Brian Webster <email@hidden>
- Date: Thu, 8 Aug 2002 09:43:09 -0500
Hmm, well, it does seem that those are two different fonts,
since one is Times and the other is Times Roman. Do they return
different family names as well?
There's probably some way to specify the base font, but I'm also
pretty sure it would mean digging into private API (it looks
like the initWithHTML:... methods actually use Apple's private
HTMLDisplay framework to do the dirty work). Whether you want
to do that's up to you.
On Wednesday, August 7, 2002, at 01:09 PM, Dan Wood wrote:
Thanks Brian.
This is getting close (see snippet I did below) but it looks
like the problem is that the text that I have has runs of text
alternating between Times-Roman and Times-Bold (not using the
bold traits) -- and since I really want to convert these to
plain and bold variations of another font, it looks like I
don't have much to do other than something kludgey like scan
for the word "Bold" in the font name and react accordingly.
YUCK!
It sure would be easier to be able to specify the base font, so
I wouldn't have to do this, and even font tags like <small>
would behave as expected. Any other ideas?
Dan
NSRange range;
NSFontManager *fontManager = [NSFontManager sharedFontManager];
range = NSMakeRange(0,0);
while(NSMaxRange(range) < [result length])
{
NSDictionary *attributes = [result
attributesAtIndex:NSMaxRange(range) effectiveRange:&range];
NSFont *oldFont = [attributes objectForKey:NSFontAttributeName];
NSFontTraitMask oldTraits = [fontManager
traitsOfFont:oldFont]; // save the old traits
NSFont *newFont = [fontManager
convertFont:givenFont toHaveTrait:oldTraits];
[result addAttribute:NSFontAttributeName
value:newFont range:range];
}
On Tuesday, August 6, 2002, at 07:33 AM, Brian Webster wrote:
On Tuesday, August 6, 2002, at 12:04 AM, cocoa-dev-
email@hidden wrote:
Any suggestions for either (a) parsing the HTML with a
particular base
font, rather than Times Roman, or (b) cleanly replacing the typeface
and size, without the styles?
Take a look at the code snippet in this message in the
archives. I think it should suit your purposes with only
minor modifications.
http://cocoa.mamasam.com/COCOADEV/2002/07/1/39315.php
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
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.
--
Dan Wood
Karelia Software, LLC
email@hidden
http://www.karelia.com/
Watson for Mac OS X: http://www.karelia.com/watson/
_______________________________________________
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.