Commit 42dceb45 authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander Trofimov

для сохранения utf-16 символов; перешел на XmlUtils::EncodeXmlString

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@58551 954022d7-b5bf-4e40-9824-e11837661b57
parent abd736ea
......@@ -48,8 +48,8 @@ namespace Writers
}
CString AddRels(CString sType, CString sTarget, bool bExternal = false)
{
SerializeCommon::CorrectString(sType);
SerializeCommon::CorrectString(sTarget);
sType = XmlUtils::EncodeXmlString(sType);
sTarget = XmlUtils::EncodeXmlString(sTarget);
CString srId;srId.Format(_T("rId%d"), m_nRid);
CString sRels;
if(bExternal)
......
......@@ -1171,8 +1171,7 @@ public:
}
if(bPStyle)
{
CString sStyleName = PStyle;
SerializeCommon::CorrectString(sStyleName);
CString sStyleName = XmlUtils::EncodeXmlString(PStyle);
CString sFormatXml;sFormatXml.Format(_T("<w:pStyle w:val=\"%s\"/>"), sStyleName);
oWriter.WriteString(sFormatXml);
}
......@@ -1197,7 +1196,7 @@ public:
sText.AppendFormat(_T("%%%d"), (item->Number+1));
}
}
SerializeCommon::CorrectString(sText);
sText = XmlUtils::EncodeXmlString(sText);
CString sTextXml;sTextXml.Format(_T("<w:lvlText w:val=\"%s\"/>"), sText);
oWriter.WriteString(sTextXml);
}
......@@ -1256,15 +1255,13 @@ public:
oWriterANum.WriteString(sANumId);
if(!StyleLink.IsEmpty())
{
CString sCorrectStyleLink = StyleLink;
SerializeCommon::CorrectString(sCorrectStyleLink);
CString sCorrectStyleLink = XmlUtils::EncodeXmlString(StyleLink);
CString sXml;sXml.Format(_T("<w:styleLink w:val=\"%s\"/>"), sCorrectStyleLink);
oWriterANum.WriteString(sXml);
}
if(!NumStyleLink.IsEmpty())
{
CString sCorrectNumStyleLink = NumStyleLink;
SerializeCommon::CorrectString(sCorrectNumStyleLink);
CString sCorrectNumStyleLink = XmlUtils::EncodeXmlString(NumStyleLink);
CString sXml;sXml.Format(_T("<w:numStyleLink w:val=\"%s\"/>"), sCorrectNumStyleLink);
oWriterANum.WriteString(sXml);
}
......@@ -1406,12 +1403,9 @@ public:
{
if(false == rId.IsEmpty())
{
CString sCorrect_rId = rId;
CString sCorrect_tooltip = tooltip;
CString sCorrect_anchor = anchor;
SerializeCommon::CorrectString(sCorrect_rId);
SerializeCommon::CorrectString(sCorrect_tooltip);
SerializeCommon::CorrectString(sCorrect_anchor);
CString sCorrect_rId = XmlUtils::EncodeXmlString(rId);
CString sCorrect_tooltip = XmlUtils::EncodeXmlString(tooltip);
CString sCorrect_anchor = XmlUtils::EncodeXmlString(anchor);
CString sStart;
sStart.Format(_T("<w:hyperlink r:id=\"%s\""), sCorrect_rId);
if(false == tooltip.IsEmpty())
......@@ -1549,8 +1543,7 @@ public:
CString sInitials;
if(false == pComment->UserName.IsEmpty())
{
CString sUserName = pComment->UserName;
SerializeCommon::CorrectString(sUserName);
CString sUserName = XmlUtils::EncodeXmlString(pComment->UserName);
sRes.AppendFormat(_T(" w:author=\"%s\""), sUserName);
// initials
int nTokenPos = 0;
......@@ -1565,13 +1558,12 @@ public:
}
if(false == pComment->Date.IsEmpty())
{
CString sDate = pComment->Date;
SerializeCommon::CorrectString(sDate);
CString sDate = XmlUtils::EncodeXmlString(pComment->Date);
sRes.AppendFormat(_T(" w:date=\"%s\""), sDate);
}
if(false == sInitials.IsEmpty())
{
SerializeCommon::CorrectString(sInitials);
sInitials = XmlUtils::EncodeXmlString(sInitials);
sRes.AppendFormat(_T(" w:initials=\"%s\""), sInitials);
}
sRes.Append(_T(">"));
......@@ -1618,10 +1610,8 @@ public:
CString sRes;
if(false == pComment->UserName.IsEmpty() && false == pComment->UserId.IsEmpty())
{
CString sUserName = pComment->UserName;
SerializeCommon::CorrectString(sUserName);
CString sUserId = pComment->UserId;
SerializeCommon::CorrectString(sUserId);
CString sUserName = XmlUtils::EncodeXmlString(pComment->UserName);
CString sUserId = XmlUtils::EncodeXmlString(pComment->UserId);
sRes.AppendFormat(_T("<w15:person w15:author=\"%s\"><w15:presenceInfo w15:providerId=\"Teamlab\" w15:userId=\"%s\"/></w15:person>"), sUserName, sUserId);
}
return sRes;
......@@ -1733,20 +1723,17 @@ public:
// sRes.AppendFormat(_T("<w:comment w:id=\"%d\""), Id);
// if(false == UserName.IsEmpty())
// {
// CString sUserName = UserName;
// SerializeCommon::CorrectString(sUserName);
// CString sUserName = XmlUtils::EncodeXmlString(UserName);
// sRes.AppendFormat(_T(" w:author=\"%s\""), sUserName);
// }
// if(false == Date.IsEmpty())
// {
// CString sDate = Date;
// SerializeCommon::CorrectString(sDate);
// CString sDate = XmlUtils::EncodeXmlString(Date);
// sRes.AppendFormat(_T(" w:date=\"%s\""), sDate);
// }
// if(false == Initials.IsEmpty())
// {
// CString sInitials = Initials;
// SerializeCommon::CorrectString(sInitials);
// CString sInitials = XmlUtils::EncodeXmlString(Initials);
// sRes.AppendFormat(_T(" w:initials=\"%s\""), sInitials);
// }
// sRes.Append(_T(">"));
......@@ -1762,13 +1749,11 @@ public:
// {
// CString sRes;
// CString sFormat = _T("<w:p><w:pPr><w:spacing w:line=\"240\" w:after=\"0\" w:lineRule=\"auto\" w:before=\"0\"/><w:ind w:firstLine=\"0\" w:left=\"0\" w:right=\"0\"/><w:jc w:val=\"left\"/></w:pPr><w:r><w:rPr><w:rFonts w:eastAsia=\"Arial\" w:ascii=\"Arial\" w:hAnsi=\"Arial\" w:cs=\"Arial\"/><w:sz w:val=\"22\"/></w:rPr><w:t xml:space=\"preserve\">%s</w:t></w:r></w:p>");
// CString sName = pComment->UserName + _T(":");
// SerializeCommon::CorrectString(sName);
// CString sName = XmlUtils::EncodeXmlString(pComment->UserName + _T(":"));
// sRes.AppendFormat(sFormat, sName);
// if(false == pComment->Text.IsEmpty())
// {
// CString sText = pComment->Text;
// SerializeCommon::CorrectString(sText);
// CString sText = XmlUtils::EncodeXmlString(pComment->Text);
// sRes.AppendFormat(sFormat, sText);
// }
// if(false == bCheckLast || pComment->replies.GetCount() > 0)
......@@ -2380,12 +2365,9 @@ public:
{
if(false == rId.IsEmpty())
{
CString sCorrect_rId = rId;
CString sCorrect_tooltip = sTooltip;
CString sCorrect_anchor = sAnchor;
SerializeCommon::CorrectString(sCorrect_rId);
SerializeCommon::CorrectString(sCorrect_tooltip);
SerializeCommon::CorrectString(sCorrect_anchor);
CString sCorrect_rId = XmlUtils::EncodeXmlString(rId);
CString sCorrect_tooltip = XmlUtils::EncodeXmlString(sTooltip);
CString sCorrect_anchor = XmlUtils::EncodeXmlString(sAnchor);
CString sStart;
sStart.Format(_T("<w:hyperlink r:id=\"%s\""), sCorrect_rId);
if(false == sTooltip.IsEmpty())
......
......@@ -244,7 +244,7 @@ public:
case c_oSerProp_rPrType::FontAscii:
{
CString sFontName(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(sFontName);
sFontName = XmlUtils::EncodeXmlString(sFontName);
if(!sFontName.IsEmpty())
{
orPr->bFontAscii = true;
......@@ -255,7 +255,7 @@ public:
case c_oSerProp_rPrType::FontHAnsi:
{
CString sFontName(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(sFontName);
sFontName = XmlUtils::EncodeXmlString(sFontName);
if(!sFontName.IsEmpty())
{
orPr->bFontHAnsi = true;
......@@ -266,7 +266,7 @@ public:
case c_oSerProp_rPrType::FontCS:
{
CString sFontName(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(sFontName);
sFontName = XmlUtils::EncodeXmlString(sFontName);
if(!sFontName.IsEmpty())
{
orPr->bFontCS = true;
......@@ -277,7 +277,7 @@ public:
case c_oSerProp_rPrType::FontAE:
{
CString sFontName(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(sFontName);
sFontName = XmlUtils::EncodeXmlString(sFontName);
if(!sFontName.IsEmpty())
{
orPr->bFontAE = true;
......@@ -658,7 +658,7 @@ public:
case c_oSerProp_pPrType::ParaStyle:
{
CString sStyleName(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(sStyleName);
sStyleName = XmlUtils::EncodeXmlString(sStyleName);
CString sStyle;sStyle.Format(_T("<w:pStyle w:val=\"%s\" />"), sStyleName);
pCStringWriter->WriteString(sStyle);
break;
......@@ -1266,7 +1266,7 @@ public:
else if( c_oSerProp_tblPrType::Style == type )
{
CString Name(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(Name);
Name = XmlUtils::EncodeXmlString(Name);
pWiterTblPr->Style.Format(_T("<w:tblStyle w:val=\"%s\"/>"), Name);
}
else if( c_oSerProp_tblPrType::Look == type )
......@@ -2069,13 +2069,13 @@ public:
if(c_oSer_sts::Style_Name == type)
{
CString Name(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(Name);
Name = XmlUtils::EncodeXmlString(Name);
odocStyle->Name = Name;
}
else if(c_oSer_sts::Style_Id == type)
{
CString Id(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(Id);
Id = XmlUtils::EncodeXmlString(Id);
odocStyle->Id = Id;
}
else if(c_oSer_sts::Style_Type == type)
......@@ -2089,13 +2089,13 @@ public:
else if(c_oSer_sts::Style_BasedOn == type)
{
CString BasedOn(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(BasedOn);
BasedOn = XmlUtils::EncodeXmlString(BasedOn);
odocStyle->BasedOn = BasedOn;
}
else if(c_oSer_sts::Style_Next == type)
{
CString NextId(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(NextId);
NextId = XmlUtils::EncodeXmlString(NextId);
odocStyle->NextId = NextId;
}
else if(c_oSer_sts::Style_qFormat == type)
......@@ -2725,7 +2725,7 @@ public:
if ( c_oSer_OMathBottomNodesValType::Val == type )
{
CString sFontName(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(sFontName);
sFontName = XmlUtils::EncodeXmlString(sFontName);
CString sVal; sVal.Format(_T("<m:font m:val=\"%s\" />"), sFontName);
m_oFileWriter.m_oSettingWriter.AddSetting(sVal);
......@@ -3033,8 +3033,7 @@ public:
m_pCurHyperlink = pHyperlink;
res = Read1(length, &Binary_DocumentTableReader::ReadParagraphContent, this, NULL);
long rId;
CString sHref = pHyperlink->sLink;
SerializeCommon::CorrectString(sHref);
CString sHref = XmlUtils::EncodeXmlString(pHyperlink->sLink);
m_oFileWriter.m_pDrawingConverter->WriteRels(CString(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink")), sHref, CString(_T("External")), &rId);
CString srId;srId.Format(_T("rId%d"), rId);
pHyperlink->rId = srId;
......@@ -4555,23 +4554,8 @@ public:
}
CString GetMathText (long length)
{
CString strRes = _T("");
CString strVal(m_oBufferedStream.GetString3(length));
for (int i = 0, length = strVal.GetLength(); i < length; ++i )
{
WCHAR sChr = strVal.GetAt(i);
if ( true == SerializeCommon::IsUnicodeSymbol( sChr ) )
{
strRes += sChr;
}
}
strRes.Replace(_T("&"), _T("&amp;"));
strRes.Replace(_T("'"), _T("&apos;"));
strRes.Replace(_T("<"), _T("&lt;"));
strRes.Replace(_T(">"), _T("&gt;"));
strRes.Replace(_T("\""),_T("&quot;"));
return strRes;
return XmlUtils::EncodeXmlString(strVal, true);
}
int ReadMathMRun(BYTE type, long length, void* poResult)
{
......@@ -5222,7 +5206,7 @@ public:
{
GetRunStringWriter().WriteString(CString(_T("<w:t xml:space=\"preserve\">")));
CString sText(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(sText);
sText = XmlUtils::EncodeXmlString(sText);
GetRunStringWriter().WriteString(sText);
GetRunStringWriter().WriteString(CString(_T("</w:t>")));
}
......@@ -5259,7 +5243,7 @@ public:
{
CString sNewImgName = m_oMediaWriter.m_aImageNames[odocImg.MediaId];
CString sNewImgRel;sNewImgRel = _T("media/") + sNewImgName;
SerializeCommon::CorrectString(sNewImgRel);
sNewImgRel = XmlUtils::EncodeXmlString(sNewImgRel);
long rId;
m_oFileWriter.m_pDrawingConverter->WriteRels(CString(_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image")), sNewImgRel, CString(), &rId);
odocImg.srId.Format(_T("rId%d"), rId);
......@@ -5330,7 +5314,7 @@ public:
else if(c_oSerRunType::fldstart == type)
{
CString sField(m_oBufferedStream.GetString3(length));
SerializeCommon::CorrectString(sField);
sField = XmlUtils::EncodeXmlString(sField);
GetRunStringWriter().WriteString(CString(_T("<w:fldChar w:fldCharType=\"begin\"/></w:r><w:r>")));
if(m_oCur_rPr.IsNoEmpty())
m_oCur_rPr.Write(&GetRunStringWriter());
......
......@@ -107,7 +107,7 @@ namespace Writers
RELEASEARRAY(psaArray);
}
SerializeCommon::CorrectString(sFontName);
sFontName = XmlUtils::EncodeXmlString(sFontName);
m_oWriter.WriteString(_T("<w:font w:name=\"") + sFontName + _T("\">"));
if(!sPanose.IsEmpty())
m_oWriter.WriteString(_T("<w:panose1 w:val=\"")+sPanose+_T("\"/>"));
......
......@@ -202,14 +202,53 @@ namespace XmlUtils
return result;
}
AVSINLINE static CString EncodeXmlString(const CString& string)
AVSINLINE static CString EncodeXmlString(const CString& string, bool bDeleteNoUnicode = false)
{
CString sResult = string;
for (unsigned int i = 0, length = sResult.GetLength(); i < length; ++i )
CString sResult;
if(bDeleteNoUnicode)
{
sResult = _T("");
for (unsigned int i = 0, length = string.GetLength(); i < length; ++i )
{
WCHAR symbol = string.GetAt(i);
if ( false == IsUnicodeSymbol( symbol ) )
{
if(0xD800 <= symbol && symbol <= 0xDFFF && i + 1 < length)
{
i++;
WCHAR symbol2 = string.GetAt(i);
if (symbol < 0xDC00 && symbol2 >= 0xDC00 && symbol2 <= 0xDFFF)
{
sResult.AppendChar(symbol);
sResult.AppendChar(symbol2);
}
}
}
else
sResult.AppendChar(symbol);
}
}
else
{
if ( false == IsUnicodeSymbol( sResult.GetAt(i) ) )
sResult = string;
for (unsigned int i = 0, length = string.GetLength(); i < length; ++i )
{
sResult.SetAt(i, ' ');
WCHAR symbol = string.GetAt(i);
if ( false == IsUnicodeSymbol( symbol ) )
{
if(0xD800 <= symbol && symbol <= 0xDFFF && i + 1 < length)
{
i++;
WCHAR symbol2 = string.GetAt(i);
if (!(symbol < 0xDC00 && symbol2 >= 0xDC00 && symbol2 <= 0xDFFF))
{
sResult.SetAt(i - 1, ' ');
sResult.SetAt(i, ' ');
}
}
else
sResult.SetAt(i, ' ');
}
}
}
sResult.Replace(_T("&"), _T("&amp;"));
......
......@@ -9,34 +9,6 @@
namespace SerializeCommon
{
bool IsUnicodeSymbol( WCHAR symbol )
{
bool result = false;
if ( ( 0x0009 == symbol ) || ( 0x000A == symbol ) || ( 0x000D == symbol ) ||
( ( 0x0020 <= symbol ) && ( 0xD7FF >= symbol ) ) || ( ( 0xE000 <= symbol ) && ( symbol <= 0xFFFD ) ) ||
( ( 0x10000 <= symbol ) && symbol ) )
{
result = true;
}
return result;
}
void CorrectString(CString& strValue)
{
for (unsigned int i = 0, length = strValue.GetLength(); i < length; ++i )
{
if ( false == IsUnicodeSymbol( strValue.GetAt(i) ) )
{
strValue.SetAt(i, ' ');
}
}
strValue.Replace(_T("&"), _T("&amp;"));
strValue.Replace(_T("'"), _T("&apos;"));
strValue.Replace(_T("<"), _T("&lt;"));
strValue.Replace(_T(">"), _T("&gt;"));
strValue.Replace(_T("\""), _T("&quot;"));
}
CString DownloadImage(const CString& strFile)
{
CFileDownloader oDownloader(strFile, FALSE);
......
......@@ -15,8 +15,6 @@
namespace SerializeCommon
{
bool IsUnicodeSymbol( WCHAR symbol );
void CorrectString(CString& strValue);
CString DownloadImage(const CString& strFile);
VOID convertBase64ToImage (CString sImage, CString &pBase64);
long Round(double val);
......
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