diff options
author | nyamatongwe <unknown> | 2011-05-26 09:14:45 +1000 |
---|---|---|
committer | nyamatongwe <unknown> | 2011-05-26 09:14:45 +1000 |
commit | 82266f54fef82a3481bf9ec091d85c2c202df5ec (patch) | |
tree | 9478fbba514910e3648d97940ccd3771c9b64509 /cocoa/QuartzTextStyle.h | |
parent | 1ef9f42a4e839bf12d454e8560e7d697e1e3b0c9 (diff) | |
download | scintilla-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/QuartzTextStyle.h')
-rw-r--r-- | cocoa/QuartzTextStyle.h | 114 |
1 files changed, 51 insertions, 63 deletions
diff --git a/cocoa/QuartzTextStyle.h b/cocoa/QuartzTextStyle.h index 36729b77b..2825fbb2f 100644 --- a/cocoa/QuartzTextStyle.h +++ b/cocoa/QuartzTextStyle.h @@ -15,75 +15,63 @@ class QuartzTextStyle public: QuartzTextStyle() { - ATSUCreateStyle( &style ); + styleDict = CFDictionaryCreateMutable(NULL, 1, NULL, NULL); } ~QuartzTextStyle() { - if ( style != NULL ) - ATSUDisposeStyle( style ); - style = NULL; + if (styleDict != NULL) + { + CFRelease(styleDict); + styleDict = NULL; + } } - - void setAttribute( ATSUAttributeTag tag, ByteCount size, ATSUAttributeValuePtr value ) - { - ATSUSetAttributes( style, 1, &tag, &size, &value ); - } - - void setAttribute( QuartzTextStyleAttribute& attribute ) - { - setAttribute( attribute.getTag(), attribute.getSize(), attribute.getValuePtr() ); - } - - void getAttribute( ATSUAttributeTag tag, ByteCount size, ATSUAttributeValuePtr value, ByteCount* actualSize ) - { - ATSUGetAttribute( style, tag, size, value, actualSize ); - } - - template <class T> - T getAttribute( ATSUAttributeTag tag ) - { - T value; - ByteCount actualSize; - ATSUGetAttribute( style, tag, sizeof( T ), &value, &actualSize ); - return value; - } - - // TODO: Is calling this actually faster than calling setAttribute multiple times? - void setAttributes( QuartzTextStyleAttribute* attributes[], int number ) - { - // Create the parallel arrays and initialize them properly - ATSUAttributeTag* tags = new ATSUAttributeTag[ number ]; - ByteCount* sizes = new ByteCount[ number ]; - ATSUAttributeValuePtr* values = new ATSUAttributeValuePtr[ number ]; - - for ( int i = 0; i < number; ++ i ) - { - tags[i] = attributes[i]->getTag(); - sizes[i] = attributes[i]->getSize(); - values[i] = attributes[i]->getValuePtr(); - } - - ATSUSetAttributes( style, number, tags, sizes, values ); - - // Free the arrays that were allocated - delete[] tags; - delete[] sizes; - delete[] values; - } - - void setFontFeature( ATSUFontFeatureType featureType, ATSUFontFeatureSelector selector ) - { - ATSUSetFontFeatures( style, 1, &featureType, &selector ); - } - - const ATSUStyle& getATSUStyle() const - { - return style; - } - + + CFMutableDictionaryRef getCTStyle() const + { + return styleDict; + } + + void setCTStyleColor(CGColor* inColor ) + { + CFDictionarySetValue(styleDict, kCTForegroundColorAttributeName, inColor); + } + + float getAscent() const + { + return ::CTFontGetAscent(fontRef); + } + + float getDescent() const + { + return ::CTFontGetDescent(fontRef); + } + + float getLeading() const + { + return ::CTFontGetLeading(fontRef); + } + + void setFontRef(CTFontRef inRef) + { + fontRef = inRef; + + if (styleDict != NULL) + CFRelease(styleDict); + + styleDict = CFDictionaryCreateMutable(NULL, 1, NULL, NULL); + + CFDictionaryAddValue(styleDict, kCTFontAttributeName, fontRef); + } + + CTFontRef getFontRef() + { + return fontRef; + } + private: - ATSUStyle style; + CFMutableDictionaryRef styleDict; + CTFontRef fontRef; }; #endif |