Commit 639f43fc authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

RtfFile linux build

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62114 954022d7-b5bf-4e40-9824-e11837661b57
parent 440f5c8d
#pragma once
#include <vector>
#include <string>
#include "IdGenerator.h"
#include "RtfDefine.h"
......@@ -57,12 +58,15 @@ public:
};
template<class T> class ItemContainer
template<class T>
class ItemContainer
{
protected:
std::vector<T> m_aArray;
public:
ItemContainer( )
protected:
std::vector<T> m_aArray;
public:
ItemContainer( )
{
}
ItemContainer( const ItemContainer& oItemContainer )
......@@ -157,31 +161,31 @@ public:
template<class T> class ItemSingleContainer: public ItemContainer<T>
{
public:
int AddItem( T piRend)
int AddItem( T piRend)
{
for( int i = 0; i < (int)m_aArray.size(); i++ )
if( m_aArray[i] == piRend )
for( int i = 0; i < ItemContainer<T>::m_aArray.size(); i++ )
if( ItemContainer<T>::m_aArray[i] == piRend )
return i;
m_aArray.push_back(piRend);
return (int)m_aArray.size() - 1;
ItemContainer<T>::m_aArray.push_back(piRend);
return (int)ItemContainer<T>::m_aArray.size() - 1;
}
};
template<class T> class ItemWithLastContainer: public ItemContainer<T>
{
public:
void RemoveItem( T piRend )
void RemoveItem( T piRend )
{
if( (int)m_aArray.size() > 1 )
if( ItemContainer<T>::m_aArray.size() > 1 )
{
ItemContainer::RemoveItem( piRend );
ItemContainer<T>::RemoveItem( piRend );
}
}
void RemoveItem( int nIndex = -1 )
void RemoveItem( int nIndex = -1 )
{
if( (int)m_aArray.size() > 1 )
if( ItemContainer<T>::m_aArray.size() > 1 )
{
ItemContainer::RemoveItem( nIndex );
ItemContainer<T>::RemoveItem( nIndex );
}
}
};
......
......@@ -273,7 +273,7 @@ bool OleReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader,CStrin
//delete oStream.lpstbl;
delete[] pData;
if( FAILED( hRes ) )
if( hRes != S_OK )
Utils::RemoveDirOrFile( sOleStorageName );
}
}
......@@ -325,7 +325,7 @@ bool ParagraphPropDestination::ExecuteCommand(RtfDocument& oDocument, RtfReader&
AddItem( m_oCurParagraph, oReader, true, false );
m_oCurParagraph = RtfParagraphPtr(new RtfParagraph());
}
else if( _T("row" == sCommand || "nestrow") == sCommand)
else if( _T("row") == sCommand || _T("nestrow") == sCommand)
{
m_oCurParagraph->m_oProperty = oReader.m_oState->m_oParagraphProp;
m_oCurParagraph->m_oOldList = RtfOldListPtr( new RtfOldList() );
......
......@@ -1078,7 +1078,7 @@ private: RtfShape& m_oShape;
CString m_sFile;
CString m_sData;
bool m_bBin;
byte* m_pbBin;
BYTE* m_pbBin;
int m_nBinLength;
public: PictureReader( RtfReader& oReader, RtfShape& oShape ):m_oShape(oShape)
{
......@@ -1802,8 +1802,9 @@ private: void TryToPepairResult( RtfDocument& oDocument, RtfReader& oReader )
return;
sResTokenize = sField.Tokenize( _T(" \""), nStartTokenize );
int nCommand = 0; //0 - none; 1 - \f; 3 - other
bool bWaitRightBreak = false;
while( sResTokenize != "" )
bool bWaitRightBreak = false;
while( sResTokenize != _T("") )
{
int nTokenLen = sResTokenize.GetLength();
if( nTokenLen > 0 && sResTokenize[0] == '\"' && sResTokenize[nTokenLen - 1] != '\"' ) //текст в кавычках считается как один
......@@ -3199,9 +3200,9 @@ public: RtfSectionCommand()
COMMAND_RTF_INT( _T("brdrart"), oReader.m_oCurSectionProp.m_nBorderArt, sCommand, hasParameter, parameter)
COMMAND_RTF_INT( _T("pgbrdropt"), oReader.m_oCurSectionProp.m_nBorderMeasure, sCommand, hasParameter, parameter)
COMMAND_RTF_BOOL( _T("pgbrdrsna"), oReader.m_oCurSectionProp.m_nBorderAlign, sCommand, hasParameter, parameter)
else if( _T("header" == sCommand || "footer" == sCommand || "headerl") == sCommand ||
_T("headerr" == sCommand || "headerf" == sCommand || "footerl") == sCommand ||
_T("footerr" == sCommand || "footerf") == sCommand )
else if( _T("header") == sCommand || _T("footer") == sCommand || _T("headerl") == sCommand ||
_T("headerr") == sCommand || _T("headerf") == sCommand || _T("footerl") == sCommand ||
_T("footerr") == sCommand || _T("footerf") == sCommand )
{
ParagraphReader oParagraphReader(sCommand, oReader);
oAbstrReader.StartSubReader( oParagraphReader, oDocument, oReader );
......@@ -3326,8 +3327,8 @@ public:
RtfMathPropReader oMathPropReader;
return StartSubReader( oMathPropReader, oDocument, oReader );
}
else if( _T("ftnsep" == sCommand || "ftnsepc") == sCommand ||
_T("aftnsep" == sCommand || "aftnsepc") == sCommand )
else if( _T("ftnsep") == sCommand || _T("ftnsepc") == sCommand ||
_T("aftnsep")== sCommand || _T("aftnsepc") == sCommand )
{
ParagraphReader oParagraphReader(sCommand, oReader);
StartSubReader( oParagraphReader, oDocument, oReader );
......
......@@ -6,7 +6,7 @@
#include <atlbase.h>
#include <atlstr.h>
#else
#include "../../Common/DocxFormat/Source/Base/ASCString.h"
#include "../../../../Common/DocxFormat/Source/Base/ASCString.h"
#endif
class IdGenerator
......@@ -143,4 +143,4 @@ public:
else
return pPair->second;
}
};
\ No newline at end of file
};
......@@ -162,7 +162,7 @@ bool OOXParagraphReader::Parse2( ReaderParameter oParam , RtfParagraph& oOutputP
RtfCharPtr oNewChar( new RtfChar() );
oNewChar->m_bRtfEncode = false;
CString sFieldText;
sFieldText.AppendFormat(_T("HYPERLINK \"%ls\""), sTarget );
sFieldText.AppendFormat(_T("HYPERLINK \"%ls\""), sTarget.GetBuffer() );
oNewChar->setText( sFieldText );
RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() );
oNewInsertParagraph->AddItem( oNewChar );
......@@ -716,7 +716,7 @@ bool OOXRunReader::Parse( ReaderParameter oParam , RtfParagraph& oOutputParagrap
int nFontSize = 10;
if( PROP_DEF != oNewProperty.m_nFontSize )
nFontSize = oNewProperty.m_nFontSize / 2;
sFieldText.AppendFormat(_T("SYMBOL %d \\\\f \"%ls\" \\\\s %d"), nChar, sFont, nFontSize );
sFieldText.AppendFormat(_T("SYMBOL %d \\\\f \"%ls\" \\\\s %d"), nChar, sFont.GetBuffer(), nFontSize );
oNewChar->setText( sFieldText );
RtfParagraphPtr oNewInsertParagraph( new RtfParagraph() );
oNewInsertParagraph->AddItem( oNewChar );
......
......@@ -111,7 +111,7 @@ public:
int res = file_inp.OpenFile(sPath);
if (res != S_OK) return false;
res = file_out.CreateFileW(sTargetFile);
res = file_out.CreateFile(sTargetFile);
if (res != S_OK) return false;
DWORD dwBytesRead = 0;
......@@ -169,4 +169,4 @@ public:
return true;
}
};
\ No newline at end of file
};
......@@ -44,7 +44,7 @@ CString RtfBookmarkStart::RenderToOOX(RenderParameter oRenderParameter)
sResult.AppendFormat(_T(" w:colFirst =\"%d\""), nID);
if( PROP_DEF != nLastColumn )
sResult.AppendFormat(_T(" w:colLast =\"%d\""), nID);
sResult.AppendFormat(_T(" w:name =\"%ls\""), Utils::PrepareToXML( m_sName ) );
sResult.AppendFormat(_T(" w:name =\"%ls\""), Utils::PrepareToXML( m_sName ).GetBuffer() );
sResult.Append(_T("/>"));
return sResult;
}
......@@ -111,7 +111,7 @@ CString RtfFootnote::RenderToOOX(RenderParameter oRenderParameter)
sResult.Append( _T("<w:r>") );
CString srPr = m_oCharProp.RenderToOOX( oRenderParameter );
if( false == srPr.IsEmpty() )
sResult.AppendFormat( _T("<w:rPr>%ls</w:rPr>"), srPr );
sResult.AppendFormat( _T("<w:rPr>%ls</w:rPr>"), srPr.GetBuffer() );
sResult.AppendFormat( _T("<w:endnoteReference w:id=\"%d\"/>"), nID );
sResult.Append( _T("</w:r>") );
}
......@@ -126,10 +126,10 @@ CString RtfFootnote::RenderToOOX(RenderParameter oRenderParameter)
sResult.Append( _T("<w:r>") );
CString srPr = m_oCharProp.RenderToOOX( oRenderParameter );
if( false == srPr.IsEmpty() )
sResult.AppendFormat( _T("<w:rPr>%ls</w:rPr>"), srPr );
sResult.AppendFormat( _T("<w:rPr>%ls</w:rPr>"), srPr.GetBuffer() );
sResult.AppendFormat( _T("<w:footnoteReference w:id=\"%d\"/>"), nID );
sResult.Append( _T("</w:r>") );
}
return sResult;
}
\ No newline at end of file
}
#include "RtfChar.h"
#include "RtfDocument.h"
CString RtfChar::renderRtfText( CString& sText, void* poDocument, RtfCharProperty* oCharProperty )
{
RtfDocument* oDocument = static_cast<RtfDocument*>(poDocument);
CString sResult;
CString RtfChar::renderRtfText( CString& sText, void* poDocument, RtfCharProperty* oCharProperty )
{
RtfDocument* oDocument = static_cast<RtfDocument*>(poDocument);
CString sResult;
int nCodePage = -1;
//применяем параметры codepage от текущего шрифта todo associated fonts.
RtfFont oFont;
if( NULL != oCharProperty && true == oDocument->m_oFontTable.GetFont( oCharProperty->m_nFont, oFont ) )
{
if( PROP_DEF != oFont.m_nCharset )
nCodePage = RtfUtility::CharsetToCodepage( oFont.m_nCharset );
else if( PROP_DEF != oFont.m_nCodePage )
nCodePage = oFont.m_nCodePage;
}
int nCodePage = -1;
//применяем параметры codepage от текущего шрифта todo associated fonts.
//todooo разобраться со шрифтами и их подбором
RtfFont oFont;
if( NULL != oCharProperty && true == oDocument->m_oFontTable.GetFont( oCharProperty->m_nFont, oFont ) )
{
if( PROP_DEF != oFont.m_nCharset )
nCodePage = RtfUtility::CharsetToCodepage( oFont.m_nCharset );
else if( PROP_DEF != oFont.m_nCodePage )
nCodePage = oFont.m_nCodePage;
}
//от настроек документа
if( -1 == nCodePage && RtfDocumentProperty::cp_none != oDocument->m_oProperty.m_eCodePage )
{
switch ( oDocument->m_oProperty.m_eCodePage )
{
case RtfDocumentProperty::cp_ansi:
{
if( PROP_DEF != oDocument->m_oProperty.m_nAnsiCodePage )
nCodePage = oDocument->m_oProperty.m_nAnsiCodePage;
else
nCodePage = CP_ACP;
break;
}
case RtfDocumentProperty::cp_mac: nCodePage = CP_MACCP;break;
case RtfDocumentProperty::cp_pc: nCodePage = 437;break;
case RtfDocumentProperty::cp_pca: nCodePage = 850;break;
}
}
//если ничего нет ставим ANSI
if( -1 == nCodePage )
nCodePage = CP_ACP;
//от настроек документа
if( -1 == nCodePage && RtfDocumentProperty::cp_none != oDocument->m_oProperty.m_eCodePage )
{
switch ( oDocument->m_oProperty.m_eCodePage )
{
case RtfDocumentProperty::cp_ansi:
{
if( PROP_DEF != oDocument->m_oProperty.m_nAnsiCodePage )
nCodePage = oDocument->m_oProperty.m_nAnsiCodePage;
else
nCodePage = CP_ACP;
break;
}
case RtfDocumentProperty::cp_mac: nCodePage = CP_MACCP;break;
case RtfDocumentProperty::cp_pc: nCodePage = 437;break;
case RtfDocumentProperty::cp_pca: nCodePage = 850;break;
}
}
//если ничего нет ставим ANSI
if( -1 == nCodePage )
nCodePage = CP_ACP;
//делаем Ansi строку
int nBufSize = ::WideCharToMultiByte(nCodePage, 0, sText, -1, NULL, 0, NULL, NULL);
CStringA sTempResultAnsi;
LPSTR pcBuffer = sTempResultAnsi.GetBuffer(nBufSize);
::WideCharToMultiByte(nCodePage, 0, sText, -1, pcBuffer, nBufSize, NULL, NULL);
sTempResultAnsi.ReleaseBuffer();
//делаем обратное преобразование чтобы понять какие символы свонвертировались неправильно
nBufSize = ::MultiByteToWideChar(nCodePage, 0, sTempResultAnsi, -1, NULL, 0);
CStringW sTempResultUni;
LPWSTR pwBuffer = sTempResultUni.GetBuffer(nBufSize);
::MultiByteToWideChar(nCodePage, 0, sTempResultAnsi, -1, pwBuffer, nBufSize);
sTempResultUni.ReleaseBuffer();
//todooo проверить !!!!!
//делаем Ansi строку
std::wstring unicodeStr(sText.GetBuffer());
for( int i = 0; i < sTempResultUni.GetLength() && i < sText.GetLength() ; i++ )
{
bool bWriteUnicode = true;
if( sTempResultUni[i] == sText[i] )
{
CString sUniChar; sUniChar.AppendChar( sText[i] );
//делаем Ansi строку
int nBufSize = ::WideCharToMultiByte(nCodePage, 0, sUniChar, -1, NULL, 0, NULL, NULL);
CStringA sTempAnsiChars;
LPSTR pcBuffer = sTempAnsiChars.GetBuffer(nBufSize);
::WideCharToMultiByte(nCodePage, 0, sUniChar, -1, pcBuffer, nBufSize, NULL, NULL);
sTempAnsiChars.ReleaseBuffer();
for( int k = 0; k < sTempAnsiChars.GetLength(); k++ )
{
unsigned char nCharCode = sTempAnsiChars[k];
bWriteUnicode = false;
//if (nCharCode == '\n') {
// sResult.Append(_T("\\line"));
//} else if (nCharCode == '\r') {
// // ignore '\r'
//} else if (nCharCode == '\t') {
// sResult.Append(_T("\\tab"));
//} else if (nCharCode <= 0xff) {
if (nCharCode == 0x5c || nCharCode == 0x7b || nCharCode == 0x7d) {
sResult.AppendFormat( _T("\\'%x"), nCharCode );
} else if (0x00 <= nCharCode && nCharCode - 1 < 0x10) {
sResult.AppendFormat(_T("\\'0%x"), nCharCode - 1 );
} else if (0x10 <= nCharCode - 1 && nCharCode < 0x20) {
sResult.AppendFormat(_T("\\'%x"), nCharCode - 1 );
} else if ( 0x20 <= nCharCode && nCharCode < 0x80 ) {
sResult.AppendChar( nCharCode );
} else { // 0x80 <= nUnicode <= 0xff
sResult.AppendFormat( _T("\\'%x"), nCharCode );
}
}
}
if( true == bWriteUnicode )
{
int nUnicode = (int)sText[i];
if (0 < nUnicode && nUnicode <= 0x8000) {
sResult.AppendFormat(_T("\\u%d*"),nUnicode);
} else if (0x8000 < nUnicode && nUnicode <= 0xffff) {
sResult.AppendFormat(_T("\\u%d*"),nUnicode - 0x10000);
} else {
sResult.Append(_T("\\u9633*"));
}
}
}
return sResult;
}
std::string ansiStr(unicodeStr.begin(), unicodeStr.end());
//делаем обратное преобразование чтобы понять какие символы свонвертировались неправильно
std::wstring unicodeStrBack(ansiStr.begin(), ansiStr.end());
for( int i = 0; i < unicodeStr.length() && i < unicodeStrBack.length() ; i++ )
{
bool bWriteUnicode = true;
if( unicodeStrBack[i] == unicodeStr[i] )
{
CString sUniChar; sUniChar.AppendChar( unicodeStr[i] );
//делаем Ansi строку sUniChar
// -> sTempAnsiChars
std::string sTempAnsiChars(unicodeStr.begin()+i, unicodeStr.begin() + i + 1);
for( int k = 0; k < sTempAnsiChars.length(); k++ )
{
unsigned char nCharCode = sTempAnsiChars[k];
bWriteUnicode = false;
if (nCharCode == 0x5c || nCharCode == 0x7b || nCharCode == 0x7d)
{
sResult.AppendFormat( _T("\\'%x"), nCharCode );
} else if (0x00 <= nCharCode && nCharCode - 1 < 0x10)
{
sResult.AppendFormat(_T("\\'0%x"), nCharCode - 1 );
} else if (0x10 <= nCharCode - 1 && nCharCode < 0x20)
{
sResult.AppendFormat(_T("\\'%x"), nCharCode - 1 );
} else if ( 0x20 <= nCharCode && nCharCode < 0x80 )
{
sResult.AppendChar( nCharCode );
} else { // 0x80 <= nUnicode <= 0xff
sResult.AppendFormat( _T("\\'%x"), nCharCode );
}
}
}
if( true == bWriteUnicode )
{
int nUnicode = (int)unicodeStr[i];
if (0 < nUnicode && nUnicode <= 0x8000)
{
sResult.AppendFormat(_T("\\u%d*"),nUnicode);
} else if (0x8000 < nUnicode && nUnicode <= 0xffff) {
sResult.AppendFormat(_T("\\u%d*"),nUnicode - 0x10000);
} else {
sResult.Append(_T("\\u9633*"));
}
}
}
return sResult;
}
......@@ -276,60 +276,66 @@ private: CString renderTextToXML( CString sParam )
{
CString sResult;
if( _T("Text") == sParam )
sResult.AppendFormat( _T("<w:t xml:space= \"preserve\">%ls</w:t>"), Utils::PrepareToXML( m_sChars ) );
{
sResult.AppendFormat( _T("<w:t xml:space= \"preserve\">%ls</w:t>"), Utils::PrepareToXML( m_sChars ).GetBuffer() );
}
else if( _T("Math") == sParam )
sResult.AppendFormat( _T("<m:t xml:space= \"preserve\">%ls</m:t>"), Utils::PrepareToXML( m_sChars ));
{
sResult.AppendFormat( _T("<m:t xml:space= \"preserve\">%ls</m:t>"), Utils::PrepareToXML( m_sChars ).GetBuffer());
}
return sResult;
}
public:
CString RenderToOOX(RenderParameter oRenderParameter)
{
CString sResult;
if(RENDER_TO_OOX_PARAM_RUN == oRenderParameter.nType)
{
sResult.Append(_T("<w:r>"));
sResult.Append(_T("<w:rPr>"));
sResult.Append( m_oProperty.RenderToOOX(oRenderParameter) );
sResult.Append(_T("</w:rPr>"));
sResult.Append( renderTextToXML(_T("Text")) );
sResult.Append(_T("</w:r>"));
}
else if(RENDER_TO_OOX_PARAM_TEXT == oRenderParameter.nType)
sResult = renderTextToXML( _T("Text") );
else if( RENDER_TO_OOX_PARAM_MATH == oRenderParameter.nType)
sResult = renderTextToXML( _T("Math") );
else if( RENDER_TO_OOX_PARAM_PLAIN == oRenderParameter.nType)
sResult = m_sChars;
return sResult;
}
public: CString RenderToOOX(RenderParameter oRenderParameter)
{
CString sResult;
if(RENDER_TO_OOX_PARAM_RUN == oRenderParameter.nType)
{
sResult.Append(_T("<w:r>"));
sResult.Append(_T("<w:rPr>"));
sResult.Append( m_oProperty.RenderToOOX(oRenderParameter) );
sResult.Append(_T("</w:rPr>"));
sResult.Append( renderTextToXML(_T("Text")) );
sResult.Append(_T("</w:r>"));
}
else if(RENDER_TO_OOX_PARAM_TEXT == oRenderParameter.nType)
sResult = renderTextToXML( _T("Text") );
else if( RENDER_TO_OOX_PARAM_MATH == oRenderParameter.nType)
sResult = renderTextToXML( _T("Math") );
else if( RENDER_TO_OOX_PARAM_PLAIN == oRenderParameter.nType)
sResult = m_sChars;
return sResult;
}
public: static CString renderRtfText( CString& sText, void* poDocument, RtfCharProperty* oCharProperty = NULL );
public: CString RenderToRtf(RenderParameter oRenderParameter)
{
CString result;
if( RENDER_TO_RTF_PARAM_CHAR == oRenderParameter.nType )
{
if( true == m_bRtfEncode )
result.Append( renderRtfText( m_sChars, oRenderParameter.poDocument, &m_oProperty ) );
else
result.Append( m_sChars );
}
else
{
CString sText;
if( true == m_bRtfEncode )
sText = renderRtfText( m_sChars, oRenderParameter.poDocument, &m_oProperty );
else
sText = m_sChars;
if( _T("") != sText )
{
result.Append(_T("{"));
result.Append( m_oProperty.RenderToRtf( oRenderParameter ) );
result.Append( _T(" ") + sText );
result.Append(_T("}"));
}
}
return result;
}
static CString renderRtfText( CString& sText, void* poDocument, RtfCharProperty* oCharProperty = NULL );
CString RenderToRtf(RenderParameter oRenderParameter)
{
CString result;
if( RENDER_TO_RTF_PARAM_CHAR == oRenderParameter.nType )
{
if( true == m_bRtfEncode )
result.Append( renderRtfText( m_sChars, oRenderParameter.poDocument, &m_oProperty ) );
else
result.Append( m_sChars );
}
else
{
CString sText;
if( true == m_bRtfEncode )
sText = renderRtfText( m_sChars, oRenderParameter.poDocument, &m_oProperty );
else
sText = m_sChars;
if( _T("") != sText )
{
result.Append(_T("{"));
result.Append( m_oProperty.RenderToRtf( oRenderParameter ) );
result.Append( _T(" ") + sText );
result.Append(_T("}"));
}
}
return result;
}
};
class RtfCharNative : public RtfChar
{
......@@ -355,4 +361,4 @@ public: CString RenderToRtf(RenderParameter oRenderParameter)
}
};
typedef boost::shared_ptr<RtfCharNative> RtfCharNativePtr;
typedef boost::shared_ptr<RtfChar> RtfCharPtr;
\ No newline at end of file
typedef boost::shared_ptr<RtfChar> RtfCharPtr;
......@@ -2,7 +2,11 @@
const long g_cdMaxPercent = 1000000;
#define PROP_DEF INT_MIN
#ifdef INT_MIN
#define PROP_DEF INT_MIN
#else
#define PROP_DEF (-0x7FFFFFFF-1)
#endif
#define RTF_MAX 1
#define RTF_MID 2
......
......@@ -179,10 +179,11 @@ public: CString RenderToRtf(RenderParameter oRenderParameter)
if( true == m_bReferenceToEndnote )
sResult.Append( _T("\\fldalt") );
if( false == m_sData.IsEmpty() )
sResult.AppendFormat( _T("{\\*\\datafield %ls}"), m_sData);
sResult.AppendFormat( _T("{\\*\\datafield %ls}"), m_sData.GetBuffer());
sResult.Append(_T("}"));
sResult.AppendFormat(_T("{\\fldrslt %ls}"), m_oResult->RenderToRtf( oRenderParameter ) );
CString str = m_oResult->RenderToRtf( oRenderParameter ) ;
sResult.AppendFormat(_T("{\\fldrslt %ls}"), str.GetBuffer());
sResult.Append(_T("}"));
return sResult;
}
......@@ -206,7 +207,7 @@ public: CString RenderToOOX(RenderParameter oRenderParameter)
{
//оставляем только одну ссылку
CString sHyperlink = sInsertText;
sHyperlink.Delete( nIndex, (int)_tcslen( _T("HYPERLINK") ) );
sHyperlink.Delete( nIndex, 9/*(int)_tcslen( _T("HYPERLINK") )*/ );
sHyperlink.Remove( '\"' );
sHyperlink.Trim();
//заменяем пробелы на %20
......@@ -216,7 +217,7 @@ public: CString RenderToOOX(RenderParameter oRenderParameter)
OOXRelsWriter* poRelsWriter = static_cast<OOXRelsWriter*>( oRenderParameter.poRels );
CString sId = poRelsWriter->AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"), Utils::PrepareToXML( sHyperlink ), false );
//добавляем гиперссылку в документ
sResult.AppendFormat( _T("<w:hyperlink r:id=\"%ls\" >"), sId );
sResult.AppendFormat( _T("<w:hyperlink r:id=\"%ls\" >"), sId.GetBuffer() );
oNewParam.nType = RENDER_TO_OOX_PARAM_RUN;
sResult.Append(m_oResult->RenderToOOX(oNewParam));
sResult.Append( _T("</w:hyperlink>") );
......@@ -228,7 +229,9 @@ public: CString RenderToOOX(RenderParameter oRenderParameter)
RenderParameter oNewParametr = oRenderParameter;
oNewParametr.nType = RENDER_TO_OOX_PARAM_PLAIN;
//sResult.Append(_T("<w:r>"));
sResult.AppendFormat(_T("<w:fldSimple w:instr=\"%ls\">"), Utils::PrepareToXML( m_oInsert->RenderToOOX(oNewParametr) ).Trim() );
CString str = Utils::PrepareToXML( m_oInsert->RenderToOOX(oNewParametr) ).Trim();
sResult.AppendFormat(_T("<w:fldSimple w:instr=\"%ls\">"), str.GetBuffer() );
RenderParameter oNewParam = oRenderParameter;
oNewParam.nType = RENDER_TO_OOX_PARAM_RUN;
sResult.Append(m_oResult->RenderToOOX(oNewParam));
......@@ -241,7 +244,10 @@ public: CString RenderToOOX(RenderParameter oRenderParameter)
RenderParameter oNewParametr = oRenderParameter;
oNewParametr.nType = RENDER_TO_OOX_PARAM_PLAIN;
sResult.Append(_T("<w:r><w:fldChar w:fldCharType=\"begin\"/></w:r>"));
sResult.AppendFormat(_T("<w:r><w:instrText xml:space=\"preserve\">%ls</w:instrText></w:r>"), Utils::PrepareToXML( m_oInsert->RenderToOOX(oNewParametr) ));
CString str = Utils::PrepareToXML( m_oInsert->RenderToOOX(oNewParametr) );
sResult.AppendFormat(_T("<w:r><w:instrText xml:space=\"preserve\">%ls</w:instrText></w:r>"), str.GetBuffer());
sResult.Append(_T("<w:r><w:fldChar w:fldCharType=\"separate\"/></w:r>"));
//заканчиваем этот параграф
sResult.Append(_T("</w:p>"));
......@@ -288,4 +294,4 @@ typedef boost::shared_ptr<RtfField> RtfFieldPtr;
typedef boost::shared_ptr<OOXFieldBegin> OOXFieldBeginPtr;
typedef boost::shared_ptr<OOXFieldInsertText> OOXFieldInsertTextPtr;
typedef boost::shared_ptr<OOXFieldSeparate> OOXFieldSeparatePtr;
typedef boost::shared_ptr<OOXFieldEnd> OOXFieldEndPtr;
\ No newline at end of file
typedef boost::shared_ptr<OOXFieldEnd> OOXFieldEndPtr;
......@@ -23,7 +23,7 @@ CString RtfFontTable::RenderToRtf(RenderParameter oRenderParameter)
RenderParameter oNewParameter = oRenderParameter;
oNewParameter.nType = RENDER_TO_RTF_PARAM_FONT_TBL;
for( int i = 0; i < (int)m_aArray.size(); i++ )
sResult.AppendFormat(_T("%ls"),m_aArray[i].RenderToRtf( oNewParameter ));
sResult.AppendFormat(_T("%ls"),m_aArray[i].RenderToRtf( oNewParameter ).GetBuffer());
sResult.Append(_T("}"));
}
return sResult;
......@@ -73,4 +73,4 @@ CString RtfListOverrideTable::RenderToOOX(RenderParameter oRenderParameter)
sResult.Append( poDocument->m_aOldLists[i]->RenderToOOX( oNewParam ) );
}
return sResult;
}
\ No newline at end of file
}
......@@ -114,7 +114,10 @@ public:
RenderParameter oNewParameter = oRenderParameter;
oNewParameter.nType = RENDER_TO_RTF_PARAM_COLOR_TBL;
for( int i = 0; i < (int)m_aArray.size(); i++ )
sResult.AppendFormat(_T("%ls"),m_aArray[i].RenderToRtf( oNewParameter ));
{
CString str = m_aArray[i].RenderToRtf( oNewParameter );
sResult.AppendFormat(_T("%ls"), str.GetBuffer());
}
sResult.Append(_T("}"));
}
return sResult;
......@@ -212,7 +215,10 @@ public:
{
sResult.Append(_T("{\\stylesheet"));
for( int i = 0; i < (int)m_aArray.size(); i++ )
sResult.AppendFormat(_T("%ls\n\n"),m_aArray[i]->RenderToRtf( oRenderParameter ));
{
CString str = m_aArray[i]->RenderToRtf( oRenderParameter );
sResult.AppendFormat(_T("%ls\n\n"), str.GetBuffer());
}
sResult.Append(_T("}"));
}
return sResult;
......@@ -341,11 +347,16 @@ public:
{
sResult.Append(_T("{\\*\\listpicture") );
for( int i = 0; i < (int)m_aPictureList.GetCount(); i++ )
{
sResult.Append( m_aPictureList[i]->RenderToRtf( oRenderParameter ) );
}
sResult.Append(_T("}") );
}
for( int i = 0; i < (int)m_aArray.size(); i++)
sResult.AppendFormat(_T("{%ls}"), m_aArray[i].RenderToRtf( oRenderParameter ) );
{
CString str = m_aArray[i].RenderToRtf( oRenderParameter );
sResult.AppendFormat(_T("{%ls}"), str.GetBuffer() );
}
sResult.Append(_T("}"));
}
return sResult;
......@@ -372,10 +383,13 @@ public:
{
sResult.Append(_T("{\\*\\listoverridetable"));
for( int i = 0; i < (int)m_aArray.size(); i++)
sResult.AppendFormat(_T("{%ls}"), m_aArray[i].RenderToRtf( oRenderParameter ) );
{
CString str = m_aArray[i].RenderToRtf( oRenderParameter );
sResult.AppendFormat(_T("{%ls}"), str.GetBuffer() );
}
sResult.Append(_T("}"));
}
return sResult;
}
CString RenderToOOX(RenderParameter oRenderParameter);
};
\ No newline at end of file
};
......@@ -11,8 +11,8 @@
class StringStream
{
private:
LONGLONG m_nSizeAbs;//размер файла
LONGLONG m_nPosAbs;//позиция в файле
LONG64 m_nSizeAbs;//размер файла
LONG64 m_nPosAbs;//позиция в файле
//CStringA m_sBuffer;
unsigned char* m_aBuffer;
......@@ -52,11 +52,11 @@ public:
dwBytesRead = srcFile.GetPosition();
srcFile.CloseFile();
}
void getBytes( int nCount, byte** pbData )
void getBytes( int nCount, BYTE** pbData )
{
if( m_nPosAbs + nCount < m_nSizeAbs )
{
(*pbData) = new byte[nCount];
(*pbData) = new BYTE[nCount];
memcpy( (*pbData), (m_aBuffer + m_nPosAbs + 1), nCount);
m_nPosAbs += nCount;
}
......@@ -97,11 +97,11 @@ public:
m_nSizeAbs += nExtBufSize;
}
LONGLONG getCurPosition()
LONG64 getCurPosition()
{
return m_nPosAbs;
}
LONGLONG getSize()
LONG64 getSize()
{
return m_nSizeAbs;
}
......@@ -121,11 +121,12 @@ public:
{
m_oFileWriter = NULL;
m_nReadBufSize = 1024 * 1024 * 5; // 5мб
m_caReadBuffer = (char*)::HeapAlloc(GetProcessHeap(), 0, m_nReadBufSize);
m_caReadBuffer = (char*)new char[m_nReadBufSize];
}
~RtfLex()
{
RELEASEHEAP( m_caReadBuffer );
if (m_caReadBuffer) delete []m_caReadBuffer;
m_caReadBuffer = NULL;
RELEASEOBJECT( m_oFileWriter );
}
double GetProgress()
......@@ -144,7 +145,7 @@ public:
{
return m_oCurToken;
}
void ReadBytes( int nCount, byte** pbData )
void ReadBytes( int nCount, BYTE** pbData )
{
m_oStream.getBytes(nCount, pbData);
}
......@@ -214,7 +215,7 @@ private:
if(c == '\\' || c == '{' || c == '}')
{
token.Type = RtfToken::Text;
token.Key = CStringA((TCHAR)c);
token.Key = (char)c;
}
else if( c > 0 && c <= 31 )
{
......@@ -296,7 +297,7 @@ private:
c = m_oStream.getc();
m_oStream.ungetc();
}
parametroInt = _ttol(parametroStr);
parametroInt = _wtoi(parametroStr.GetBuffer());
if (negativo)
parametroInt = -parametroInt;
......
......@@ -82,7 +82,7 @@ public:
if( RENDER_TO_RTF_PARAM_NESTED != oRenderParameter.nType )
sResult.Append(_T("{\\mmath"));
sResult.AppendFormat(_T("{\\%ls"), m_sRtfName);
sResult.AppendFormat(_T("{\\%ls"), m_sRtfName.GetBuffer());
RenderParameter oNewParameter = oRenderParameter;
oNewParameter.nType = RENDER_TO_RTF_PARAM_UNKNOWN;
......@@ -107,7 +107,7 @@ public:
sResult.Append(_T("}"));
if( RENDER_TO_RTF_PARAM_NESTED != oRenderParameter.nType )
sResult.AppendFormat(_T("}"), m_sRtfName);
sResult.AppendFormat(_T("}"), m_sRtfName.GetBuffer());
return sResult;
}
CString RenderToOOX(RenderParameter oRenderParameter)
......@@ -139,4 +139,4 @@ public:
}
};
typedef boost::shared_ptr<RtfMath> RtfMathPtr;
\ No newline at end of file
typedef boost::shared_ptr<RtfMath> RtfMathPtr;
......@@ -27,7 +27,7 @@ CString RtfOldList::RenderToOOX(RenderParameter oRenderParameter)
sResult.Append(_T("<w:lvl w:ilvl=\"0\">"));
sResult.Append(_T("<w:numFmt w:val=\"bullet\"/>"));
if( false == sText.IsEmpty() )
sResult.AppendFormat(_T("<w:lvlText w:val=\"%ls\"/>"), Utils::PrepareToXML( sText ) );
sResult.AppendFormat(_T("<w:lvlText w:val=\"%ls\"/>"), Utils::PrepareToXML( sText ).GetBuffer() );
else
{
sResult.Append(_T("<w:lvlText w:val=\"") );
......@@ -35,9 +35,9 @@ CString RtfOldList::RenderToOOX(RenderParameter oRenderParameter)
sResult.Append(_T("\"/>") );
}
if( false == sParProp.IsEmpty() )
sResult.AppendFormat(_T("<w:pPr>%ls</w:pPr>"), sParProp );
sResult.AppendFormat(_T("<w:pPr>%ls</w:pPr>"), sParProp.GetBuffer() );
if( false == sCharProp.IsEmpty() )
sResult.AppendFormat(_T("<w:rPr>%ls</w:rPr>"), sCharProp );
sResult.AppendFormat(_T("<w:rPr>%ls</w:rPr>"), sCharProp.GetBuffer() );
if( lj_none != m_eLevelJust )
{
switch( m_eLevelJust )
......@@ -93,4 +93,4 @@ bool RtfOldList::operator==( const RtfOldList& oOldList )
if( sText1 != sText2 )
return false;
return true;
}
\ No newline at end of file
}
......@@ -45,16 +45,16 @@ CString RtfOle::RenderToOOXOnlyOle(RenderParameter oRenderParameter)
case ot_link: sResult.Append( _T(" Type=\"Link\"") );break;
default: sResult.Append( _T(" Type=\"Embed\"") );break;
}
sResult.AppendFormat( _T(" ProgID=\"%ls\""), m_sOleClass );
sResult.AppendFormat( _T(" ShapeID=\"_x0000_s%d\""), poDocument->GetShapeId( oRenderParameter.nValue ) );
sResult.AppendFormat( _T(" ProgID=\"%ls\""), m_sOleClass.GetBuffer() );
sResult.AppendFormat( _T(" ShapeID=\"_x0000_s%d\""), poDocument->GetShapeId( oRenderParameter.nValue ) );
sResult.Append( _T(" DrawAspect=\"Content\"") );
sResult.AppendFormat( _T(" ObjectID=\"%ls\""), poDocument->m_oIdGenerator.Generate_OleId() );
sResult.AppendFormat( _T(" ObjectID=\"%ls\""), poDocument->m_oIdGenerator.Generate_OleId().GetBuffer() );
CString sExtension = _T("bin");
CString sMime = _T("application/vnd.openxmlformats-officedocument.oleObject");
CString sFilenameRels;
sFilenameRels.AppendFormat( _T("oleObject%d.%ls"), poDocument->m_oIdGenerator.Generate_OleIndex(), sExtension);
sFilenameRels.AppendFormat( _T("oleObject%d.%ls"), poDocument->m_oIdGenerator.Generate_OleIndex(), sExtension.GetBuffer());
CString sFilenameFull = poOOXWriter->m_sTargetFolder + FILE_SEPARATOR_STR + _T("word") + FILE_SEPARATOR_STR + _T("embeddings");
......@@ -66,34 +66,8 @@ CString RtfOle::RenderToOOXOnlyOle(RenderParameter oRenderParameter)
Utils::CopyDirOrFile( m_sOleFilename, sFilenameFull );
poOOXWriter->m_oContentTypes.AddExtension( sMime, sExtension);
CString srId = poRelsWriter->AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"), sFilenameRels);
sResult.AppendFormat( _T(" r:id=\"%ls\""), srId );
CString srId = poRelsWriter->AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"), sFilenameRels);
sResult.AppendFormat( _T(" r:id=\"%ls\""), srId.GetBuffer() );
sResult.Append( _T("/>") );
return sResult;
}
DWORD CALLBACK OleGet1(POLE::Stream *pStream, void FAR* pTarget, DWORD dwRead)
{
RtfOle1ToOle2Stream* piStream = static_cast<RtfOle1ToOle2Stream*>(pStream);
if( piStream->nCurPos + (int)dwRead > piStream->nBufferSize )
return 0;
memcpy( pTarget, (piStream->pBuffer + piStream->nCurPos) , dwRead );
piStream->nCurPos += dwRead;
return dwRead;
}
DWORD CALLBACK OlePut1(POLE::Stream *pStream, const void FAR* pTarget, DWORD dwRead)
{
return 0;
}
DWORD CALLBACK OleGet2(POLE::Stream *pStream, void FAR* pTarget, DWORD dwRead)
{
return 0;
}
DWORD CALLBACK OlePut2(POLE::Stream *pStream, const void FAR* pTarget, DWORD dwWrite)
{
RtfOle2ToOle1Stream* piStream = static_cast<RtfOle2ToOle1Stream*>(pStream);
BYTE* pSource = (BYTE*)pTarget;
for( int i = 0; i < (int)dwWrite; i++ )
piStream->aBuffer.push_back( pSource[i] );
return dwWrite;
}
\ No newline at end of file
......@@ -29,8 +29,8 @@ public:
}
bool IsValid()
{
return PROP_DEF != m_nWidth && PROP_DEF != m_nHeight
&& ::GetFileAttributes( m_sOleFilename ) != DWORD( -1 ) && _T("") != m_sOleFilename;
return PROP_DEF != m_nWidth && PROP_DEF != m_nHeight && _T("") != m_sOleFilename;
/*&& ::GetFileAttributes( m_sOleFilename ) != DWORD( -1 )*/
}
CString RenderToRtf(RenderParameter oRenderParameter)
{
......@@ -48,13 +48,18 @@ public:
}
RENDER_RTF_INT( m_nWidth, sResult, _T("objw") );
RENDER_RTF_INT( m_nHeight, sResult, _T("objh") );
if( _T("") != m_sOleClass )
sResult.AppendFormat( _T("{\\*\\objclass %ls}"), m_sOleClass );
if( _T("") != m_sOleClass )
sResult.AppendFormat( _T("{\\*\\objclass %ls}"), m_sOleClass.GetBuffer() );
if( _T("") != m_sOleFilename )
sResult.AppendFormat( _T("{\\*\\objdata %ls}"), RtfInternalEncoder::Encode( m_sOleFilename ) );
{
CString str = RtfUtility::RtfInternalEncoder::Encode( m_sOleFilename );
sResult.AppendFormat( _T("{\\*\\objdata %ls}"), str.GetBuffer() );
}
if( NULL != m_oResultPic )
{
sResult.AppendFormat( _T("{\\result \\pard\\plain%ls}"), m_oResultPic->RenderToRtf( oRenderParameter ) );
CString str = m_oResultPic->RenderToRtf( oRenderParameter );
sResult.AppendFormat( _T("{\\result \\pard\\plain%ls}"), str.GetBuffer() );
}
sResult.Append( _T("}") );
return sResult;
......@@ -101,7 +106,7 @@ struct RtfOle2ToOle1Stream : POLE::Stream
{
std::vector<BYTE> aBuffer;
};
DWORD CALLBACK OleGet1(POLE::Stream* oStream, void FAR* pTarget, DWORD dwRead);;
DWORD CALLBACK OlePut1(POLE::Stream*, const void FAR*, DWORD);
DWORD CALLBACK OleGet2(POLE::Stream* oStream, void FAR* pTarget, DWORD dwRead);;
DWORD CALLBACK OlePut2(POLE::Stream*, const void FAR*, DWORD);
\ No newline at end of file
//DWORD CALLBACK OleGet1(POLE::Stream* oStream, void FAR* pTarget, DWORD dwRead);;
//DWORD CALLBACK OlePut1(POLE::Stream*, const void FAR*, DWORD);
//DWORD CALLBACK OleGet2(POLE::Stream* oStream, void FAR* pTarget, DWORD dwRead);;
//DWORD CALLBACK OlePut2(POLE::Stream*, const void FAR*, DWORD);
......@@ -32,7 +32,7 @@ CString RtfPicture::GenerateWMF(RenderParameter oRenderParameter)
//сохраняем в темповую директорию и загружаем файл как текст
RtfWriter * poWriter = static_cast<RtfWriter*>( oRenderParameter.poWriter );
IUnknown* piTempPict = NULL;
//IUnknown* piTempPict = NULL;
//todooo ??? переписать
//if( true == LoadPicture( &piTempPict, m_sPicFilename ) )
......@@ -44,7 +44,7 @@ CString RtfPicture::GenerateWMF(RenderParameter oRenderParameter)
// sResult.Append( RtfInternalEncoder::Encode( sTempFile ) );
// }
//}
RELEASEINTERFACE( piTempPict );
//RELEASEINTERFACE( piTempPict );
sResult.Append(_T("}"));
return sResult;
......@@ -82,7 +82,7 @@ CString RtfPicture::RenderToRtf(RenderParameter oRenderParameter)
}
sResult.Append( _T(" "));
sResult.Append( RtfInternalEncoder::Encode( m_sPicFilename ) );
sResult.Append( RtfUtility::RtfInternalEncoder::Encode( m_sPicFilename ) );
sResult.Append(_T("}"));
return sResult;
......@@ -107,7 +107,7 @@ CString RtfPicture::RenderToOOX(RenderParameter oRenderParameter)
}
CString sFilenameRels;
sFilenameRels.AppendFormat( _T("Image%d.%ls"), poRtfDocument->m_oIdGenerator.Generate_ImageIndex(), sExtension);
sFilenameRels.AppendFormat( _T("Image%d.%ls"), poRtfDocument->m_oIdGenerator.Generate_ImageIndex(), sExtension.GetBuffer());
CString sFilenameFull = poOOXWriter->m_sTargetFolder + FILE_SEPARATOR_STR + _T("word") + FILE_SEPARATOR_STR +_T("media");
FileSystem::Directory::CreateDirectory( sFilenameFull );
......@@ -197,4 +197,4 @@ CString RtfPicture::RenderToOOX(RenderParameter oRenderParameter)
// //piImageFile->SaveImage2( &m_piPicture, IMAGEFORMAT_PNG, bstrFilePath);
// //SysFreeString( bstrFilePath );
// return true;
//}
\ No newline at end of file
//}
......@@ -89,9 +89,8 @@ public:
{
BYTE pBuffer[ 16 ];
DWORD dwBytesRead = 0;
HANDLE hFile;
CFile file;
CFile file;
if (file.OpenFile(sFilename) != S_OK) return dt_none;
file.ReadFile(pBuffer, 16);
......@@ -135,4 +134,4 @@ public:
return dt_none;
}
};
typedef boost::shared_ptr<RtfPicture> RtfPicturePtr;
\ No newline at end of file
typedef boost::shared_ptr<RtfPicture> RtfPicturePtr;
......@@ -6,13 +6,19 @@
#include "../../../Common/DocxFormat/Source/Common/SimpleTypes_Drawing.h"
#define MERGE_PROPERTY(propName, propObj)\
if( PROP_DEF != ##propObj##.##propName## )\
propName = ##propObj##.##propName##;
#if defined (_WIN32) || defined (_WIN64)
#define MERGE_PROPERTY(propName, propObj)\
if( PROP_DEF != ##propObj##.##propName## ) propName = ##propObj##.##propName##;
#define MERGE_PROPERTY_DEF(propName, propObj, defval)\
if( defval != ##propObj##.##propName## )\
propName = ##propObj##.##propName##;
#define MERGE_PROPERTY_DEF(propName, propObj, defval)\
if( defval != ##propObj##.##propName## ) propName = ##propObj##.##propName##;
#else
#define MERGE_PROPERTY(propName, propObj)\
if( PROP_DEF != propObj.propName ) propName = propObj.propName;
#define MERGE_PROPERTY_DEF(propName, propObj, defval)\
if( defval != propObj.propName ) propName = propObj.propName;
#endif
#define DEFAULT_PROPERTY(propName)\
propName= PROP_DEF;
......@@ -127,11 +133,11 @@ public:
typedef enum {TC_NONE,cmaindarkone ,cmainlightone ,cmaindarktwo ,cmainlighttwo ,caccentone ,caccenttwo ,caccentthree ,caccentfour ,caccentfive ,caccentsix ,chyperlink ,cfollowedhyperlink ,cbackgroundone ,ctextone ,cbackgroundtwo ,ctexttwo} ThemeColor;
ThemeColor m_eTheme;
byte m_byteRed;
byte m_byteGreen;
byte m_byteBlue;
byte m_byteTint;
byte m_byteShade;
BYTE m_byteRed;
BYTE m_byteGreen;
BYTE m_byteBlue;
BYTE m_byteTint;
BYTE m_byteShade;
RtfColor()
{
......@@ -141,7 +147,7 @@ public:
{
SetHEX( nHex );
}
RtfColor(byte r, byte g, byte b)
RtfColor(BYTE r, BYTE g, BYTE b)
{
SetRGB( r, g, b );
}
......@@ -162,21 +168,21 @@ public:
m_byteShade = 0;
m_eTheme = TC_NONE;
}
byte GetR()
BYTE GetR()
{
byte byteRed = SetShade( m_byteRed );
BYTE byteRed = SetShade( m_byteRed );
byteRed = SetTint( byteRed );
return byteRed;
}
byte GetG()
BYTE GetG()
{
byte byteGreen = SetShade( m_byteGreen );
BYTE byteGreen = SetShade( m_byteGreen );
byteGreen = SetTint( byteGreen );
return byteGreen;
}
byte GetB()
BYTE GetB()
{
byte byteBlue = SetShade( m_byteBlue );
BYTE byteBlue = SetShade( m_byteBlue );
byteBlue = SetTint( byteBlue );
return byteBlue;
}
......@@ -193,7 +199,7 @@ public:
m_byteGreen = (color&0xFF00) >>4;
m_byteBlue = (color&0xFF);
}
void SetRGB(byte red, byte green, byte blue)
void SetRGB(BYTE red, BYTE green, BYTE blue)
{
SetDefault();
m_byteRed = red;
......@@ -261,12 +267,12 @@ public:
break;
}
}
m_byteRed = (byte)(r * 255.0f);
m_byteGreen = (byte)(g * 255.0f);
m_byteBlue = (byte)(b * 255.0f);
m_byteRed = (byte)(r * 255);
m_byteGreen = (byte)(g * 255);
m_byteBlue = (byte)(b * 255);
m_byteRed = (BYTE)(r * 255.0f);
m_byteGreen = (BYTE)(g * 255.0f);
m_byteBlue = (BYTE)(b * 255.0f);
m_byteRed = (BYTE)(r * 255);
m_byteGreen = (BYTE)(g * 255);
m_byteBlue = (BYTE)(b * 255);
}
void SetRGBPercent(int nRedPer, int nGreenPer, int nBluePer)
{
......@@ -289,21 +295,21 @@ public:
}
CString ToHexColor()
{
byte byteRed = SetShade( m_byteRed );
BYTE byteRed = SetShade( m_byteRed );
byteRed = SetTint( byteRed );
CString sRed;
if( byteRed < 0x10 )
sRed.AppendFormat( _T("0%x"), byteRed );
else
sRed.AppendFormat( _T("%x"), byteRed );
byte byteGreen = SetShade( m_byteGreen );
BYTE byteGreen = SetShade( m_byteGreen );
byteGreen = SetTint( byteGreen );
CString sGreen;
if( byteGreen < 0x10 )
sGreen.AppendFormat( _T("0%x"), byteGreen );
else
sGreen.AppendFormat( _T("%x"), byteGreen );
byte byteBlue = SetShade( m_byteBlue );
BYTE byteBlue = SetShade( m_byteBlue );
byteBlue = SetTint( byteBlue );
CString sBlue;
if( byteBlue < 0x10 )
......@@ -316,11 +322,11 @@ public:
int ToInt()const
{
CString sResult;
byte byteRed = SetShade( m_byteRed );
BYTE byteRed = SetShade( m_byteRed );
byteRed = SetTint( byteRed );
byte byteGreen = SetShade( m_byteGreen );
BYTE byteGreen = SetShade( m_byteGreen );
byteGreen = SetTint( byteGreen );
byte byteBlue = SetShade( m_byteBlue );
BYTE byteBlue = SetShade( m_byteBlue );
byteBlue = SetTint( byteBlue );
int nColor = (byteRed << 16) | (byteGreen << 8) | byteBlue;
......@@ -328,14 +334,14 @@ public:
}
CString RenderToRtf(RenderParameter oRenderParameter);
CString RenderToOOX(RenderParameter oRenderParameter);
byte SetShade(byte bColor)const
BYTE SetShade(BYTE bColor)const
{
//return (byte)( ( 1.0 - m_byteShade / 255 ) * bColor );
//return (BYTE)( ( 1.0 - m_byteShade / 255 ) * bColor );
return bColor;
}
byte SetTint(byte bColor)const
BYTE SetTint(BYTE bColor)const
{
//return (byte)( ( 1.0 - m_byteTint / 255 ) * ( 255 - bColor ) + bColor );
//return (BYTE)( ( 1.0 - m_byteTint / 255 ) * ( 255 - bColor ) + bColor );
return bColor;
}
static bool GetHighlightByColor( RtfColor oOutputColor,CString& oStr ) //todo
......@@ -578,7 +584,7 @@ public:
//CString white = _T("FFFFFF");
//CString yellow = _T("FFFF00");
long nMinDelta = MAXLONG;
long nMinDelta = 0x7FFFFFFF; //MAXLONG;
int nIndex = -1;
for( int i = 0; i < (int)sColors.size(); i++ )
{
......@@ -616,20 +622,31 @@ private:
CString WriteOOXAttribute( CString sParam )
{
CString sResult;
if( m_eTheme == TC_NONE )
if( _T("") == sParam )
sResult.AppendFormat(_T("color = \"%ls\""),ToHexColor());
else if( _T("Fill") == sParam )
sResult.AppendFormat(_T("fill = \"%ls\""),ToHexColor());
else
{
CString sTheme;
if( true == GetStringByTheme( sTheme, m_eTheme ) )
{
sResult.AppendFormat(_T("theme%sColor = \"%ls\" theme%sShade = \"%d\" theme%sTint = \"%d\""),sParam,sTheme,sParam,m_byteShade ,sParam,m_byteTint);
}
}
return sResult;
if( m_eTheme == TC_NONE )
{
if( _T("") == sParam )
{
sResult = _T("color = \"");
sResult.Append(ToHexColor());
sResult.Append(_T("\""));
}
else if( _T("Fill") == sParam )
{
sResult = _T("fill = \"");
sResult.Append(ToHexColor());
sResult.Append(_T("\""));
}
}
else
{
CString sTheme;
if( true == GetStringByTheme( sTheme, m_eTheme ) )
{
sResult.AppendFormat(_T("theme%sColor = \"%ls\" theme%sShade = \"%d\" theme%sTint = \"%d\""),
sParam.GetBuffer(), sTheme.GetBuffer(), sParam.GetBuffer(), m_byteShade ,sParam.GetBuffer(), m_byteTint);
}
}
return sResult;
}
};
......@@ -950,7 +967,7 @@ public:
for( int i = 0; i < (int)m_aTabs.size(); i++ )
sTabs.Append( m_aTabs[i].RenderToOOX( oRenderParameter ) );
if( false == sTabs.IsEmpty() )
sResult.AppendFormat( _T("<w:tabs>%ls</w:tabs>"), sTabs );
sResult.AppendFormat( _T("<w:tabs>%ls</w:tabs>"), sTabs.GetBuffer() );
return sResult;
}
};
......@@ -3224,4 +3241,4 @@ typedef boost::shared_ptr<RtfShadingPar> RtfShadingParPtr;
typedef boost::shared_ptr<RtfShading> RtfShadingPtr;
typedef boost::shared_ptr<RtfColor> RtfColorPtr;
typedef boost::shared_ptr<RtfFont> RtfFontPtr;
//typedef boost::shared_ptr<RtfColorSchemeMapping> RtfColorSchemeMappingPtr;
\ No newline at end of file
//typedef boost::shared_ptr<RtfColorSchemeMapping> RtfColorSchemeMappingPtr;
......@@ -104,7 +104,7 @@ public:
break;
case RtfToken::Keyword:
ExecuteTextInternal2(oDocument, oReader, m_oTok.Key, m_nSkipChars);
if( _T("u") == m_oTok.Key )
if( m_oTok.Key == "u")
{
ExecuteText( oDocument, oReader, ExecuteTextInternal( oDocument, oReader, m_oTok.Key, m_oTok.HasParameter, m_oTok.Parameter, m_nSkipChars) );
break;
......@@ -124,9 +124,9 @@ public:
m_bCanStartNewReader = false;
break;
case RtfToken::Control:
if( m_oTok.Key == _T("42") )
if( m_oTok.Key == "42" )
m_bSkip = true;
if( m_oTok.Key == _T("39") && true == m_oTok.HasParameter )
if( m_oTok.Key == "39" && true == m_oTok.HasParameter )
oReader.m_oState->m_sCurText.AppendChar( m_oTok.Parameter );
break;
case RtfToken::Text:
......@@ -206,7 +206,7 @@ public:
{
CString sResult;
if( _T("u") == sKey )
if( "u" == sKey )
{
if( true == bHasPar )
sResult.AppendChar( nPar );
......@@ -214,7 +214,7 @@ public:
else
{
CStringA sCharString;
if( _T("39") == sKey )
if( "39" == sKey )
{
if( true == bHasPar )
sCharString.AppendChar( nPar );
......@@ -236,7 +236,8 @@ public:
oReader.m_oState->m_sCurText.Empty();
if(sResult.GetLength() > 0)
{
ExecuteTextInternalSkipChars(sResult, oReader, CStringA(""), nSkipChars);
CStringA str;
ExecuteTextInternalSkipChars(sResult, oReader, str, nSkipChars);
ExecuteText( oDocument, oReader, sResult);
}
}
......@@ -258,7 +259,7 @@ public:
nSkipChars = 0;
}
}
if( _T("u") == sKey )
if( "u" == sKey )
{
//надо правильно установить m_nSkipChars по значению \ucN
nSkipChars = oReader.m_oState->m_nUD;
......@@ -292,19 +293,25 @@ public:
nCodepage = CP_ACP;
break;
}
case RtfDocumentProperty::cp_mac: nCodepage = CP_MACCP;break;
case RtfDocumentProperty::cp_pc: nCodepage = 437;break;
case RtfDocumentProperty::cp_pca: nCodepage = 850;break;
case RtfDocumentProperty::cp_mac: nCodepage = CP_MACCP; break;
case RtfDocumentProperty::cp_pc: nCodepage = 437; break; //ms dos latin us
case RtfDocumentProperty::cp_pca: nCodepage = 850; break; //ms dos latin eu
}
}
//если ничего нет ставим ANSI
if( -1 == nCodepage )
nCodepage = CP_ACP;
int nLengthW ;
nLengthW = MultiByteToWideChar(nCodepage, 0, sCharString, -1, NULL, NULL);
MultiByteToWideChar(nCodepage, 0, sCharString, -1, sResult.GetBuffer( nLengthW ), nLengthW);
sResult.ReleaseBuffer();
#if defined (_WIN32) || defined (_WIN64)
int nLengthW ;
nLengthW = MultiByteToWideChar(nCodepage, 0, sCharString, -1, NULL, NULL);
MultiByteToWideChar(nCodepage, 0, sCharString, -1, sResult.GetBuffer( nLengthW ), nLengthW);
sResult.ReleaseBuffer();
#else
//todooo расширить до других codepages (щас тока анси)
std::string sAnsi(sCharString.GetBuffer());
std::wstring s(sAnsi.begin(), sAnsi.end());
#endif
//sResult = sKey;
}
return sResult;
......
......@@ -124,12 +124,13 @@ public:
m_nZoom = 100;
//вычисляем стандартный default ansi codepage для системы
TCHAR codepage[7];
int nRes = GetLocaleInfo( LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, codepage, 6 );
if( nRes != 0 )
#if defined (_WIN32) || defined(_WIN64)
TCHAR codepage[7];
if( GetLocaleInfo( LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE, codepage, 6 ) != 0)
m_nAnsiCodePage = _ttoi(codepage);
else
m_nAnsiCodePage = CP_ACP;
#endif
m_nAnsiCodePage = CP_ACP;
m_bDorderSurroundHeader = PROP_DEF;
m_bDorderSurroundFotter = PROP_DEF;
......@@ -616,4 +617,4 @@ public: RtfSectionProperty m_oProperty;
return _T("");
}
};
typedef boost::shared_ptr<RtfSection> RtfSectionPtr;
\ No newline at end of file
typedef boost::shared_ptr<RtfSection> RtfSectionPtr;
......@@ -156,7 +156,7 @@ CString RtfShape::RenderToRtfShapeProperty(RenderParameter oRenderParameter)
sResult.AppendFormat( _T("{\\sp{\\sn colSpan}{\\sv %d}}"),m_nColSpan);
//Rehydration
if( _T("") != m_sMetroBlob )
sResult.AppendFormat( _T("{\\sp{\\sn metroBlob}{\\sv %d}}"),m_sMetroBlob);
sResult.AppendFormat( _T("{\\sp{\\sn metroBlob}{\\sv %d}}"),m_sMetroBlob.GetBuffer());
//Object Type
if( PROP_DEF != m_bIsBullet )
......@@ -335,7 +335,7 @@ CString RtfShape::RenderToOOX(RenderParameter oRenderParameter)
sResult.Append( _T("<pic:cNvPicPr><a:picLocks noChangeAspect=\"1\" noChangeArrowheads=\"1\"/></pic:cNvPicPr>") );
sResult.Append( _T("</pic:nvPicPr>") );
sResult.AppendFormat( _T("<pic:blipFill><a:blip r:embed=\"%ls\"/>"), m_oPicture->RenderToOOX(oRenderParameter) );
sResult.AppendFormat( _T("<pic:blipFill><a:blip r:embed=\"%ls\"/>"), m_oPicture->RenderToOOX(oRenderParameter).GetBuffer() );
CString sCrop;
if( PROP_DEF != nCropLeft )
sCrop.AppendFormat( _T(" l=\"%d\""), nCropLeft ); //тысячный доли процента
......@@ -346,7 +346,7 @@ CString RtfShape::RenderToOOX(RenderParameter oRenderParameter)
if( PROP_DEF != nCropBottom )
sCrop.AppendFormat( _T(" b=\"%d\""), nCropBottom );
if( false == sCrop.IsEmpty() )
sResult.AppendFormat( _T("<a:srcRect %ls/>"), sCrop );
sResult.AppendFormat( _T("<a:srcRect %ls/>"), sCrop.GetBuffer() );
sResult.Append( _T("<a:stretch><a:fillRect/></a:stretch>") );
sResult.Append( _T("</pic:blipFill>") );
if( PROP_DEF != m_oPicture->m_nWidthGoal && PROP_DEF != m_oPicture->m_nHeightGoal )
......@@ -561,7 +561,7 @@ CString RtfShape::RenderToOOX(RenderParameter oRenderParameter)
for( int i = 2; i < (int)m_aWrapPoints.size() - 1; i+=2 )
sResult.AppendFormat( _T("<wp:lineTo x=\"%d\" y=\"%d\" />"), m_aWrapPoints[i], m_aWrapPoints[i+1] );
sResult.Append( _T("</wp:wrapPolygon>") );
sResult.AppendFormat( _T("</%ls>"), sTag );
sResult.AppendFormat( _T("</%ls>"), sTag.GetBuffer() );
}
}
int nImageID = poDocument->m_oIdGenerator.Generate_ImagePropId();
......@@ -599,7 +599,7 @@ CString RtfShape::RenderToOOX(RenderParameter oRenderParameter)
sResult.Append( _T("<pic:cNvPicPr><a:picLocks noChangeAspect=\"1\" noChangeArrowheads=\"1\"/></pic:cNvPicPr>") );
sResult.Append( _T("</pic:nvPicPr>") );
sResult.AppendFormat( _T("<pic:blipFill><a:blip r:embed=\"%ls\"/>"), m_oPicture->RenderToOOX(oRenderParameter) );
sResult.AppendFormat( _T("<pic:blipFill><a:blip r:embed=\"%ls\"/>"), m_oPicture->RenderToOOX(oRenderParameter).GetBuffer() );
CString sCrop;
if( PROP_DEF != nCropLeft )
sCrop.AppendFormat( _T(" l=\"%d\""), nCropLeft ); //тысячный доли процента
......@@ -610,7 +610,7 @@ CString RtfShape::RenderToOOX(RenderParameter oRenderParameter)
if( PROP_DEF != nCropBottom )
sCrop.AppendFormat( _T(" b=\"%d\""), nCropBottom );
if( false == sCrop.IsEmpty() )
sResult.AppendFormat( _T("<a:srcRect %ls/>"), sCrop );
sResult.AppendFormat( _T("<a:srcRect %ls/>"), sCrop.GetBuffer() );
sResult.Append( _T("<a:stretch><a:fillRect/></a:stretch>") );
sResult.Append( _T("</pic:blipFill>") );
......@@ -720,7 +720,7 @@ CString RtfShape::RenderToOOXBegin(RenderParameter oRenderParameter)
if( _T("") == oRenderParameter.sValue )
sResult.Append( _T("<v:shape") );
else
sResult.AppendFormat( _T("<%ls"),oRenderParameter.sValue );
sResult.AppendFormat( _T("<%ls"),oRenderParameter.sValue.GetBuffer() );
sResult.AppendFormat( _T(" id=\"_x0000_s%d\""), poDocument->GetShapeId( m_nID ) );
if( PROP_DEF != m_nShapeType )
......@@ -922,7 +922,7 @@ CString RtfShape::RenderToOOXBegin(RenderParameter oRenderParameter)
if( false == sStyle.IsEmpty() )
{
sStyle.Delete( sStyle.GetLength() - 1 );
sResult.AppendFormat( _T(" style=\"%ls\""),sStyle );
sResult.AppendFormat( _T(" style=\"%ls\""),sStyle.GetBuffer() );
}
if( PROP_DEF != m_bLayoutInCell )
......@@ -982,7 +982,7 @@ CString RtfShape::RenderToOOXBegin(RenderParameter oRenderParameter)
}
}
}
sResult.AppendFormat( _T(" adj=\"%ls\""),sAdjust );
sResult.AppendFormat( _T(" adj=\"%ls\""),sAdjust.GetBuffer() );
}
//Geometry
if( m_aWrapPoints.size() > 0 )
......@@ -1098,7 +1098,7 @@ CString RtfShape::RenderToOOXBegin(RenderParameter oRenderParameter)
}
}
if( false == sStroke.IsEmpty() )
sResult.AppendFormat( _T("<v:stroke %ls/>"), sStroke );
sResult.AppendFormat( _T("<v:stroke %ls/>"), sStroke.GetBuffer() );
if( 0 != m_aTextItems )
{
......@@ -1138,7 +1138,7 @@ CString RtfShape::RenderToOOXBegin(RenderParameter oRenderParameter)
CString sPicture = m_oPicture->RenderToOOX(oRenderParameter);
if( _T("") == sPicture )//если не сохранилась картинка, то весь shape будет бесполезным
return _T("");
sResult.AppendFormat( _T("<v:imagedata r:id=\"%ls\""), sPicture );
sResult.AppendFormat( _T("<v:imagedata r:id=\"%ls\""), sPicture.GetBuffer() );
if( PROP_DEF != nCropLeft )
sResult.AppendFormat( _T(" cropleft=\"%df\""), nCropLeft );
if( PROP_DEF != nCropTop )
......@@ -1157,7 +1157,7 @@ CString RtfShape::RenderToOOXEnd(RenderParameter oRenderParameter)
if( _T("") == oRenderParameter.sValue )
sResult.Append( _T("</v:shape>") );
else
sResult.AppendFormat( _T("</%ls>"), oRenderParameter.sValue );
sResult.AppendFormat( _T("</%ls>"), oRenderParameter.sValue.GetBuffer() );
if( RENDER_TO_OOX_PARAM_SHAPE_WSHAPE2 == oRenderParameter.nType )
;
else if( RENDER_TO_OOX_PARAM_SHAPE_WSHAPE == oRenderParameter.nType )
......@@ -1182,4 +1182,4 @@ CString RtfShapeGroup::RenderToOOX(RenderParameter oRenderParameter)
sResult.Append( m_aArray[i]->RenderToOOX( oNewParamShape ) );
sResult.Append( RenderToOOXEnd( oNewParamGroup ) );
return sResult;
}
\ No newline at end of file
}
......@@ -4,7 +4,7 @@
#include <atlbase.h>
#include <atlstr.h>
#else
#include "../../Common/DocxFormat/Source/Base/ASCString.h"
#include "../../../../Common/DocxFormat/Source/Base/ASCString.h"
#endif
class RtfToken
......@@ -24,4 +24,4 @@ public:
HasParameter = false;
Parameter = 0;
}
};
\ No newline at end of file
};
......@@ -95,7 +95,7 @@ bool RtfWriter::SaveByItem()
oNewParam.nType = RENDER_TO_OOX_PARAM_FIRST_SECTION;
}
sRtf = m_oDocument[0]->m_oProperty.RenderToRtf(oNewParam);
RtfInternalEncoder::Decode( sRtf, *m_oCurTempFileSectWriter );
RtfUtility::RtfInternalEncoder::Decode( sRtf, *m_oCurTempFileSectWriter );
//дописываем в файл
RELEASEOBJECT( m_oCurTempFileSectWriter );
//создаем новый
......@@ -121,7 +121,7 @@ bool RtfWriter::SaveByItem()
sRtf.Append( _T("\\par") );
//oNewParam.nValue = RENDER_TO_RTF_PARAM_NO_PAR;
}
RtfInternalEncoder::Decode( sRtf, *m_oCurTempFileWriter );
RtfUtility::RtfInternalEncoder::Decode( sRtf, *m_oCurTempFileWriter );
//m_oTempFileWriter->Write( (BYTE*)(LPCSTR)sRtf, sRtf.GetLength() );
//удаляем элемент который только что написали
......@@ -152,7 +152,7 @@ bool RtfWriter::SaveByItemEnd()
oNewParam.nType = RENDER_TO_OOX_PARAM_FIRST_SECTION;
}
sRtf = m_oDocument[0]->m_oProperty.RenderToRtf(oNewParam);
RtfInternalEncoder::Decode( sRtf, *m_oCurTempFileSectWriter );
RtfUtility::RtfInternalEncoder::Decode( sRtf, *m_oCurTempFileSectWriter );
//дописываем в файл
RELEASEOBJECT( m_oCurTempFileSectWriter );
}
......@@ -171,7 +171,7 @@ bool RtfWriter::SaveByItemEnd()
//пишем заголовок потом все содежимое
sRtf = CreateRtfStart();
DWORD dwBytesWrite = 0;
RtfInternalEncoder::Decode( sRtf, oTargetFileWriter );
RtfUtility::RtfInternalEncoder::Decode( sRtf, oTargetFileWriter );
//WriteFile ( hTargetFile, sRtf, ( DWORD ) sRtf.GetLength(), &dwBytesWrite, NULL );
//копируем заголовки из массива и параграфы из темповых файлов
......@@ -215,8 +215,8 @@ bool RtfWriter::SaveByItemEnd()
//завершаем документ
sRtf = CreateRtfEnd();
RtfInternalEncoder::Decode( sRtf, oTargetFileWriter );
byte nEndFile = 0;
RtfUtility::RtfInternalEncoder::Decode( sRtf, oTargetFileWriter );
BYTE nEndFile = 0;
oTargetFileWriter.Write( &nEndFile, 1);
}
catch(...)
......@@ -265,25 +265,25 @@ CString RtfWriter::CreateRtfStart()
{
sFootnote = m_oDocument.m_oFootnoteSep->RenderToRtf( oRenderParameter );
if( _T("") != sFootnote )
sResult.AppendFormat( _T("{\\*\\ftnsep %ls}"), sFootnote );
sResult.AppendFormat( _T("{\\*\\ftnsep %ls}"), sFootnote.GetBuffer() );
}
if( NULL != m_oDocument.m_oFootnoteCon )
{
sFootnote = m_oDocument.m_oFootnoteCon->RenderToRtf( oRenderParameter );
if( _T("") != sFootnote )
sResult.AppendFormat( _T("{\\*\\ftnsepc %ls}"), sFootnote );
sResult.AppendFormat( _T("{\\*\\ftnsepc %ls}"), sFootnote.GetBuffer() );
}
if( NULL != m_oDocument.m_oEndnoteSep )
{
sFootnote = m_oDocument.m_oEndnoteSep->RenderToRtf( oRenderParameter );
if( _T("") != sFootnote )
sResult.AppendFormat( _T("{\\*\\aftnsep %ls}"), sFootnote );
sResult.AppendFormat( _T("{\\*\\aftnsep %ls}"), sFootnote.GetBuffer() );
}
if( NULL != m_oDocument.m_oEndnoteCon )
{
sFootnote = m_oDocument.m_oEndnoteCon->RenderToRtf( oRenderParameter );
if( _T("") != sFootnote )
sResult.AppendFormat( _T("{\\*\\aftnsepc %ls}"), sFootnote );
sResult.AppendFormat( _T("{\\*\\aftnsepc %ls}"), sFootnote.GetBuffer() );
}
sResult.Append(_T("\n\n"));
......
......@@ -64,26 +64,4 @@ public:
sResult.Replace(_T("'"), _T("&apos;"));
return sResult;
}
//static CStringA UnicodeToCodepage( CStringW sUni, UINT nCodepage = CP_UTF8 )
//{
// CStringA sUtf;
// int nBufSize = WideCharToMultiByte(nCodepage, 0, sUni, -1, NULL, NULL, NULL, NULL);
// LPSTR pBuff = new CHAR[ nBufSize + 1 ];
// WideCharToMultiByte(nCodepage, 0, sUni, -1, pBuff, nBufSize, NULL, NULL);
// pBuff[ nBufSize ] = 0;
// sUtf.Append( pBuff );
// delete pBuff;
// return sUtf;
//}
//public: static CStringW CodepageToUnicode( CStringA sUtf, UINT nCodepage = CP_UTF8 )
// {
// CStringW sUni;
// int nBufSize = MultiByteToWideChar(nCodepage, 0, sUtf, -1, NULL, NULL);
// LPWSTR pBuff = new WCHAR[ nBufSize + 1 ];
// MultiByteToWideChar(nCodepage, 0, sUtf, -1, pBuff, nBufSize);
// pBuff[ nBufSize ] = 0;
// sUni.Append( pBuff );
// delete pBuff;
// return sUni;
// }
};
......@@ -27,13 +27,13 @@ public:
{
CFile file;
if (file.CreateFileW(sFolder + FILE_SEPARATOR_STR + _T("[Content_Types].xml")) != S_OK) return false;
if (file.CreateFile(sFolder + FILE_SEPARATOR_STR + _T("[Content_Types].xml")) != S_OK) return false;
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );//todooo UTF32 !!!
file.WriteFile( sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml.GetBuffer());
file.WriteFile((void*)sXmlUTF.c_str(), sXmlUTF.length());
file.CloseFile();
return true;
......@@ -57,11 +57,11 @@ private:
sResult.Append( _T("<Default Extension=\"xml\" ContentType=\"application/xml\"/>") );
for( int i = 0; i < (int)m_aExtensions.size(); i++ )
sResult.AppendFormat( _T("<Default Extension=\"%ls\" ContentType=\"%ls\"/>"), m_aExtensions[i], m_aExtTypes[i]);
sResult.AppendFormat( _T("<Default Extension=\"%ls\" ContentType=\"%ls\"/>"), m_aExtensions[i].GetBuffer(), m_aExtTypes[i].GetBuffer());
for( int i = 0; i < (int)m_aTargets.size(); i++ )
sResult.AppendFormat( _T("<Override PartName=\"%ls\" ContentType=\"%ls\"/>"), m_aTargets[i], m_aTypes[i]);
sResult.AppendFormat( _T("<Override PartName=\"%ls\" ContentType=\"%ls\"/>"), m_aTargets[i].GetBuffer(), m_aTypes[i].GetBuffer());
sResult.Append( _T("</Types>") );
return sResult;
}
};
\ No newline at end of file
};
......@@ -23,15 +23,17 @@ public:
if( false == m_sFileXml.IsEmpty() )
{
CFile file;
if (file.CreateFileW(pathWord + FILE_SEPARATOR_STR + _T("fontTable.xml"))) return false;
if (file.CreateFile(pathWord + FILE_SEPARATOR_STR + _T("fontTable.xml"))) return false;
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"), _T("fontTable.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"), _T("/word/fontTable.xml") );
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
std::wstring sXml = CreateXml();
std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml);
file.WriteFile((void*)sXmlUTF.c_str(), sXmlUTF.length());
file.CloseFile();
return true;
}
......@@ -47,14 +49,16 @@ public:
}
private:
CString m_sFileXml;
OOXWriter& m_oWriter;
CString CreateXml()
OOXWriter& m_oWriter;
std::wstring CreateXml()
{
CString sResult;
sResult.Append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") );
sResult.Append( _T("<w:fonts xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">") );
sResult.Append( m_sFileXml );
sResult.Append( _T("</w:fonts>") );
std::wstring sResult;
sResult.append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") );
sResult.append( _T("<w:fonts xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">") );
sResult.append( m_sFileXml.GetBuffer() );
sResult.append( _T("</w:fonts>") );
return sResult;
}
};
\ No newline at end of file
};
......@@ -16,7 +16,7 @@ public:
CString sFootnote;
sFootnote.Append( _T("<w:footnote") );
if( false == sType.IsEmpty() )
sFootnote.AppendFormat( _T(" w:type=\"%ls\""), sType );
sFootnote.AppendFormat( _T(" w:type=\"%ls\""), sType.GetBuffer() );
if( PROP_DEF != nID )
sFootnote.AppendFormat( _T(" w:id=\"%d\""), nID );
sFootnote.Append( _T(">") );
......@@ -29,7 +29,7 @@ public:
{
m_sFootnotes.Append( _T("<w:footnote") );
if( false == sType.IsEmpty() )
m_sFootnotes.AppendFormat( _T(" w:type=\"%ls\""), sType );
m_sFootnotes.AppendFormat( _T(" w:type=\"%ls\""), sType.GetBuffer() );
if( PROP_DEF != nID )
m_sFootnotes.AppendFormat( _T(" w:id=\"%d\""), nID );
m_sFootnotes.Append( _T(">") );
......@@ -41,23 +41,27 @@ public:
if( m_sFootnotes.IsEmpty() ) return false;
CFile file;
if (file.CreateFileW(sFolder + FILE_SEPARATOR_STR + _T("footnotes.xml"))) return false;
if (file.CreateFile(sFolder + FILE_SEPARATOR_STR + _T("footnotes.xml"))) return false;
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"), _T("footnotes.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"), _T("/word/footnotes.xml") );
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml.GetBuffer());
file.WriteFile((void*)sXmlUTF.c_str(), sXmlUTF.length());
file.CloseFile();
return true;
}
private:
RtfDocument& m_oDocument;
OOXWriter& m_oWriter;
CString m_sFootnotes;
CString CreateXml()
CString m_sFootnotes;
CString CreateXml()
{
CString sResult;
sResult.Append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>") );
......@@ -83,7 +87,7 @@ public:
CString sEndnote;
sEndnote.Append( _T("<w:endnote") );
if( false == sType.IsEmpty() )
sEndnote.AppendFormat( _T(" w:type=\"%ls\""), sType );
sEndnote.AppendFormat( _T(" w:type=\"%ls\""), sType.GetBuffer() );
if( -2 != nID )
sEndnote.AppendFormat( _T(" w:id=\"%d\""), nID );
sEndnote.Append( _T(">") );
......@@ -96,7 +100,7 @@ public:
{
m_sEndnotes.Append( _T("<w:endnote") );
if( false == sType.IsEmpty() )
m_sEndnotes.AppendFormat( _T(" w:type=\"%ls\""), sType );
m_sEndnotes.AppendFormat( _T(" w:type=\"%ls\""), sType.GetBuffer() );
if( -2 != nID )
m_sEndnotes.AppendFormat( _T(" w:id=\"%d\""), nID );
m_sEndnotes.Append( _T(">") );
......@@ -108,14 +112,14 @@ public:
if( m_sEndnotes.IsEmpty() ) return false;
CFile file;
if (file.CreateFileW(sFolder + FILE_SEPARATOR_STR + _T("endnotes.xml"))) return false;
if (file.CreateFile(sFolder + FILE_SEPARATOR_STR + _T("endnotes.xml"))) return false;
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"), _T("endnotes.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"), _T("/word/endnotes.xml") );
CStringA sXml = CreateXml();
std::string sXml = CreateXml();
file.WriteFile(sXml.GetBuffer(), sXml.GetLength());
file.WriteFile((void*)sXml.c_str(), sXml.length());
file.CloseFile();
return true;
}
......@@ -123,14 +127,15 @@ private:
RtfDocument& m_oDocument;
OOXWriter& m_oWriter;
CString m_sEndnotes;
CStringA CreateXml()
std::string CreateXml()
{
CString sResult;
sResult.Append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>") );
sResult.AppendChar('\n');
sResult.Append( _T("<w:endnotes xmlns:wpc=\"http://schemas.microsoft.com/office/word/2008/6/28/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2008/9/16/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2009/2/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2008/6/28/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2008/6/28/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2008/6/28/wordprocessingShape\" >") );
sResult.Append( m_sEndnotes );
sResult.Append( _T("</w:endnotes>") );
return Convert::UnicodeToUtf8( sResult);
std::wstring sResult;
sResult.append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>") );
sResult.append( _T("<w:endnotes xmlns:wpc=\"http://schemas.microsoft.com/office/word/2008/6/28/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2008/9/16/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2009/2/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2008/6/28/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2008/6/28/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2008/6/28/wordprocessingShape\" >") );
sResult.append( m_sEndnotes.GetBuffer() );
sResult.append( _T("</w:endnotes>") );
return NSFile::CUtf8Converter::GetUtf8StringFromUnicode( sResult);
}
};
\ No newline at end of file
};
......@@ -23,17 +23,16 @@ public:
{
CFile file;
if (file.CreateFileW(sFolder + FILE_SEPARATOR_STR + _T("word") + FILE_SEPARATOR_STR + _T("numbering.xml")) != S_OK) return false;
if (file.CreateFile(sFolder + FILE_SEPARATOR_STR + _T("word") + FILE_SEPARATOR_STR + _T("numbering.xml")) != S_OK) return false;
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"), _T("numbering.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"), _T("/word/numbering.xml") );
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
file.CloseFile();
std::wstring sXml = CreateXml();
std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml);
file.WriteFile((void*)sXmlUTF.c_str(), sXmlUTF.length());
file.CloseFile();
return true;
}
......@@ -45,15 +44,17 @@ public:
}
private:
CString m_sFileXml;
OOXWriter& m_oWriter;
CString CreateXml()
OOXWriter& m_oWriter;
std::wstring CreateXml()
{
CString sResult;
sResult.Append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") );
sResult.Append( _T("\n") );
sResult.Append( _T("<w:numbering xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\">") );
sResult.Append( m_sFileXml );
sResult.Append( _T("</w:numbering>") );
std::wstring sResult;
sResult.append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") );
sResult.append( _T("\n") );
sResult.append( _T("<w:numbering xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\">") );
sResult.append( m_sFileXml.GetBuffer() );
sResult.append( _T("</w:numbering>") );
return sResult;
}
};
\ No newline at end of file
};
......@@ -38,7 +38,7 @@ public:
sResult.Append( _T("<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">") );
for( int i = 0; i < (int)m_aTargets.size(); i++ )
{
sResult.AppendFormat( _T("<Relationship Id=\"%ls\" Type=\"%ls\" Target=\"%ls\""), m_aIDs[i], m_aTypes[i], m_aTargets[i]);
sResult.AppendFormat( _T("<Relationship Id=\"%ls\" Type=\"%ls\" Target=\"%ls\""), m_aIDs[i].GetBuffer(), m_aTypes[i].GetBuffer(), m_aTargets[i].GetBuffer());
if( false == m_aModes[i] )
sResult.Append( _T(" TargetMode=\"External\"") );
sResult.Append( _T("/>") );
......@@ -52,16 +52,17 @@ public:
if( m_aTargets.size() < 1 )return false;
CString pathRels = sFolder + FILE_SEPARATOR_STR + _T("_rels");
FileSystem::Directory::CreateDirectoryW(pathRels) ;
FileSystem::Directory::CreateDirectory(pathRels) ;
CFile file;
if (file.CreateFileW(pathRels + FILE_SEPARATOR_STR + m_sFileName + _T(".rels"))) return false;
if (file.CreateFile(pathRels + FILE_SEPARATOR_STR + m_sFileName + _T(".rels"))) return false;
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml.GetBuffer());
file.WriteFile((void*)sXmlUTF.c_str(), sXmlUTF.length());
file.CloseFile();
}
};
typedef boost::shared_ptr<OOXRelsWriter> OOXRelsWriterPtr;
\ No newline at end of file
typedef boost::shared_ptr<OOXRelsWriter> OOXRelsWriterPtr;
......@@ -26,16 +26,16 @@ public:
if( false == m_sFileXml.IsEmpty() )
{
CFile file;
if (file.CreateFileW(pathWord + FILE_SEPARATOR_STR + _T("styles.xml"))) return false;
if (file.CreateFile(pathWord + FILE_SEPARATOR_STR + _T("styles.xml"))) return false;
m_oWriter.m_oDocRels.AddRelationship( _T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"), _T("styles.xml") );
m_oWriter.m_oContentTypes.AddContent( _T("application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"), _T("/word/styles.xml") );
DWORD dwBytesWritten;
CString sXml = CreateXml();
CStringA sXmlUTF = Convert::UnicodeToUtf8( sXml );
std::wstring sXml = CreateXml();
std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml);
file.WriteFile((void*)sXmlUTF.c_str(), sXmlUTF.length());
file.WriteFile(sXmlUTF.GetBuffer(), sXmlUTF.GetLength());
file.CloseFile();
return true;
}
......@@ -49,14 +49,14 @@ private:
CString m_sFileXml;
OOXWriter& m_oWriter;
CString CreateXml()
std::wstring CreateXml()
{
CString sResult;
sResult.Append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") );
sResult.Append( _T("\n") );
sResult.Append( _T("<w:styles xmlns:w = \"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">") );
sResult.Append( m_sFileXml );
sResult.Append( _T("</w:styles>") );
std::wstring sResult;
sResult.append( _T("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>") );
sResult.append( _T("\n") );
sResult.append( _T("<w:styles xmlns:w = \"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">") );
sResult.append( m_sFileXml.GetBuffer() );
sResult.append( _T("</w:styles>") );
return sResult;
}
};
\ No newline at end of file
};
......@@ -19,11 +19,11 @@ namespace NFileWriter
// ( )
virtual void Flush () = 0;
//
virtual void Seek ( LONG64 lPosition, DWORD dwFrom = FILE_CURRENT ) = 0;
virtual void Seek ( LONG64 lPosition, DWORD dwFrom = 0 ) = 0;
//
virtual void GetPosition(ULONGLONG& nPos) = 0;
virtual void GetPosition(ULONG64& nPos) = 0;
//
virtual void GetSize(ULONGLONG& nLen) = 0;
virtual void GetSize(ULONG64& nLen) = 0;
public :
......@@ -109,7 +109,7 @@ namespace NFileWriter
while ( 0 >= ( lBufferFreeLength = m_lBufferSize - m_lWritePointer ) )
{
// , ,
if ( FALSE == WriteBuffer ( m_lBufferSize ) )
if ( false == WriteBuffer ( m_lBufferSize ) )
throw 1;
}
......@@ -135,7 +135,7 @@ namespace NFileWriter
if ( 0 < m_lWritePointer )
{
// ,
if ( FALSE == WriteBuffer ( m_lWritePointer ) )
if ( false == WriteBuffer ( m_lWritePointer ) )
throw 1;
}
}
......@@ -156,13 +156,13 @@ namespace NFileWriter
}
//
virtual void GetPosition(ULONGLONG& nPos)
virtual void GetPosition(ULONG64& nPos)
{
nPos = m_oFile.GetPosition() + m_lWritePointer;
}
//
virtual void GetSize(ULONGLONG& nLen)
virtual void GetSize(ULONG64& nLen)
{
nLen = m_oFile.GetFileSize() + m_lWritePointer;
......@@ -170,17 +170,17 @@ namespace NFileWriter
private :
//
BOOL WriteBuffer ( LONG64 lSize )
bool WriteBuffer ( LONG64 lSize )
{
//
if (m_oFile.WriteFile(m_lpBuffer, ( DWORD ) lSize) != S_OK)
{
// - , FALSE
return FALSE;
return false;
}
// 0
m_lWritePointer = 0;
return TRUE;
return true;
}
};
}
\ No newline at end of file
}
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