aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa/PlatCocoa.mm
diff options
context:
space:
mode:
Diffstat (limited to 'cocoa/PlatCocoa.mm')
-rw-r--r--cocoa/PlatCocoa.mm19
1 files changed, 4 insertions, 15 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 5f9d788cd..c89a6f3aa 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -31,6 +31,7 @@
#include "StringCopy.h"
#include "XPM.h"
+#include "UniConversion.h"
#import "ScintillaView.h"
#import "ScintillaCocoa.h"
@@ -864,18 +865,6 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION yba
textLayout->draw(rc.left, ybase);
}
-static size_t utf8LengthFromLead(unsigned char uch) {
- if (uch >= (0x80 + 0x40 + 0x20 + 0x10)) {
- return 4;
- } else if (uch >= (0x80 + 0x40 + 0x20)) {
- return 3;
- } else if (uch >= (0x80)) {
- return 2;
- } else {
- return 1;
- }
-}
-
//--------------------------------------------------------------------------------------------------
void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions) {
@@ -892,10 +881,10 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION
const unsigned char *us = reinterpret_cast<const unsigned char *>(s);
int i=0;
while (ui<fit) {
- size_t lenChar = utf8LengthFromLead(us[i]);
- size_t codeUnits = (lenChar < 4) ? 1 : 2;
+ const unsigned int byteCount = UTF8BytesOfLead[us[i]];
+ const int codeUnits = UTF16LengthFromUTF8ByteCount(byteCount);
CGFloat xPosition = CTLineGetOffsetForStringIndex(mLine, ui+codeUnits, NULL);
- for (unsigned int bytePos=0; (bytePos<lenChar) && (i<len); bytePos++) {
+ for (unsigned int bytePos=0; (bytePos<byteCount) && (i<len); bytePos++) {
positions[i++] = static_cast<XYPOSITION>(xPosition);
}
ui += codeUnits;