notepad-plus-plus/scintilla/cocoa/QuartzTextStyle.h

96 lines
2.1 KiB
C
Raw Normal View History

/*
* QuartzTextStyle.h
*
* Created by Evan Jones on Wed Oct 02 2002.
*
*/
#ifndef QUARTZTEXTSTYLE_H
#define QUARTZTEXTSTYLE_H
#include "QuartzTextStyleAttribute.h"
2019-05-04 18:14:48 +00:00
class QuartzTextStyle {
public:
2019-05-04 18:14:48 +00:00
QuartzTextStyle() {
fontRef = NULL;
styleDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
2019-05-04 18:14:48 +00:00
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
characterSet = 0;
}
2019-05-04 18:14:48 +00:00
QuartzTextStyle(const QuartzTextStyle &other) {
// 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);
CFDictionaryAddValue(styleDict, kCTFontAttributeName, fontRef);
characterSet = other.characterSet;
}
2019-05-04 18:14:48 +00:00
~QuartzTextStyle() {
if (styleDict != NULL) {
CFRelease(styleDict);
styleDict = NULL;
}
2019-05-04 18:14:48 +00:00
if (fontRef) {
CFRelease(fontRef);
fontRef = NULL;
}
}
2019-05-04 18:14:48 +00:00
CFMutableDictionaryRef getCTStyle() const {
return styleDict;
}
void setCTStyleColour(CGColor *inColour) {
CFDictionarySetValue(styleDict, kCTForegroundColorAttributeName, inColour);
}
2019-05-04 18:14:48 +00:00
float getAscent() const {
return static_cast<float>(::CTFontGetAscent(fontRef));
}
2019-05-04 18:14:48 +00:00
float getDescent() const {
return static_cast<float>(::CTFontGetDescent(fontRef));
}
2019-05-04 18:14:48 +00:00
float getLeading() const {
return static_cast<float>(::CTFontGetLeading(fontRef));
}
2019-05-04 18:14:48 +00:00
void setFontRef(CTFontRef inRef, int characterSet_) {
fontRef = inRef;
characterSet = characterSet_;
if (styleDict != NULL)
CFRelease(styleDict);
styleDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2,
2019-05-04 18:14:48 +00:00
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionaryAddValue(styleDict, kCTFontAttributeName, fontRef);
}
2019-05-04 18:14:48 +00:00
CTFontRef getFontRef() {
return fontRef;
}
2019-05-04 18:14:48 +00:00
int getCharacterSet() {
return characterSet;
}
private:
CFMutableDictionaryRef styleDict;
CTFontRef fontRef;
int characterSet;
};
#endif