Commit d70f36e3 authored by ElenaSubbotina's avatar ElenaSubbotina

DocFormat - fix users files

parent 60cf51ad
...@@ -53,62 +53,31 @@ namespace DocFileFormat ...@@ -53,62 +53,31 @@ namespace DocFileFormat
PathParser (const unsigned char* pSegmentInfo, unsigned int pSegmentInfoSize, const unsigned char* pVertices, unsigned int pVerticesSize, std::vector<_guides> & guides) PathParser (const unsigned char* pSegmentInfo, unsigned int pSegmentInfoSize, const unsigned char* pVertices, unsigned int pVerticesSize, std::vector<_guides> & guides)
{ {
int offset = 6;
if ((pSegmentInfo != NULL) && (pSegmentInfoSize > 0)) if ((pSegmentInfo != NULL) && (pSegmentInfoSize > 0))
{ {
int offset = 6;
unsigned short nElems = FormatUtils::BytesToUInt16(pSegmentInfo, 0, pSegmentInfoSize); unsigned short nElems = FormatUtils::BytesToUInt16(pSegmentInfo, 0, pSegmentInfoSize);
unsigned short nElemsAlloc = FormatUtils::BytesToUInt16(pSegmentInfo, 2, pSegmentInfoSize); unsigned short nElemsAlloc = FormatUtils::BytesToUInt16(pSegmentInfo, 2, pSegmentInfoSize);
unsigned short cb = FormatUtils::BytesToUInt16(pSegmentInfo, 4, pSegmentInfoSize); unsigned short cb = FormatUtils::BytesToUInt16(pSegmentInfo, 4, pSegmentInfoSize);
// видимо без шапки сразу пишутся все элементы unsigned short cbElement = 4;
bool headerIs = ((0xfff0 != cb) && (cb > 8) || nElems > nElemsAlloc);
if (headerIs)
{
cb = 2;
offset = 0;
nElems = pSegmentInfoSize / 2;
for (unsigned short i = 0; i < nElems; ++i) if (cb == 0xfff0)
{ cbElement = 2;
PathSegment oSegment = PathSegment(FormatUtils::BytesToUInt16(pSegmentInfo + offset, (i * cb), pSegmentInfoSize));
m_arSegments.push_back (oSegment); if (nElems == 0)
} {
nElems = (pSegmentInfoSize - offset) / cbElement;
} }
else for (unsigned short i = 0; i < nElems; ++i)
{ {
if ((0xfff0 != cb) && (8 != cb) && (4 != cb) && (2 != cb)) PathSegment oSegment = PathSegment(FormatUtils::BytesToInt32(pSegmentInfo + offset, (i * cbElement), pSegmentInfoSize - offset));
{ m_arSegments.push_back (oSegment);
cb = 0xfff0;
offset = 0;
nElems = pSegmentInfoSize / 2;
}
if (0xfff0 == cb)
{
cb = 4;
for (unsigned short i = 0; i < nElems; ++i)
{
PathSegment oSegment = PathSegment(FormatUtils::BytesToUInt16(pSegmentInfo + offset, (i * cb), pSegmentInfoSize));
m_arSegments.push_back (oSegment);
}
}
else
{
if ((2 != cb) && (1 != cb))
cb = 8;
for (unsigned short i = 0; i < nElems; ++i)
{
PathSegment oSegment = PathSegment(FormatUtils::BytesToInt32(pSegmentInfo + offset, (i * cb), pSegmentInfoSize));
m_arSegments.push_back (oSegment);
}
if ((long)pSegmentInfoSize < (long)(cb*nElems)) // Есть несколько файлов с мусором вместо данных
m_arSegments.clear();
}
} }
if ((long)pSegmentInfoSize < (long)(cb * nElems)) // Есть несколько файлов с мусором вместо данных
m_arSegments.clear();
} }
if ((NULL != pVertices) && (pVerticesSize > 0)) if ((NULL != pVertices) && (pVerticesSize > 0))
...@@ -117,19 +86,23 @@ namespace DocFileFormat ...@@ -117,19 +86,23 @@ namespace DocFileFormat
unsigned short nElemsAlloc = FormatUtils::BytesToUInt16(pVertices, 2, pVerticesSize); unsigned short nElemsAlloc = FormatUtils::BytesToUInt16(pVertices, 2, pVerticesSize);
unsigned short cb = FormatUtils::BytesToUInt16(pVertices, 4, pVerticesSize); unsigned short cb = FormatUtils::BytesToUInt16(pVertices, 4, pVerticesSize);
unsigned short cbElement = cb;
if (cb == 0xfff0)
cbElement = 4;
for (unsigned short i = 0; i < nElems; ++i) for (unsigned short i = 0; i < nElems; ++i)
{ {
POINT point; POINT point;
if (0xfff0 == cb) if (cbElement == 4)
{ {
cb = 4; point.x = FormatUtils::BytesToInt16(pVertices + offset, (i * cbElement), pVerticesSize - offset);
point.x = FormatUtils::BytesToInt16(pVertices + 6, (i * cb), pVerticesSize); point.y = FormatUtils::BytesToInt16(pVertices + offset, (i * cbElement) + (cbElement / 2), pVerticesSize - offset);
point.y = FormatUtils::BytesToInt16(pVertices + 6, (i * cb) + (cb / 2), pVerticesSize);
} }
else else
{ {
point.x = FormatUtils::BytesToInt32(pVertices + 6, (i * cb), pVerticesSize); point.x = FormatUtils::BytesToInt32(pVertices + offset, (i * cbElement), pVerticesSize - offset);
point.y = FormatUtils::BytesToInt32(pVertices + 6, (i * cb) + (cb / 2), pVerticesSize); point.y = FormatUtils::BytesToInt32(pVertices + offset, (i * cbElement) + (cbElement / 2), pVerticesSize - offset);
} }
LONG lMinF = (LONG)0x80000000; LONG lMinF = (LONG)0x80000000;
......
...@@ -288,6 +288,7 @@ namespace DocFileFormat ...@@ -288,6 +288,7 @@ namespace DocFileFormat
int ndyTextBottom = -1; int ndyTextBottom = -1;
bool bHavePath = false; bool bHavePath = false;
int nShapePath = -1;
int nAdjValues = 0; int nAdjValues = 0;
int nLTxID = -1; int nLTxID = -1;
...@@ -361,6 +362,7 @@ namespace DocFileFormat ...@@ -361,6 +362,7 @@ namespace DocFileFormat
case shapePath : case shapePath :
{ {
bHavePath = true; bHavePath = true;
nShapePath = iter->op;
}break; }break;
case pVertices: case pVertices:
{ {
...@@ -1653,7 +1655,7 @@ namespace DocFileFormat ...@@ -1653,7 +1655,7 @@ namespace DocFileFormat
} }
if (!bRelV && m_pSpa) if (!bRelV && m_pSpa)
{ {
appendStyleProperty(oStyle, L"mso-position-vertical-relative", mapVerticalPositionRelative(m_pSpa->bx)); appendStyleProperty(oStyle, L"mso-position-vertical-relative", mapVerticalPositionRelative(m_pSpa->by));
} }
if (!m_isInlineShape && !bZIndex) if (!m_isInlineShape && !bZIndex)
{ {
......
...@@ -29,19 +29,16 @@ ...@@ -29,19 +29,16 @@
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
* *
*/ */
// DocFormatTest.cpp : Defines the entry point for the console application. #include <iostream>
//
#include "../DocFormatLib/DocFormatLib.h"
#include "../../OfficeUtils/src/ASCOfficeCriticalSection.h"
#include "../../Common/DocxFormat/Source/Base/Base.h"
#include "../../DesktopEditor/common/Directory.h"
#include "../../OfficeUtils/src/OfficeUtils.h" #include "../../OfficeUtils/src/OfficeUtils.h"
#include "../../DesktopEditor/common/Directory.h" #include "../DocFormatLib/DocFormatLib.h"
#include <string> #pragma comment(lib,"Shell32.lib")
#include <windows.h> #pragma comment(lib,"Advapi32.lib")
#include <tchar.h>
#if defined(_WIN64) #if defined(_WIN64)
#pragma comment(lib, "../../build/bin/icu/win_64/icuuc.lib") #pragma comment(lib, "../../build/bin/icu/win_64/icuuc.lib")
...@@ -49,36 +46,34 @@ ...@@ -49,36 +46,34 @@
#pragma comment(lib, "../../build/bin/icu/win_32/icuuc.lib") #pragma comment(lib, "../../build/bin/icu/win_32/icuuc.lib")
#endif #endif
int _tmain(int argc, _TCHAR* argv[]) HRESULT convert_single(std::wstring srcFileName)
{ {
if (argc < 2) return 1; HRESULT hr = S_OK;
std::wstring sSrcDoc = argv[1];
std::wstring sDstDocx;
std::wstring outputDir = NSDirectory::GetFolderPath(sSrcDoc); std::wstring outputDir = NSDirectory::GetFolderPath(srcFileName);
std::wstring dstTempPath = NSDirectory::CreateDirectoryWithUniqueName(outputDir); std::wstring dstTempPath = NSDirectory::CreateDirectoryWithUniqueName(outputDir);
std::wstring dstPath;
COfficeDocFile docFile; COfficeDocFile docFile;
docFile.m_sTempFolder = outputDir; docFile.m_sTempFolder = outputDir;
bool bMacros = true; bool bMacros = true;
HRESULT hRes = docFile.LoadFromFile( sSrcDoc, dstTempPath, L"password", bMacros, NULL); HRESULT hRes = docFile.LoadFromFile( srcFileName, dstTempPath, L"password", bMacros, NULL);
if (bMacros) if (bMacros)
{ {
sDstDocx = sSrcDoc + L"-my.docm"; dstPath = srcFileName + L"-my.docm";
} }
else else
{ {
sDstDocx = sSrcDoc + L"-my.docx"; dstPath = srcFileName + L"-my.docx";
} }
if (hRes == S_OK) if (hRes == S_OK)
{ {
COfficeUtils oCOfficeUtils(NULL); COfficeUtils oCOfficeUtils(NULL);
hRes = oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), sDstDocx, -1); hRes = oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), dstPath, -1);
} }
NSDirectory::DeleteDirectory(dstTempPath); NSDirectory::DeleteDirectory(dstTempPath);
...@@ -86,3 +81,33 @@ int _tmain(int argc, _TCHAR* argv[]) ...@@ -86,3 +81,33 @@ int _tmain(int argc, _TCHAR* argv[])
return hRes; return hRes;
} }
HRESULT convert_directory(std::wstring pathName)
{
HRESULT hr = S_OK;
std::vector<std::wstring> arFiles = NSDirectory::GetFiles(pathName, false);
for (size_t i = 0; i < arFiles.size(); i++)
{
convert_single(arFiles[i]);
}
return S_OK;
}
int _tmain(int argc, _TCHAR* argv[])
{
if (argc < 2) return 1;
HRESULT hr = -1;
if (NSFile::CFileBinary::Exists(argv[1]))
{
hr = convert_single(argv[1]);
}
else if (NSDirectory::Exists(argv[1]))
{
hr = convert_directory(argv[1]);
}
return hr;
}
\ 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