2010-07-14 09:47:17 +00:00
|
|
|
/*
|
|
|
|
* QuartzTextStyle.h
|
|
|
|
*
|
|
|
|
* Created by Evan Jones on Wed Oct 02 2002.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _QUARTZ_TEXT_STYLE_H
|
|
|
|
#define _QUARTZ_TEXT_STYLE_H
|
|
|
|
|
|
|
|
#include "QuartzTextStyleAttribute.h"
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
class QuartzTextStyle {
|
2010-07-14 09:47:17 +00:00
|
|
|
public:
|
2019-05-04 18:14:48 +00:00
|
|
|
QuartzTextStyle() {
|
2013-08-28 00:44:27 +00:00
|
|
|
fontRef = NULL;
|
|
|
|
styleDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
|
2019-05-04 18:14:48 +00:00
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
characterSet = 0;
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
QuartzTextStyle(const QuartzTextStyle &other) {
|
2013-08-28 00:44:27 +00:00
|
|
|
// Does not copy font colour attribute
|
|
|
|
fontRef = static_cast<CTFontRef>(CFRetain(other.fontRef));
|
|
|
|
styleDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
|
2019-05-04 18:14:48 +00:00
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
2013-08-28 00:44:27 +00:00
|
|
|
CFDictionaryAddValue(styleDict, kCTFontAttributeName, fontRef);
|
|
|
|
characterSet = other.characterSet;
|
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
~QuartzTextStyle() {
|
|
|
|
if (styleDict != NULL) {
|
2011-07-17 22:30:49 +00:00
|
|
|
CFRelease(styleDict);
|
|
|
|
styleDict = NULL;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
if (fontRef) {
|
2013-08-28 00:44:27 +00:00
|
|
|
CFRelease(fontRef);
|
|
|
|
fontRef = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
CFMutableDictionaryRef getCTStyle() const {
|
2011-07-17 22:30:49 +00:00
|
|
|
return styleDict;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-07-21 13:26:02 +00:00
|
|
|
void setCTStyleColour(CGColor *inColour) {
|
|
|
|
CFDictionarySetValue(styleDict, kCTForegroundColorAttributeName, inColour);
|
2011-07-17 22:30:49 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
float getAscent() const {
|
2015-06-07 21:19:26 +00:00
|
|
|
return static_cast<float>(::CTFontGetAscent(fontRef));
|
2011-07-17 22:30:49 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
float getDescent() const {
|
2015-06-07 21:19:26 +00:00
|
|
|
return static_cast<float>(::CTFontGetDescent(fontRef));
|
2011-07-17 22:30:49 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
float getLeading() const {
|
2015-06-07 21:19:26 +00:00
|
|
|
return static_cast<float>(::CTFontGetLeading(fontRef));
|
2011-07-17 22:30:49 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
void setFontRef(CTFontRef inRef, int characterSet_) {
|
2011-07-17 22:30:49 +00:00
|
|
|
fontRef = inRef;
|
2013-08-28 00:44:27 +00:00
|
|
|
characterSet = characterSet_;
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
if (styleDict != NULL)
|
|
|
|
CFRelease(styleDict);
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
styleDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
|
2019-05-04 18:14:48 +00:00
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
CFDictionaryAddValue(styleDict, kCTFontAttributeName, fontRef);
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
CTFontRef getFontRef() {
|
2011-07-17 22:30:49 +00:00
|
|
|
return fontRef;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
int getCharacterSet() {
|
2013-08-28 00:44:27 +00:00
|
|
|
return characterSet;
|
|
|
|
}
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
private:
|
2011-07-17 22:30:49 +00:00
|
|
|
CFMutableDictionaryRef styleDict;
|
|
|
|
CTFontRef fontRef;
|
2013-08-28 00:44:27 +00:00
|
|
|
int characterSet;
|
2010-07-14 09:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|