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"
|
|
|
|
|
|
|
|
class QuartzTextStyle
|
|
|
|
{
|
|
|
|
public:
|
2013-08-28 00:44:27 +00:00
|
|
|
QuartzTextStyle()
|
|
|
|
{
|
|
|
|
fontRef = NULL;
|
|
|
|
styleDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
|
|
|
|
characterSet = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QuartzTextStyle(const QuartzTextStyle &other)
|
|
|
|
{
|
|
|
|
// Does not copy font colour attribute
|
|
|
|
fontRef = static_cast<CTFontRef>(CFRetain(other.fontRef));
|
|
|
|
styleDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
CFDictionaryAddValue(styleDict, kCTFontAttributeName, fontRef);
|
|
|
|
characterSet = other.characterSet;
|
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
~QuartzTextStyle()
|
|
|
|
{
|
2011-07-17 22:30:49 +00:00
|
|
|
if (styleDict != NULL)
|
|
|
|
{
|
|
|
|
CFRelease(styleDict);
|
|
|
|
styleDict = NULL;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
if (fontRef)
|
|
|
|
{
|
|
|
|
CFRelease(fontRef);
|
|
|
|
fontRef = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
CFMutableDictionaryRef getCTStyle() const
|
|
|
|
{
|
|
|
|
return styleDict;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
void setCTStyleColor(CGColor *inColor)
|
2011-07-17 22:30:49 +00:00
|
|
|
{
|
|
|
|
CFDictionarySetValue(styleDict, kCTForegroundColorAttributeName, inColor);
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
float getAscent() const
|
|
|
|
{
|
|
|
|
return ::CTFontGetAscent(fontRef);
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
float getDescent() const
|
|
|
|
{
|
|
|
|
return ::CTFontGetDescent(fontRef);
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
float getLeading() const
|
|
|
|
{
|
|
|
|
return ::CTFontGetLeading(fontRef);
|
|
|
|
}
|
2013-08-28 00:44:27 +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,
|
|
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
CFDictionaryAddValue(styleDict, kCTFontAttributeName, fontRef);
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
CTFontRef getFontRef()
|
|
|
|
{
|
|
|
|
return fontRef;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
int getCharacterSet()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|