diff options
| -rw-r--r-- | gtk/ScintillaGTK.cxx | 51 | 
1 files changed, 19 insertions, 32 deletions
| diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 831ae5d1a..25bb2a947 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -296,8 +296,6 @@ private:  	static void PreeditChanged(GtkIMContext *context, ScintillaGTK *sciThis);  	void MoveImeCarets(int pos);  	void DrawImeIndicator(int indicator, int len); -	static void GetImeUnderlines(PangoAttrList *attrs, bool *normalInput); -	static void GetImeBackgrounds(PangoAttrList *attrs, bool *targetInput);  	void SetCandidateWindowPos();  	static void StyleSetText(GtkWidget *widget, GtkStyle *previous, void*); @@ -2328,24 +2326,28 @@ void ScintillaGTK::DrawImeIndicator(int indicator, int len) {  	}  } -void ScintillaGTK::GetImeUnderlines(PangoAttrList *attrs, bool *normalInput) { -	// Whether single underlines attribute is or not -	// attr position is counted by the number of UTF-8 bytes +static std::vector<int> MapImeIndicators(PangoAttrList *attrs, const char *u8Str) { +	// Map input style to scintilla ime indicator. +	// Attrs position points between UTF-8 bytes. +	// Indicator index to be returned is character based though. +	glong charactersLen = g_utf8_strlen(u8Str, strlen(u8Str)); +	std::vector<int> indicator(charactersLen, SC_INDICATOR_UNKNOWN); +  	PangoAttrIterator *iterunderline = pango_attr_list_get_iterator(attrs);  	if (iterunderline) {  		do {  			PangoAttribute  *attrunderline = pango_attr_iterator_get(iterunderline, PANGO_ATTR_UNDERLINE);  			if (attrunderline) { -				glong start = attrunderline->start_index; -				glong end = attrunderline->end_index; +				glong start = g_utf8_strlen(u8Str, attrunderline->start_index); +				glong end = g_utf8_strlen(u8Str, attrunderline->end_index);  				PangoUnderline uline = (PangoUnderline)((PangoAttrInt *)attrunderline)->value;  				for (glong i=start; i < end; ++i) {  					switch (uline) {  					case PANGO_UNDERLINE_NONE: -						normalInput[i] = false; +						indicator[i] = SC_INDICATOR_UNKNOWN;  						break;  					case PANGO_UNDERLINE_SINGLE: // normal input -						normalInput[i] = true; +						indicator[i] = SC_INDICATOR_INPUT;  						break;  					case PANGO_UNDERLINE_DOUBLE:  					case PANGO_UNDERLINE_LOW: @@ -2357,25 +2359,22 @@ void ScintillaGTK::GetImeUnderlines(PangoAttrList *attrs, bool *normalInput) {  		} while (pango_attr_iterator_next(iterunderline));  		pango_attr_iterator_destroy(iterunderline);  	} -} -void ScintillaGTK::GetImeBackgrounds(PangoAttrList *attrs, bool *targetInput) { -	// Whether background color attribue is or not -	// attr position is measured in UTF-8 bytes  	PangoAttrIterator *itercolor = pango_attr_list_get_iterator(attrs);  	if (itercolor) {  		do {  			PangoAttribute  *backcolor = pango_attr_iterator_get(itercolor, PANGO_ATTR_BACKGROUND);  			if (backcolor) { -				glong start = backcolor->start_index; -				glong end =  backcolor->end_index; +				glong start = g_utf8_strlen(u8Str, backcolor->start_index); +				glong end = g_utf8_strlen(u8Str, backcolor->end_index);  				for (glong i=start; i < end; ++i) { -					targetInput[i] = true;  // target converted +					indicator[i] = SC_INDICATOR_TARGET;  // target converted  				}  			}  		} while (pango_attr_iterator_next(itercolor));  		pango_attr_iterator_destroy(itercolor);  	} +	return indicator;  }  void ScintillaGTK::SetCandidateWindowPos() { @@ -2456,14 +2455,10 @@ void ScintillaGTK::PreeditChangedInlineThis() {  		pdoc->TentativeStart(); // TentativeActive() from now on  		// Get preedit string attribues -		bool normalInput[maxLenInputIME*3+1] = {false}; -		bool targetInput[maxLenInputIME*3+1] = {false}; -		GetImeUnderlines(preeditStr.attrs, normalInput); -		GetImeBackgrounds(preeditStr.attrs, targetInput); +		std::vector<int> indicator = MapImeIndicators(preeditStr.attrs, preeditStr.str);  		// Display preedit characters, one by one  		glong imeCharPos[maxLenInputIME+1] = { 0 }; -		glong attrPos = 0;  		glong charWidth = 0;  		bool tmpRecordingMacro = recordingMacro; @@ -2478,19 +2473,11 @@ void ScintillaGTK::PreeditChangedInlineThis() {  			AddCharUTF(docChar.c_str(), docChar.size());  			// Draw an indicator on the character, -			// Overlapping allowed -			if (normalInput[attrPos]) { -				DrawImeIndicator(SC_INDICATOR_INPUT, docChar.size()); -			} -			if (targetInput[attrPos]) { -				DrawImeIndicator(SC_INDICATOR_TARGET, docChar.size()); -			} +			DrawImeIndicator(indicator[i], docChar.size()); - 			// Record attribute positions in UTF-8 bytes -			attrPos += u8CharLen; - 			// Record character positions in UTF-8 or DBCS bytes +			// Record character positions in UTF-8 or DBCS bytes  			charWidth += docChar.size(); - 			imeCharPos[i+1] = charWidth; +			imeCharPos[i+1] = charWidth;  		}  		recordingMacro = tmpRecordingMacro; | 
