aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa/QuartzTextStyleAttribute.h
diff options
context:
space:
mode:
authornyamatongwe <unknown>2011-05-26 09:14:45 +1000
committernyamatongwe <unknown>2011-05-26 09:14:45 +1000
commit82266f54fef82a3481bf9ec091d85c2c202df5ec (patch)
tree9478fbba514910e3648d97940ccd3771c9b64509 /cocoa/QuartzTextStyleAttribute.h
parent1ef9f42a4e839bf12d454e8560e7d697e1e3b0c9 (diff)
downloadscintilla-mirror-82266f54fef82a3481bf9ec091d85c2c202df5ec.tar.gz
Convert text drawing and measurement to use Core Text API.
Contributed by Elizabeth Irizarry of Adobe with some modifications by Neil Hodgson.
Diffstat (limited to 'cocoa/QuartzTextStyleAttribute.h')
-rw-r--r--cocoa/QuartzTextStyleAttribute.h145
1 files changed, 34 insertions, 111 deletions
diff --git a/cocoa/QuartzTextStyleAttribute.h b/cocoa/QuartzTextStyleAttribute.h
index cf227e47f..41582e8ec 100644
--- a/cocoa/QuartzTextStyleAttribute.h
+++ b/cocoa/QuartzTextStyleAttribute.h
@@ -12,131 +12,54 @@
#ifndef _QUARTZ_TEXT_STYLE_ATTRIBUTE_H
#define _QUARTZ_TEXT_STYLE_ATTRIBUTE_H
-class QuartzTextStyleAttribute
-{
-public:
- QuartzTextStyleAttribute() {}
- virtual ~QuartzTextStyleAttribute() {}
- virtual ByteCount getSize() const = 0;
- virtual ATSUAttributeValuePtr getValuePtr() = 0;
- virtual ATSUAttributeTag getTag() const = 0;
-};
-
-class QuartzTextSize : public QuartzTextStyleAttribute
-{
-public:
- QuartzTextSize( float points )
- {
- size = X2Fix( points );
- }
-
- ByteCount getSize() const
- {
- return sizeof( size );
- }
-
- ATSUAttributeValuePtr getValuePtr()
- {
- return &size;
- }
-
- ATSUAttributeTag getTag() const
- {
- return kATSUSizeTag;
- }
-
-private:
- Fixed size;
-};
-
-class QuartzTextStyleAttributeBoolean : public QuartzTextStyleAttribute
-{
-public:
- QuartzTextStyleAttributeBoolean( bool newVal ) : value( newVal ) {}
-
- ByteCount getSize() const
- {
- return sizeof( value );
- }
- ATSUAttributeValuePtr getValuePtr()
- {
- return &value;
- }
-
- virtual ATSUAttributeTag getTag() const = 0;
-
-private:
- Boolean value;
-};
-
-class QuartzTextBold : public QuartzTextStyleAttributeBoolean
-{
-public:
- QuartzTextBold( bool newVal ) : QuartzTextStyleAttributeBoolean( newVal ) {}
- ATSUAttributeTag getTag() const
- {
- return kATSUQDBoldfaceTag;
- }
-};
-
-class QuartzTextItalic : public QuartzTextStyleAttributeBoolean
-{
-public:
- QuartzTextItalic( bool newVal ) : QuartzTextStyleAttributeBoolean( newVal ) {}
- ATSUAttributeTag getTag() const
- {
- return kATSUQDItalicTag;
- }
-};
-
-class QuartzTextUnderline : public QuartzTextStyleAttributeBoolean
-{
-public:
- QuartzTextUnderline( bool newVal ) : QuartzTextStyleAttributeBoolean( newVal ) {}
- ATSUAttributeTag getTag() const {
- return kATSUQDUnderlineTag;
- }
-};
-
-class QuartzFont : public QuartzTextStyleAttribute
+class QuartzFont
{
public:
/** Create a font style from a name. */
- QuartzFont( const char* name, int length )
+ QuartzFont( const char* name, int length, float size, bool bold, bool italic )
{
assert( name != NULL && length > 0 && name[length] == '\0' );
- // try to create font
- OSStatus err = ATSUFindFontFromName( const_cast<char*>( name ), length, kFontFullName, (unsigned) kFontNoPlatform, kFontRomanScript, (unsigned) kFontNoLanguage, &fontid );
- // need a fallback if font isn't installed
- if( err != noErr || fontid == kATSUInvalidFontID )
- ::ATSUFindFontFromName( "Lucida Grande", 13, kFontFullName, (unsigned) kFontNoPlatform, kFontRomanScript, (unsigned) kFontNoLanguage, &fontid );
+ CFStringRef fontName = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingMacRoman);
+ assert(fontName != NULL);
+
+ if (bold || italic)
+ {
+ CTFontSymbolicTraits desiredTrait = 0;
+ CTFontSymbolicTraits traitMask = 0;
+
+ // if bold was specified, add the trait
+ if (bold) {
+ desiredTrait |= kCTFontBoldTrait;
+ traitMask |= kCTFontBoldTrait;
+ }
+
+ // if italic was specified, add the trait
+ if (italic) {
+ desiredTrait |= kCTFontItalicTrait;
+ traitMask |= kCTFontItalicTrait;
+ }
+
+ // create a font and then a copy of it with the sym traits
+ CTFontRef iFont = ::CTFontCreateWithName(fontName, size, NULL);
+ fontid = ::CTFontCreateCopyWithSymbolicTraits(iFont, size, NULL, desiredTrait, traitMask);
+ CFRelease(iFont);
+ }
+ else
+ {
+ // create the font, no traits
+ fontid = ::CTFontCreateWithName(fontName, size, NULL);
+ }
}
- ByteCount getSize() const
- {
- return sizeof( fontid );
- }
-
- ATSUAttributeValuePtr getValuePtr()
- {
- return &fontid;
- }
-
- ATSUAttributeTag getTag() const
- {
- return kATSUFontTag;
- }
-
- ATSUFontID getFontID() const
+ CTFontRef getFontID()
{
return fontid;
}
private:
- ATSUFontID fontid;
+ CTFontRef fontid;
};
-
#endif