• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Replacing Font/Size of NSMutableAttributedString, but not styles
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Replacing Font/Size of NSMutableAttributedString, but not styles


  • Subject: Re: Replacing Font/Size of NSMutableAttributedString, but not styles
  • From: Dan Wood <email@hidden>
  • Date: Wed, 07 Aug 2002 11:09:18 -0700

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.

  • Follow-Ups:
    • Re: Replacing Font/Size of NSMutableAttributedString, but not styles
      • From: Brian Webster <email@hidden>
References: 
 >Re: Replacing Font/Size of NSMutableAttributedString, but not styles (From: Brian Webster <email@hidden>)

  • Prev by Date: Re: concatenating literal strings
  • Next by Date: Re: forwardInvocation: Works Locally but crashes with DO
  • Previous by thread: Re: Replacing Font/Size of NSMutableAttributedString, but not styles
  • Next by thread: Re: Replacing Font/Size of NSMutableAttributedString, but not styles
  • Index(es):
    • Date
    • Thread