aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'cocoa')
-rw-r--r--cocoa/PlatCocoa.h6
-rw-r--r--cocoa/PlatCocoa.mm37
2 files changed, 26 insertions, 17 deletions
diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h
index 1df4e0458..040821cb8 100644
--- a/cocoa/PlatCocoa.h
+++ b/cocoa/PlatCocoa.h
@@ -41,7 +41,7 @@ namespace Scintilla {
// A class to do the actual text rendering for us using Quartz 2D.
class SurfaceImpl : public Surface {
private:
- bool unicodeMode;
+ SurfaceMode mode;
float x;
float y;
@@ -49,7 +49,6 @@ private:
/** The text layout instance */
std::unique_ptr<QuartzTextLayout> textLayout;
- int codePage;
int verticalDeviceResolution;
/** If the surface is a bitmap context, contains a reference to the bitmap data. */
@@ -71,6 +70,7 @@ private:
static const int BITS_PER_PIXEL = BITS_PER_COMPONENT * 4;
static const int BYTES_PER_PIXEL = BITS_PER_PIXEL / 8;
+ bool UnicodeMode() const noexcept;
void Clear();
public:
@@ -82,6 +82,8 @@ public:
void InitPixMap(int width, int height, Surface *surface_, WindowID wid) override;
CGContextRef GetContext() { return gc; }
+ void SetMode(SurfaceMode mode) override;
+
void Release() noexcept override;
int Supports(int feature) noexcept override;
bool Initialised() override;
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index ef8a3f518..b5e1da79b 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -350,13 +350,11 @@ const int SupportsCocoa[] = {
//----------------- SurfaceImpl --------------------------------------------------------------------
SurfaceImpl::SurfaceImpl() {
- unicodeMode = true;
x = 0;
y = 0;
gc = NULL;
textLayout.reset(new QuartzTextLayout());
- codePage = 0;
verticalDeviceResolution = 0;
bitmapData.reset(); // Release will try and delete bitmapData if != nullptr
@@ -374,6 +372,12 @@ SurfaceImpl::~SurfaceImpl() {
//--------------------------------------------------------------------------------------------------
+bool SurfaceImpl::UnicodeMode() const noexcept {
+ return mode.codePage == SC_CP_UTF8;
+}
+
+//--------------------------------------------------------------------------------------------------
+
void SurfaceImpl::Clear() {
if (bitmapData) {
bitmapData.reset();
@@ -468,16 +472,20 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface *surface_, WindowID
if (surface_) {
SurfaceImpl *psurfOther = static_cast<SurfaceImpl *>(surface_);
- unicodeMode = psurfOther->unicodeMode;
- codePage = psurfOther->codePage;
+ mode = psurfOther->mode;
} else {
- unicodeMode = true;
- codePage = SC_CP_UTF8;
+ mode.codePage = SC_CP_UTF8;
}
}
//--------------------------------------------------------------------------------------------------
+void SurfaceImpl::SetMode(SurfaceMode mode_) {
+ mode = mode_;
+}
+
+//--------------------------------------------------------------------------------------------------
+
int SurfaceImpl::Supports(int feature) noexcept {
for (const int f : SupportsCocoa) {
if (f == feature)
@@ -1472,7 +1480,7 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, const Font *font_, XYPOSITI
if (!style) {
return;
}
- CFStringEncoding encoding = EncodingFromCharacterSet(unicodeMode, style->getCharacterSet());
+ CFStringEncoding encoding = EncodingFromCharacterSet(UnicodeMode(), style->getCharacterSet());
ColourDesired colour(fore.AsInteger());
CGColorRef color = CGColorCreateGenericRGB(colour.GetRed()/255.0, colour.GetGreen()/255.0, colour.GetBlue()/255.0, 1.0);
@@ -1491,7 +1499,7 @@ void SurfaceImpl::MeasureWidths(const Font *font_, std::string_view text, XYPOSI
if (!style) {
return;
}
- CFStringEncoding encoding = EncodingFromCharacterSet(unicodeMode, style->getCharacterSet());
+ CFStringEncoding encoding = EncodingFromCharacterSet(UnicodeMode(), style->getCharacterSet());
const CFStringEncoding encodingUsed =
textLayout->setText(text, encoding, style);
@@ -1507,7 +1515,7 @@ void SurfaceImpl::MeasureWidths(const Font *font_, std::string_view text, XYPOSI
return;
}
- if (unicodeMode) {
+ if (UnicodeMode()) {
// Map the widths given for UTF-16 characters back onto the UTF-8 input string
CFIndex fit = textLayout->getStringLength();
int ui=0;
@@ -1530,10 +1538,10 @@ void SurfaceImpl::MeasureWidths(const Font *font_, std::string_view text, XYPOSI
while (i<text.length()) {
positions[i++] = lastPos;
}
- } else if (codePage) {
+ } else if (mode.codePage) {
int ui = 0;
for (int i=0; i<text.length();) {
- size_t lenChar = DBCSIsLeadByte(codePage, text[i]) ? 2 : 1;
+ size_t lenChar = DBCSIsLeadByte(mode.codePage, text[i]) ? 2 : 1;
CGFloat xPosition = CTLineGetOffsetForStringIndex(mLine, ui+1, NULL);
for (unsigned int bytePos=0; (bytePos<lenChar) && (i<text.length()); bytePos++) {
positions[i++] = static_cast<XYPOSITION>(xPosition);
@@ -1554,7 +1562,7 @@ XYPOSITION SurfaceImpl::WidthText(const Font *font_, std::string_view text) {
if (!style) {
return 1;
}
- CFStringEncoding encoding = EncodingFromCharacterSet(unicodeMode, style->getCharacterSet());
+ CFStringEncoding encoding = EncodingFromCharacterSet(UnicodeMode(), style->getCharacterSet());
textLayout->setText(text, encoding, style);
return static_cast<XYPOSITION>(textLayout->MeasureStringWidth());
@@ -1714,12 +1722,11 @@ void SurfaceImpl::FlushCachedState() {
}
void SurfaceImpl::SetUnicodeMode(bool unicodeMode_) {
- unicodeMode = unicodeMode_;
+ mode.codePage = unicodeMode_ ? SC_CP_UTF8 : 0;
}
void SurfaceImpl::SetDBCSMode(int codePage_) {
- if (codePage_ && (codePage_ != SC_CP_UTF8))
- codePage = codePage_;
+ mode.codePage = codePage_;
}
void SurfaceImpl::SetBidiR2L(bool) {