2010-07-14 09:47:17 +00:00
|
|
|
/*
|
|
|
|
* QuartzTextStyle.h
|
|
|
|
*
|
|
|
|
* Created by Evan Jones on Wed Oct 02 2002.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-02-21 04:53:09 +00:00
|
|
|
#ifndef QUARTZTEXTSTYLE_H
|
|
|
|
#define QUARTZTEXTSTYLE_H
|
2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
characterSet = Scintilla::CharacterSet::Ansi;
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
QuartzTextStyle(const QuartzTextStyle *other) {
|
2013-08-28 00:44:27 +00:00
|
|
|
// Does not copy font colour attribute
|
2022-01-04 23:07:50 +00:00
|
|
|
fontRef = static_cast<CTFontRef>(CFRetain(other->fontRef));
|
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
|
|
|
CFDictionaryAddValue(styleDict, kCTFontAttributeName, fontRef);
|
2022-01-04 23:07:50 +00:00
|
|
|
characterSet = other->characterSet;
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
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
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
void setFontRef(CTFontRef inRef, Scintilla::CharacterSet 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
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
CTFontRef getFontRef() const noexcept {
|
2011-07-17 22:30:49 +00:00
|
|
|
return fontRef;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
Scintilla::CharacterSet getCharacterSet() const noexcept {
|
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;
|
2022-01-04 23:07:50 +00:00
|
|
|
Scintilla::CharacterSet characterSet;
|
2010-07-14 09:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|