Files
core/ASCOfficeRtfFile/Win32/RtfFile.cpp
Elen.Subbotina 9a8c021a92 RtfFile win build
поправлены кодировки в списках (001.rtf, 21.haikufinal.rtf, 000195_65276158fedb94v8tebc20.rtf)
поправлены размеры картинки если они меньше 1 pt

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62398 954022d7-b5bf-4e40-9824-e11837661b57
2016-05-21 00:00:55 +03:00

77 lines
4.3 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// RtfFile.cpp : Implementation of CRtfFile
#include "stdafx.h"
#include "RtfFile.h"
#include "../../Common/OfficeFileErrorDescription.h"
#include "../RtfFormatLib/source/ConvertationManager.h"
#include "../RtfFormatLib/source/Basic.h"
#include "../../Common/DocxFormat/Source/SystemUtility/File.h"
// CRtfFile
STDMETHODIMP CRtfFile::LoadFromFile(BSTR sSrcFileName, BSTR sDstPath, BSTR sXMLOptions)
{
CString sFilename( sSrcFileName );
//проверяем входной файл на rtf
long nError;
if( FALSE == IsRtfFile( sFilename, nError ) )
{
if( NOERROR == nError )
return AVS_ERROR_FILEFORMAT;
else
return nError;
}
//проверяем существует ли папка
DWORD dwDirectoryAttribute = ::GetFileAttributes( sDstPath );
if( 0 == ( dwDirectoryAttribute & FILE_ATTRIBUTE_DIRECTORY ) )
return AVS_ERROR_FILEACCESS;
//конвертация
RtfConvertationManager oConvertationManager;
return oConvertationManager.ConvertRtfToOOX( std::wstring( sSrcFileName ), std::wstring( sDstPath ) );
}
STDMETHODIMP CRtfFile::SaveToFile(BSTR sDstFileName, BSTR sSrcPath, BSTR sXMLOptions)
{
//проверяем доступен ли для записи файл
HANDLE hFile = CreateFile (sDstFileName, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if ( INVALID_HANDLE_VALUE == hFile )
return AVS_ERROR_FILEACCESS;
CloseHandle( hFile );
//проверяем существует ли папка
DWORD dwDirectoryAttribute = ::GetFileAttributes( sSrcPath );
if( 0 == ( dwDirectoryAttribute & FILE_ATTRIBUTE_DIRECTORY ) )
return AVS_ERROR_FILEACCESS;
//конвертация
RtfConvertationManager oConvertationManager;
oConvertationManager.ConvertOOXToRtf( std::wstring( sDstFileName ), std::wstring( sSrcPath) );
return S_OK;
}
bool CRtfFile::IsRtfFile(CString sFilename, long& nError )
{
nError = NOERROR;
BYTE pBuffer[ 5 ];
DWORD dwBytesRead;
CFile file;
if (file.OpenFile(sFilename) != S_OK) return false;
file.ReadFile(pBuffer, 5);
file.CloseFile();
if( 5 == dwBytesRead && '{' == pBuffer[0] && '\\' == pBuffer[1] && 'r' == pBuffer[2] && 't' == pBuffer[3] && 'f' == pBuffer[4] )
return true;
return false;
}