diff options
| -rw-r--r-- | cocoa/PlatCocoa.h | 6 | ||||
| -rw-r--r-- | cocoa/PlatCocoa.mm | 37 | ||||
| -rwxr-xr-x | gtk/PlatGTK.cxx | 31 | ||||
| -rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 22 | ||||
| -rw-r--r-- | qt/ScintillaEditBase/PlatQt.h | 5 | ||||
| -rw-r--r-- | src/Platform.h | 13 | ||||
| -rw-r--r-- | win32/PlatWin.cxx | 79 | 
7 files changed, 125 insertions, 68 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) { diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 1732c217e..495c0d790 100755 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -126,6 +126,7 @@ namespace Scintilla {  // SurfaceID is a cairo_t*  class SurfaceImpl : public Surface { +	SurfaceMode mode;  	encodingType et;  	cairo_t *context;  	cairo_surface_t *psurf; @@ -152,6 +153,8 @@ public:  	void Init(SurfaceID sid, WindowID wid) override;  	void InitPixMap(int width, int height, Surface *surface_, WindowID wid) override; +	void SetMode(SurfaceMode mode_) override; +  	void Clear() noexcept;  	void Release() noexcept override;  	int Supports(int feature) noexcept override; @@ -400,7 +403,18 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface *surface_, WindowID  	cairo_set_line_width(context, 1);  	createdGC = true;  	inited = true; -	et = surfImpl->et; +	SetMode(surfImpl->mode); +} + +void SurfaceImpl::SetMode(SurfaceMode mode_) { +	mode = mode_; +	if (mode.codePage == SC_CP_UTF8) { +		et = UTF8; +	} else if (mode.codePage) { +		et = dbcs; +	} else { +		et = singleByte; +	}  }  int SurfaceImpl::Supports(int feature) noexcept { @@ -1263,13 +1277,24 @@ void SurfaceImpl::PopClip() {  void SurfaceImpl::FlushCachedState() {}  void SurfaceImpl::SetUnicodeMode(bool unicodeMode_) { -	if (unicodeMode_) +	if (unicodeMode_) { +		mode.codePage = SC_CP_UTF8;  		et = UTF8; +	} else { +		mode.codePage = 0; +		et = singleByte; +	}  }  void SurfaceImpl::SetDBCSMode(int codePage) { -	if (codePage && (codePage != SC_CP_UTF8)) +	mode.codePage = codePage; +	if (mode.codePage == SC_CP_UTF8) { +		et = UTF8; +	} else if (mode.codePage) {  		et = dbcs; +	} else { +		et = singleByte; +	}  }  void SurfaceImpl::SetBidiR2L(bool) { diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index f2681013a..6503d9c19 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -155,7 +155,7 @@ std::shared_ptr<Font> Font::Allocate(const FontParameters &fp)  SurfaceImpl::SurfaceImpl()  : device(nullptr), painter(nullptr), deviceOwned(false), painterOwned(false), x(0), y(0), -	  unicodeMode(false), codePage(0), codecName(nullptr), codec(nullptr) +	  codecName(nullptr), codec(nullptr)  {}  SurfaceImpl::~SurfaceImpl()  { @@ -200,8 +200,12 @@ void SurfaceImpl::InitPixMap(int width,  	deviceOwned = true;  	device = new QPixmap(width, height);  	SurfaceImpl *psurfOther = dynamic_cast<SurfaceImpl *>(surface); -	SetUnicodeMode(psurfOther->unicodeMode); -	SetDBCSMode(psurfOther->codePage); +	mode = psurfOther->mode; +} + +void SurfaceImpl::SetMode(SurfaceMode mode_) +{ +	mode = mode_;  }  void SurfaceImpl::Release() noexcept @@ -253,7 +257,7 @@ void SurfaceImpl::SetCodec(const Font *font)  	const FontAndCharacterSet *pfacs = AsFontAndCharacterSet(font);  	if (pfacs && pfacs->pfont) {  		const char *csid = "UTF-8"; -		if (!unicodeMode) +		if (!(mode.codePage == SC_CP_UTF8))  			csid = CharacterSetID(pfacs->characterSet);  		if (csid != codecName) {  			codecName = csid; @@ -681,7 +685,7 @@ void SurfaceImpl::MeasureWidths(const Font *font,  	tlay.beginLayout();  	QTextLine tl = tlay.createLine();  	tlay.endLayout(); -	if (unicodeMode) { +	if (mode.codePage == SC_CP_UTF8) {  		int fit = su.size();  		int ui=0;  		size_t i=0; @@ -701,11 +705,11 @@ void SurfaceImpl::MeasureWidths(const Font *font,  		while (i<text.length()) {  			positions[i++] = lastPos;  		} -	} else if (codePage) { +	} else if (mode.codePage) {  		// DBCS  		int ui = 0;  		for (size_t i=0; i<text.length();) { -			size_t lenChar = DBCSIsLeadByte(codePage, text[i]) ? 2 : 1; +			size_t lenChar = DBCSIsLeadByte(mode.codePage, text[i]) ? 2 : 1;  			qreal xPosition = tl.cursorToX(ui+1);  			for (unsigned int bytePos=0; (bytePos<lenChar) && (i<text.length()); bytePos++) {  				positions[i++] = xPosition; @@ -852,12 +856,12 @@ void SurfaceImpl::FlushCachedState()  void SurfaceImpl::SetUnicodeMode(bool unicodeMode_)  { -	unicodeMode=unicodeMode_; +	mode.codePage = unicodeMode_ ? SC_CP_UTF8 : 0;  }  void SurfaceImpl::SetDBCSMode(int codePage_)  { -	codePage = codePage_; +	mode.codePage = codePage_;  }  void SurfaceImpl::SetBidiR2L(bool) diff --git a/qt/ScintillaEditBase/PlatQt.h b/qt/ScintillaEditBase/PlatQt.h index b579ee3f3..8f4d2c51d 100644 --- a/qt/ScintillaEditBase/PlatQt.h +++ b/qt/ScintillaEditBase/PlatQt.h @@ -78,8 +78,7 @@ private:  	bool deviceOwned;  	bool painterOwned;  	float x, y; -	bool unicodeMode; -	int codePage; +	SurfaceMode mode;  	const char *codecName;  	QTextCodec *codec; @@ -94,6 +93,8 @@ public:  	void InitPixMap(int width, int height,  		Surface *surface, WindowID wid) override; +	void SetMode(SurfaceMode mode) override; +  	void Release() noexcept override;  	int Supports(int feature) noexcept override;  	bool Initialised() override; diff --git a/src/Platform.h b/src/Platform.h index 568c571cc..3afa24c92 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -163,6 +163,17 @@ public:  };  /** + * Parameters for surfaces. + */ +struct SurfaceMode { +	int codePage = 0; +	bool bidiR2L = false; +	SurfaceMode() = default; +	explicit SurfaceMode(int codePage_, bool bidiR2L_) noexcept : codePage(codePage_), bidiR2L(bidiR2L_) { +	} +}; + +/**   * A surface abstracts a place to draw.   */  class Surface { @@ -179,6 +190,8 @@ public:  	virtual void Init(SurfaceID sid, WindowID wid)=0;  	virtual void InitPixMap(int width, int height, Surface *surface_, WindowID wid)=0; +	virtual void SetMode(SurfaceMode mode)=0; +  	enum class Ends {  		semiCircles = 0x0,  		leftFlat = 0x1, diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 65a024565..3d0db3316 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -401,9 +401,9 @@ constexpr int stackBufferLength = 1000;  class TextWide : public VarBuffer<wchar_t, stackBufferLength> {  public:  	int tlen;	// Using int instead of size_t as most Win32 APIs take int. -	TextWide(std::string_view text, bool unicodeMode, int codePage=0) : +	TextWide(std::string_view text, int codePage) :  		VarBuffer<wchar_t, stackBufferLength>(text.length()) { -		if (unicodeMode) { +		if (codePage == SC_CP_UTF8) {  			tlen = static_cast<int>(UTF16FromUTF8(text, buffer, text.length()));  		} else {  			// Support Asian string display in 9x English @@ -440,7 +440,7 @@ int SystemMetricsForDpi(int nIndex, UINT dpi) noexcept {  }  class SurfaceGDI : public Surface { -	bool unicodeMode=false; +	SurfaceMode mode;  	HDC hdc{};  	bool hdcOwned=false;  	HPEN pen{}; @@ -457,8 +457,6 @@ class SurfaceGDI : public Surface {  	// There appears to be a 16 bit string length limit in GDI on NT.  	int maxLenText = 65535; -	int codePage = 0; -  	void PenColour(ColourAlpha fore, XYPOSITION widthStroke) noexcept;  	void BrushColour(ColourAlpha back) noexcept; @@ -479,6 +477,8 @@ public:  	void Init(SurfaceID sid, WindowID wid) override;  	void InitPixMap(int width, int height, Surface *surface_, WindowID wid) override; +	void SetMode(SurfaceMode mode_) override; +  	void Release() noexcept override;  	int Supports(int feature) noexcept override;  	bool Initialised() override; @@ -620,11 +620,14 @@ void SurfaceGDI::InitPixMap(int width, int height, Surface *surface_, WindowID w  	bitmap = ::CreateCompatibleBitmap(psurfOther->hdc, width, height);  	bitmapOld = SelectBitmap(hdc, bitmap);  	::SetTextAlign(hdc, TA_BASELINE); -	SetUnicodeMode(psurfOther->unicodeMode); -	SetDBCSMode(psurfOther->codePage); +	mode = psurfOther->mode;  	logPixelsY = DpiForWindow(wid);  } +void SurfaceGDI::SetMode(SurfaceMode mode_) { +	mode = mode_; +} +  void SurfaceGDI::PenColour(ColourDesired fore) {  	if (pen) {  		::SelectObject(hdc, penOld); @@ -1133,8 +1136,8 @@ void SurfaceGDI::DrawTextCommon(PRectangle rc, const Font *font_, XYPOSITION yba  	const int x = static_cast<int>(rc.left);  	const int yBaseInt = static_cast<int>(ybase); -	if (unicodeMode) { -		const TextWide tbuf(text, unicodeMode, codePage); +	if (mode.codePage == SC_CP_UTF8) { +		const TextWide tbuf(text, mode.codePage);  		::ExtTextOutW(hdc, x, yBaseInt, fuOptions, &rcw, tbuf.buffer, tbuf.tlen, nullptr);  	} else {  		::ExtTextOutA(hdc, x, yBaseInt, fuOptions, &rcw, text.data(), static_cast<UINT>(text.length()), nullptr); @@ -1177,8 +1180,8 @@ void SurfaceGDI::MeasureWidths(const Font *font_, std::string_view text, XYPOSIT  	int fit = 0;  	int i = 0;  	const int len = static_cast<int>(text.length()); -	if (unicodeMode) { -		const TextWide tbuf(text, unicodeMode, codePage); +	if (mode.codePage == SC_CP_UTF8) { +		const TextWide tbuf(text, mode.codePage);  		TextPositionsI poses(tbuf.tlen);  		if (!::GetTextExtentExPointW(hdc, tbuf.buffer, tbuf.tlen, maxWidthMeasure, &fit, poses.buffer, &sz)) {  			// Failure @@ -1214,10 +1217,10 @@ void SurfaceGDI::MeasureWidths(const Font *font_, std::string_view text, XYPOSIT  XYPOSITION SurfaceGDI::WidthText(const Font *font_, std::string_view text) {  	SetFont(font_);  	SIZE sz = { 0,0 }; -	if (!unicodeMode) { +	if (!(mode.codePage == SC_CP_UTF8)) {  		::GetTextExtentPoint32A(hdc, text.data(), std::min(static_cast<int>(text.length()), maxLenText), &sz);  	} else { -		const TextWide tbuf(text, unicodeMode, codePage); +		const TextWide tbuf(text, mode.codePage);  		::GetTextExtentPoint32W(hdc, tbuf.buffer, tbuf.tlen, &sz);  	}  	return static_cast<XYPOSITION>(sz.cx); @@ -1229,7 +1232,7 @@ void SurfaceGDI::DrawTextCommonUTF8(PRectangle rc, const Font *font_, XYPOSITION  	const int x = static_cast<int>(rc.left);  	const int yBaseInt = static_cast<int>(ybase); -	const TextWide tbuf(text, true); +	const TextWide tbuf(text, SC_CP_UTF8);  	::ExtTextOutW(hdc, x, yBaseInt, fuOptions, &rcw, tbuf.buffer, tbuf.tlen, nullptr);  } @@ -1269,7 +1272,7 @@ void SurfaceGDI::MeasureWidthsUTF8(const Font *font_, std::string_view text, XYP  	int fit = 0;  	int i = 0;  	const int len = static_cast<int>(text.length()); -	const TextWide tbuf(text, true); +	const TextWide tbuf(text, SC_CP_UTF8);  	TextPositionsI poses(tbuf.tlen);  	if (!::GetTextExtentExPointW(hdc, tbuf.buffer, tbuf.tlen, maxWidthMeasure, &fit, poses.buffer, &sz)) {  		// Failure @@ -1294,7 +1297,7 @@ void SurfaceGDI::MeasureWidthsUTF8(const Font *font_, std::string_view text, XYP  XYPOSITION SurfaceGDI::WidthTextUTF8(const Font *font_, std::string_view text) {  	SetFont(font_);  	SIZE sz = { 0,0 }; -	const TextWide tbuf(text, true); +	const TextWide tbuf(text, SC_CP_UTF8);  	::GetTextExtentPoint32W(hdc, tbuf.buffer, tbuf.tlen, &sz);  	return static_cast<XYPOSITION>(sz.cx);  } @@ -1353,12 +1356,12 @@ void SurfaceGDI::FlushDrawing() {  }  void SurfaceGDI::SetUnicodeMode(bool unicodeMode_) { -	unicodeMode=unicodeMode_; +	mode.codePage = unicodeMode_ ? SC_CP_UTF8 : 0;  }  void SurfaceGDI::SetDBCSMode(int codePage_) {  	// No action on window as automatically handled by system. -	codePage = codePage_; +	mode.codePage = codePage_;  }  void SurfaceGDI::SetBidiR2L(bool) { @@ -1398,10 +1401,9 @@ constexpr D2D1_RECT_F RectangleInset(D2D1_RECT_F rect, FLOAT inset) noexcept {  class BlobInline;  class SurfaceD2D : public Surface { -	bool unicodeMode; +	SurfaceMode mode;  	int x, y; -	int codePage;  	int codePageText;  	ID2D1RenderTarget *pRenderTarget; @@ -1436,6 +1438,8 @@ public:  	void Init(SurfaceID sid, WindowID wid) override;  	void InitPixMap(int width, int height, Surface *surface_, WindowID wid) override; +	void SetMode(SurfaceMode mode_) override; +  	void Release() noexcept override;  	int Supports(int feature) noexcept override;  	bool Initialised() override; @@ -1505,10 +1509,8 @@ public:  };  SurfaceD2D::SurfaceD2D() noexcept : -	unicodeMode(false),  	x(0), y(0) { -	codePage = 0;  	codePageText = 0;  	pRenderTarget = nullptr; @@ -1600,8 +1602,11 @@ void SurfaceD2D::InitPixMap(int width, int height, Surface *surface_, WindowID w  		pRenderTarget->BeginDraw();  		ownRenderTarget = true;  	} -	SetUnicodeMode(psurfOther->unicodeMode); -	SetDBCSMode(psurfOther->codePage); +	mode = psurfOther->mode; +} + +void SurfaceD2D::SetMode(SurfaceMode mode_) { +	mode = mode_;  }  HRESULT SurfaceD2D::GetBitmap(ID2D1Bitmap **ppBitmap) { @@ -1638,9 +1643,9 @@ void SurfaceD2D::SetFont(const Font *font_) noexcept {  	yAscent = pfm->yAscent;  	yDescent = pfm->yDescent;  	yInternalLeading = pfm->yInternalLeading; -	codePageText = codePage; -	if (!unicodeMode && pfm->characterSet) { -		codePageText = Scintilla::CodePageFromCharSet(pfm->characterSet, codePage); +	codePageText = mode.codePage; +	if (!(mode.codePage == SC_CP_UTF8) && pfm->characterSet) { +		codePageText = Scintilla::CodePageFromCharSet(pfm->characterSet, mode.codePage);  	}  	if (pRenderTarget) {  		D2D1_TEXT_ANTIALIAS_MODE aaMode; @@ -2411,7 +2416,7 @@ void ScreenLineLayout::FillTextLayoutFormats(const IScreenLine *screenLine, IDWr  /* Convert to a wide character string and replace tabs with X to stop DirectWrite tab expansion */  std::wstring ScreenLineLayout::ReplaceRepresentation(std::string_view text) { -	const TextWide wideText(text, true); +	const TextWide wideText(text, SC_CP_UTF8);  	std::wstring ws(wideText.buffer, wideText.tlen);  	std::replace(ws.begin(), ws.end(), L'\t', L'X');  	return ws; @@ -2602,7 +2607,7 @@ void SurfaceD2D::DrawTextCommon(PRectangle rc, const Font *font_, XYPOSITION yba  	SetFont(font_);  	// Use Unicode calls -	const TextWide tbuf(text, unicodeMode, codePageText); +	const TextWide tbuf(text, codePageText);  	if (pRenderTarget && pTextFormat && pBrush) {  		if (fuOptions & ETO_CLIPPED) {  			const D2D1_RECT_F rcClip = RectangleFromPRectangle(rc); @@ -2663,7 +2668,7 @@ void SurfaceD2D::MeasureWidths(const Font *font_, std::string_view text, XYPOSIT  		// SetFont failed or no access to DirectWrite so give up.  		return;  	} -	const TextWide tbuf(text, unicodeMode, codePageText); +	const TextWide tbuf(text, codePageText);  	TextPositions poses(tbuf.tlen);  	// Initialize poses for safety.  	std::fill(poses.buffer, poses.buffer + tbuf.tlen, 0.0f); @@ -2691,7 +2696,7 @@ void SurfaceD2D::MeasureWidths(const Font *font_, std::string_view text, XYPOSIT  		position += clusterMetrics[ci].width;  	}  	PLATFORM_ASSERT(ti == tbuf.tlen); -	if (unicodeMode) { +	if (mode.codePage == SC_CP_UTF8) {  		// Map the widths given for UTF-16 characters back onto the UTF-8 input string  		int ui=0;  		size_t i=0; @@ -2741,7 +2746,7 @@ void SurfaceD2D::MeasureWidths(const Font *font_, std::string_view text, XYPOSIT  XYPOSITION SurfaceD2D::WidthText(const Font *font_, std::string_view text) {  	FLOAT width = 1.0;  	SetFont(font_); -	const TextWide tbuf(text, unicodeMode, codePageText); +	const TextWide tbuf(text, codePageText);  	if (pIDWriteFactory && pTextFormat) {  		// Create a layout  		IDWriteTextLayout *pTextLayout = nullptr; @@ -2760,7 +2765,7 @@ void SurfaceD2D::DrawTextCommonUTF8(PRectangle rc, const Font *font_, XYPOSITION  	SetFont(font_);  	// Use Unicode calls -	const TextWide tbuf(text, true); +	const TextWide tbuf(text, SC_CP_UTF8);  	if (pRenderTarget && pTextFormat && pBrush) {  		if (fuOptions & ETO_CLIPPED) {  			D2D1_RECT_F rcClip = { rc.left, rc.top, rc.right, rc.bottom }; @@ -2821,7 +2826,7 @@ void SurfaceD2D::MeasureWidthsUTF8(const Font *font_, std::string_view text, XYP  		// SetFont failed or no access to DirectWrite so give up.  		return;  	} -	const TextWide tbuf(text, true); +	const TextWide tbuf(text, SC_CP_UTF8);  	TextPositions poses(tbuf.tlen);  	// Initialize poses for safety.  	std::fill(poses.buffer, poses.buffer + tbuf.tlen, 0.0f); @@ -2874,7 +2879,7 @@ void SurfaceD2D::MeasureWidthsUTF8(const Font *font_, std::string_view text, XYP  XYPOSITION SurfaceD2D::WidthTextUTF8(const Font * font_, std::string_view text) {  	FLOAT width = 1.0;  	SetFont(font_); -	const TextWide tbuf(text, true); +	const TextWide tbuf(text, SC_CP_UTF8);  	if (pIDWriteFactory && pTextFormat) {  		// Create a layout  		IDWriteTextLayout *pTextLayout = nullptr; @@ -2954,12 +2959,12 @@ void SurfaceD2D::FlushDrawing() {  }  void SurfaceD2D::SetUnicodeMode(bool unicodeMode_) { -	unicodeMode=unicodeMode_; +	mode.codePage = unicodeMode_ ? SC_CP_UTF8 : 0;  }  void SurfaceD2D::SetDBCSMode(int codePage_) {  	// No action on window as automatically handled by system. -	codePage = codePage_; +	mode.codePage = codePage_;  }  void SurfaceD2D::SetBidiR2L(bool) { | 
