Commit 24c1af56 authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

utf-16 символы на открытие и copy/paste

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58546 954022d7-b5bf-4e40-9824-e11837661b57
parent 15189e6f
...@@ -14,6 +14,28 @@ function fSortAscending( a, b ) { ...@@ -14,6 +14,28 @@ function fSortAscending( a, b ) {
function fSortDescending( a, b ) { function fSortDescending( a, b ) {
return b - a; return b - a;
} }
function isLeadingSurrogateChar(nCharCode) {
return (nCharCode >= 0xD800 && nCharCode <= 0xDFFF);
}
function decodeSurrogateChar(nLeadingChar, nTrailingChar) {
if (nLeadingChar < 0xDC00 && nTrailingChar >= 0xDC00 && nTrailingChar <= 0xDFFF)
return 0x10000 + ((nLeadingChar & 0x3FF) << 10) | (nTrailingChar & 0x3FF);
else
return null;
}
function encodeSurrogateChar(nUnicode) {
if(nUnicode < 0x10000)
{
return String.fromCharCode(nUnicode);
}
else
{
nUnicode = nUnicode - 0x10000;
var nLeadingChar = 0xD800 | (nUnicode >> 10);
var nTrailingChar = 0xDC00 | (nUnicode & 0x3FF);
return String.fromCharCode(nLeadingChar) + String.fromCharCode(nTrailingChar);
}
}
/** /**
* @constructor * @constructor
......
...@@ -560,7 +560,7 @@ CopyProcessor.prototype = ...@@ -560,7 +560,7 @@ CopyProcessor.prototype =
{ {
case para_Text: case para_Text:
//���������� ����������� //���������� �����������
var sValue = String.fromCharCode(ParaItem.Value); var sValue = encodeSurrogateChar(ParaItem.Value);
if(sValue) if(sValue)
sRes += CopyPasteCorrectString(sValue); sRes += CopyPasteCorrectString(sValue);
break; break;
...@@ -5602,14 +5602,27 @@ PasteProcessor.prototype = ...@@ -5602,14 +5602,27 @@ PasteProcessor.prototype =
this._commit_rPr(oTargetNode, bUseOnlyInherit); this._commit_rPr(oTargetNode, bUseOnlyInherit);
for(var i = 0, length = value.length; i < length; i++) for(var i = 0, length = value.length; i < length; i++)
{ {
var Char = value.charAt(i); var nUnicode = null;
var Code = value.charCodeAt(i); var nCharCode = value.charCodeAt(i);
if (isLeadingSurrogateChar(nCharCode)) {
if (i + 1 < length) {
i++;
var nTrailingChar = value.charCodeAt(i);
nUnicode = decodeSurrogateChar(nCharCode, nTrailingChar);
}
}
else
nUnicode = nCharCode;
if (null != nUnicode) {
var Item; var Item;
if(32 == Code || 160 == Code) //160 - nbsp if (0x20 != nUnicode && 0xA0 != nUnicode) {
Item = new ParaSpace(); Item = new ParaText();
Item.Value = nUnicode;
}
else else
Item = new ParaText( value[i] ); Item = new ParaSpace();
this._Paragraph_Add( Item ); this._Paragraph_Add(Item);
}
} }
} }
} }
...@@ -5968,15 +5981,28 @@ PasteProcessor.prototype = ...@@ -5968,15 +5981,28 @@ PasteProcessor.prototype =
} }
for(var i = 0, length = value.length; i < length; i++) for(var i = 0, length = value.length; i < length; i++)
{ {
var Char = value.charAt(i); var nUnicode = null;
var Code = value.charCodeAt(i); var nCharCode = value.charCodeAt(i);
if (isLeadingSurrogateChar(nCharCode)) {
if (i + 1 < length) {
i++;
var nTrailingChar = value.charCodeAt(i);
nUnicode = decodeSurrogateChar(nCharCode, nTrailingChar);
}
}
else
nUnicode = nCharCode;
if (null != nUnicode) {
var Item; var Item;
if(32 == Code || 160 == Code) //160 - nbsp if (0x20 != nUnicode && 0xA0 != nUnicode) {
Item = new ParaSpace(); Item = new ParaText();
Item.Value = nUnicode;
}
else else
Item = new ParaText( value[i] ); Item = new ParaSpace();
shape.paragraphAdd(Item); shape.paragraphAdd(Item);
} }
}
} }
} }
......
...@@ -3748,7 +3748,7 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap, copyPa ...@@ -3748,7 +3748,7 @@ function BinaryDocumentTableWriter(memory, doc, oMapCommentId, oNumIdMap, copyPa
switch ( item.Type ) switch ( item.Type )
{ {
case para_Text: case para_Text:
sCurText += String.fromCharCode(item.Value); sCurText += encodeSurrogateChar(item.Value);
break; break;
case para_Space: case para_Space:
sCurText += " "; sCurText += " ";
...@@ -7543,13 +7543,31 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, bAllow ...@@ -7543,13 +7543,31 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, bAllow
} }
for (var i = 0; i < text.length; ++i) for (var i = 0; i < text.length; ++i)
{ {
if (text[i] != ' ') var nUnicode = null;
oPos.run.Add_ToContent(oPos.pos, new ParaText(text[i]), false); var nCharCode = text.charCodeAt(i);
if (isLeadingSurrogateChar(nCharCode))
{
if(i + 1 < text.length)
{
i++;
var nTrailingChar = text.charCodeAt(i);
nUnicode = decodeSurrogateChar(nCharCode, nTrailingChar);
}
}
else
nUnicode = nCharCode;
if (null != nUnicode) {
if (0x20 != nUnicode) {
var oNewParaText = new ParaText();
oNewParaText.Value = nUnicode;
oPos.run.Add_ToContent(oPos.pos, oNewParaText, false);
}
else else
oPos.run.Add_ToContent(oPos.pos, new ParaSpace(), false); oPos.run.Add_ToContent(oPos.pos, new ParaSpace(), false);
oPos.pos++; oPos.pos++;
} }
} }
}
else if (c_oSerRunType.tab === type) else if (c_oSerRunType.tab === type)
{ {
oNewElem = new ParaTab(); oNewElem = new ParaTab();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment