Commit 597414ea authored by ElenaSubbotina's avatar ElenaSubbotina

DocFormatFile - fix users file (1995) without codepage

parent 7f06ce70
...@@ -47,30 +47,17 @@ namespace DocFileFormat ...@@ -47,30 +47,17 @@ namespace DocFileFormat
virtual ~ConversionContext() virtual ~ConversionContext()
{ {
} }
// Adds a new RSID to the set
inline void AddRsid(const std::wstring& rsid) inline void AddRsid(const std::wstring& rsid)
{ {
if (AllRsids.find(rsid) == AllRsids.end()) if (AllRsids.find(rsid) == AllRsids.end())
AllRsids.insert(rsid); AllRsids.insert(rsid);
} }
inline WordDocument* GetDocument()
{
return _doc;
}
inline WordprocessingDocument* GetXmlDocument()
{
return _docx;
}
public:
WordprocessingDocument* _docx; WordprocessingDocument* _docx;
WordDocument* _doc; WordDocument* _doc;
/// A set thta contains all revision ids.
std::set<std::wstring> AllRsids; std::set<std::wstring> AllRsids;
}; };
} }
\ No newline at end of file
...@@ -63,8 +63,16 @@ namespace DocFileFormat ...@@ -63,8 +63,16 @@ namespace DocFileFormat
{ {
long Converter::Convert(WordDocument* doc, WordprocessingDocument* docx, const ProgressCallback* progress) long Converter::Convert(WordDocument* doc, WordprocessingDocument* docx, const ProgressCallback* progress)
{ {
if (!doc || !docx) return S_FALSE;
ConversionContext context( doc, docx ); ConversionContext context( doc, docx );
//Write fontTable.xml
if (doc->FontTable)
{
FontTableMapping fontTableMapping( &context );
doc->FontTable->Convert( &fontTableMapping );
}
//Write styles.xml //Write styles.xml
if (doc->Styles) if (doc->Styles)
{ {
...@@ -107,14 +115,6 @@ namespace DocFileFormat ...@@ -107,14 +115,6 @@ namespace DocFileFormat
return S_FALSE; return S_FALSE;
} }
} }
//Write fontTable.xml
if (doc->FontTable)
{
FontTableMapping fontTableMapping( &context );
doc->FontTable->Convert( &fontTableMapping );
}
if ( progress != NULL ) if ( progress != NULL )
{ {
progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 875000 ); progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 875000 );
......
...@@ -48,7 +48,8 @@ namespace DocFileFormat ...@@ -48,7 +48,8 @@ namespace DocFileFormat
class FontFamilyName: public ByteStructure class FontFamilyName: public ByteStructure
{ {
friend class CharacterPropertiesMapping; friend class WordDocument;
friend class CharacterPropertiesMapping;
friend class DocumentMapping; friend class DocumentMapping;
friend class FontTableMapping; friend class FontTableMapping;
friend class StyleSheetMapping; friend class StyleSheetMapping;
......
...@@ -34,32 +34,30 @@ ...@@ -34,32 +34,30 @@
namespace DocFileFormat namespace DocFileFormat
{ {
FontTableMapping::FontTableMapping( ConversionContext* ctx ): AbstractOpenXmlMapping( new XMLTools::CStringXmlWriter() ) FontTableMapping::FontTableMapping( ConversionContext* ctx ) : AbstractOpenXmlMapping( new XMLTools::CStringXmlWriter() )
{ {
_ctx = ctx; _ctx = ctx;
} }
/*========================================================================================================*/
FontTableMapping::~FontTableMapping() FontTableMapping::~FontTableMapping()
{ {
RELEASEOBJECT (m_pXmlWriter); RELEASEOBJECT (m_pXmlWriter);
} }
/*========================================================================================================*/
void FontTableMapping::Apply( IVisitable* visited ) void FontTableMapping::Apply( IVisitable* visited )
{ {
StringTable<FontFamilyName>* table = static_cast<StringTable<FontFamilyName>*>( visited ); StringTable<FontFamilyName>* table = static_cast<StringTable<FontFamilyName>*>( visited );
this->_ctx->_docx->RegisterFontTable(); _ctx->_docx->RegisterFontTable();
m_pXmlWriter->WriteNodeBegin( L"?xml version=\"1.0\" encoding=\"UTF-8\"?" ); m_pXmlWriter->WriteNodeBegin( L"?xml version=\"1.0\" encoding=\"UTF-8\"?" );
m_pXmlWriter->WriteNodeBegin( L"w:fonts", TRUE ); m_pXmlWriter->WriteNodeBegin( L"w:fonts", TRUE );
m_pXmlWriter->WriteAttribute( L"xmlns:w", OpenXmlNamespaces::WordprocessingML ); m_pXmlWriter->WriteAttribute( L"xmlns:w", OpenXmlNamespaces::WordprocessingML );
m_pXmlWriter->WriteNodeEnd( L"", TRUE, FALSE ); m_pXmlWriter->WriteNodeEnd( L"", TRUE, FALSE );
int sz_fonts = table->Data.size(); int sz_fonts = table->Data.size();
int users_fonts = 0; int users_fonts = 0;
for ( std::vector<ByteStructure*>::iterator iter = table->Data.begin(); iter != table->Data.end(); iter++ ) for ( std::vector<ByteStructure*>::iterator iter = table->Data.begin(); iter != table->Data.end(); iter++ )
...@@ -140,6 +138,6 @@ namespace DocFileFormat ...@@ -140,6 +138,6 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( L"w:fonts"); m_pXmlWriter->WriteNodeEnd( L"w:fonts");
this->_ctx->_docx->FontTableXML = std::wstring( m_pXmlWriter->GetXmlString() ); _ctx->_docx->FontTableXML = m_pXmlWriter->GetXmlString() ;
} }
} }
...@@ -38,8 +38,8 @@ namespace DocFileFormat ...@@ -38,8 +38,8 @@ namespace DocFileFormat
{ {
if (m_context) if (m_context)
{ {
m_document = m_context->GetDocument(); m_document = m_context->_doc;
m_xmldocument = m_context->GetXmlDocument(); m_xmldocument = m_context->_docx;
} }
} }
......
...@@ -41,6 +41,7 @@ namespace DocFileFormat ...@@ -41,6 +41,7 @@ namespace DocFileFormat
{ {
template<class T> class StringTable: public IVisitable template<class T> class StringTable: public IVisitable
{ {
friend class WordDocument;
friend class CharacterPropertiesMapping; friend class CharacterPropertiesMapping;
friend class FontTableMapping; friend class FontTableMapping;
friend class StyleSheetMapping; friend class StyleSheetMapping;
......
...@@ -40,8 +40,45 @@ ...@@ -40,8 +40,45 @@
#include "../../DesktopEditor/common/File.h" #include "../../DesktopEditor/common/File.h"
#include "../../DesktopEditor/common/Directory.h" #include "../../DesktopEditor/common/Directory.h"
#include <unordered_map>
namespace DocFileFormat namespace DocFileFormat
{ {
static const int aCodePages[][2] = {
//charset codepage
0, 1252, //ANSI
1, 0,//Default
2, 42,//Symbol
77, 10000,//Mac Roman
78, 10001,//Mac Shift Jis
79, 10003,//Mac Hangul
80, 10008,//Mac GB2312
81, 10002,//Mac Big5
83, 10005,//Mac Hebrew
84, 10004,//Mac Arabic
85, 10006,//Mac Greek
86, 10081,//Mac Turkish
87, 10021,//Mac Thai
88, 10029,//Mac East Europe
89, 10007,//Mac Russian
128, 932,//Shift JIS
129, 949,//Hangul
130, 1361,//Johab
134, 936,//GB2312
136, 950,//Big5
238, 1250,//Greek
161, 1253,//Greek
162, 1254,//Turkish
163, 1258,//Vietnamese
177, 1255,//Hebrew
178, 1256, //Arabic
186, 1257,//Baltic
204, 1251,//Russian
222, 874,//Thai
238, 1250,//Eastern European
254, 437,//PC 437
255, 850//OEM
};
WordDocument::WordDocument (const ProgressCallback* pCallFunc, const std::wstring & sTempFolder ) : WordDocument::WordDocument (const ProgressCallback* pCallFunc, const std::wstring & sTempFolder ) :
m_PieceTable(NULL), WordDocumentStream(NULL), TableStream(NULL), DataStream(NULL), FIB(NULL), m_PieceTable(NULL), WordDocumentStream(NULL), TableStream(NULL), DataStream(NULL), FIB(NULL),
Text(NULL), RevisionAuthorTable(NULL), FontTable(NULL), BookmarkNames(NULL), AutoTextNames(NULL), Text(NULL), RevisionAuthorTable(NULL), FontTable(NULL), BookmarkNames(NULL), AutoTextNames(NULL),
...@@ -55,12 +92,15 @@ namespace DocFileFormat ...@@ -55,12 +92,15 @@ namespace DocFileFormat
AnnotationOwners(NULL), DocProperties(NULL), listFormatOverrideTable(NULL), headerAndFooterTable(NULL), AnnotationOwners(NULL), DocProperties(NULL), listFormatOverrideTable(NULL), headerAndFooterTable(NULL),
AnnotStartPlex(NULL), AnnotEndPlex(NULL), encryptionHeader(NULL) AnnotStartPlex(NULL), AnnotEndPlex(NULL), encryptionHeader(NULL)
{ {
m_pCallFunc = pCallFunc; m_pCallFunc = pCallFunc;
m_sTempFolder = sTempFolder; m_sTempFolder = sTempFolder;
m_pStorage = NULL;
officeArtContent = NULL;
bOlderVersion = false;
m_pStorage = NULL; bDocumentCodePage = false;
officeArtContent = NULL; nDocumentCodePage = ENCODING_WINDOWS_1250;
bOlderVersion = false;
} }
WordDocument::~WordDocument() WordDocument::~WordDocument()
...@@ -178,8 +218,6 @@ namespace DocFileFormat ...@@ -178,8 +218,6 @@ namespace DocFileFormat
m_pStorage->GetStream (L"SummaryInformation", &Summary); m_pStorage->GetStream (L"SummaryInformation", &Summary);
m_pStorage->GetStream (L"DocumentSummaryInformation", &DocSummary); m_pStorage->GetStream (L"DocumentSummaryInformation", &DocSummary);
document_code_page = ENCODING_WINDOWS_1250;
if ((Summary) && (Summary->size() > 0)) if ((Summary) && (Summary->size() > 0))
{ {
...@@ -188,7 +226,10 @@ namespace DocFileFormat ...@@ -188,7 +226,10 @@ namespace DocFileFormat
int document_code_page1 = summary_info.GetCodePage(); //from software last open int document_code_page1 = summary_info.GetCodePage(); //from software last open
if (document_code_page1 > 0) if (document_code_page1 > 0)
document_code_page = document_code_page1; {
nDocumentCodePage = document_code_page1;
bDocumentCodePage = true;
}
} }
if ((DocSummary) && (DocSummary->size() > 0)) if ((DocSummary) && (DocSummary->size() > 0))
{ {
...@@ -197,12 +238,18 @@ namespace DocFileFormat ...@@ -197,12 +238,18 @@ namespace DocFileFormat
int document_code_page2 = doc_summary_info.GetCodePage(); int document_code_page2 = doc_summary_info.GetCodePage();
if (document_code_page2 > 0) if (document_code_page2 > 0)
document_code_page = document_code_page2; {
nDocumentCodePage = document_code_page2;
bDocumentCodePage = true;
}
} }
if (!bOlderVersion) if (!bOlderVersion)
document_code_page = ENCODING_UTF16; {
nDocumentCodePage = ENCODING_UTF16;
bDocumentCodePage = true;
}
FIB->m_CodePage = document_code_page; FIB->m_CodePage = nDocumentCodePage;
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
try try
{ {
...@@ -353,6 +400,31 @@ namespace DocFileFormat ...@@ -353,6 +400,31 @@ namespace DocFileFormat
return AVS_ERROR_FILEFORMAT; return AVS_ERROR_FILEFORMAT;
} }
} }
if (!bDocumentCodePage && FontTable)
{
std::unordered_map<int, int> fonts_charsets;
for ( std::vector<ByteStructure*>::iterator iter = FontTable->Data.begin();!bDocumentCodePage && iter != FontTable->Data.end(); iter++ )
{
FontFamilyName* font = dynamic_cast<FontFamilyName*>( *iter );
if (!font) continue;
if (fonts_charsets.find(font->chs) == fonts_charsets.end())
{
fonts_charsets.insert(std::make_pair(font->chs, font->ff));
for (int i = 0 ; i < sizeof(aCodePages) / 2; i++)
{
if (aCodePages[i][0] == font->chs && font->chs != 0)
{
nDocumentCodePage = aCodePages[i][1];
bDocumentCodePage = true;
break;
}
}
}
}
}
if (FIB->m_FibWord97.lcbClx > 0) if (FIB->m_FibWord97.lcbClx > 0)
{ {
...@@ -371,7 +443,7 @@ namespace DocFileFormat ...@@ -371,7 +443,7 @@ namespace DocFileFormat
WordDocumentStream->read (bytes, cb); WordDocumentStream->read (bytes, cb);
Text = new std::vector<wchar_t>(); Text = new std::vector<wchar_t>();
FormatUtils::GetSTLCollectionFromBytes<std::vector<wchar_t> >(Text, bytes, cb, document_code_page); FormatUtils::GetSTLCollectionFromBytes<std::vector<wchar_t> >(Text, bytes, cb, nDocumentCodePage);
RELEASEARRAYOBJECTS(bytes); RELEASEARRAYOBJECTS(bytes);
} }
......
...@@ -69,7 +69,6 @@ namespace DocFileFormat ...@@ -69,7 +69,6 @@ namespace DocFileFormat
{ {
class WordDocument: public IVisitable class WordDocument: public IVisitable
{ {
/*Mapping classes with direct access to the Word Document.*/
friend class FootnotesMapping; friend class FootnotesMapping;
friend class EndnotesMapping; friend class EndnotesMapping;
friend class CommentsMapping; friend class CommentsMapping;
...@@ -98,7 +97,8 @@ namespace DocFileFormat ...@@ -98,7 +97,8 @@ namespace DocFileFormat
long LoadDocument (const std::wstring & fileName, const std::wstring & password); long LoadDocument (const std::wstring & fileName, const std::wstring & password);
bool bOlderVersion; bool bOlderVersion;
int document_code_page; int nDocumentCodePage;
bool bDocumentCodePage;
inline StructuredStorageReader* GetStorage() const inline StructuredStorageReader* GetStorage() const
{ {
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="Urlmon.lib" AdditionalDependencies="Urlmon.lib"
LinkIncremental="1" LinkIncremental="1"
IgnoreDefaultLibraryNames="LIBCMT.lib" IgnoreDefaultLibraryNames="LIBCMTD.lib"
IgnoreEmbeddedIDL="true" IgnoreEmbeddedIDL="true"
GenerateDebugInformation="true" GenerateDebugInformation="true"
SubSystem="1" SubSystem="1"
......
...@@ -91,7 +91,7 @@ void Font::readFields(CFRecord& record) ...@@ -91,7 +91,7 @@ void Font::readFields(CFRecord& record)
if (global_info->fonts_charsets.find(bCharSet) == global_info->fonts_charsets.end()) if (global_info->fonts_charsets.find(bCharSet) == global_info->fonts_charsets.end())
{ {
global_info->fonts_charsets.insert(global_info->fonts_charsets.begin(), std::pair<int,int>(bCharSet, bFamily)); global_info->fonts_charsets.insert(std::make_pair(bCharSet, bFamily));
} }
} }
......
...@@ -38,8 +38,7 @@ ...@@ -38,8 +38,7 @@
namespace OLEPS namespace OLEPS
{ {
SummaryInformation::SummaryInformation(XLS::CFStreamPtr stream) SummaryInformation::SummaryInformation(XLS::CFStreamPtr stream) : property_set_stream(stream)
: property_set_stream(stream)
{ {
} }
......
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