Commit ac94cf1e authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander Trofimov

Сделано еще одно ускорение записи последовательного текста. Теперь текст...

Сделано еще одно ускорение записи последовательного текста. Теперь текст объекдиняется не только в слова, но еще и в целые строки. Также результирующий файл получается меньше по размеру.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63295 954022d7-b5bf-4e40-9824-e11837661b57
parent c02df701
...@@ -249,66 +249,7 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -249,66 +249,7 @@ void CPdfRenderer::CCommandManager::Flush()
double dPrevY = -1000; double dPrevY = -1000;
unsigned short ushPrevCode = 0; unsigned short ushPrevCode = 0;
class CContiniousText CTextLine oTextLine;
{
public:
CContiniousText()
{
m_nIndex = 0;
}
void Reset()
{
m_nIndex = 0;
}
bool Add(unsigned char* pCodes, unsigned int unLen, double dX, double dY, double dWidth)
{
if (2 != unLen)
return false;
if (0 == m_nIndex)
{
m_pText[0] = pCodes[0];
m_pText[1] = pCodes[1];
m_nIndex++;
m_dStartX = dX;
m_dStartY = dY;
m_dCurX = dX + dWidth;
}
else
{
if (abs(dY - m_dStartY) > 0.001 || abs(dX - m_dCurX) > 0.01)
return false;
m_pText[m_nIndex * 2 + 0] = pCodes[0];
m_pText[m_nIndex * 2 + 1] = pCodes[1];
m_nIndex++;
m_dCurX = dX + dWidth;
}
return true;
}
void Flush(PdfWriter::CPage* pPage)
{
if (m_nIndex > 0)
pPage->DrawText(m_dStartX, m_dStartY, m_pText, m_nIndex * 2);
m_nIndex = 0;
}
private:
unsigned char m_pText[200];
int m_nIndex;
double m_dStartX;
double m_dStartY;
double m_dCurX;
};
CContiniousText oContText;
for (int nIndex = 0; nIndex < nCommandsCount; nIndex++) for (int nIndex = 0; nIndex < nCommandsCount; nIndex++)
{ {
pText = (CRendererTextCommand*)m_vCommands.at(nIndex); pText = (CRendererTextCommand*)m_vCommands.at(nIndex);
...@@ -335,7 +276,7 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -335,7 +276,7 @@ void CPdfRenderer::CCommandManager::Flush()
if (pTextFont != pText->GetFont() || abs(dTextSize - pText->GetSize()) > 0.001) if (pTextFont != pText->GetFont() || abs(dTextSize - pText->GetSize()) > 0.001)
{ {
oContText.Flush(pPage); oTextLine.Flush(pPage);
pTextFont = pText->GetFont(); pTextFont = pText->GetFont();
dTextSize = pText->GetSize(); dTextSize = pText->GetSize();
pPage->SetFontAndSize(pTextFont, dTextSize); pPage->SetFontAndSize(pTextFont, dTextSize);
...@@ -343,7 +284,7 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -343,7 +284,7 @@ void CPdfRenderer::CCommandManager::Flush()
if (lTextColor != pText->GetColor()) if (lTextColor != pText->GetColor())
{ {
oContText.Flush(pPage); oTextLine.Flush(pPage);
lTextColor = pText->GetColor(); lTextColor = pText->GetColor();
TColor oColor = lTextColor; TColor oColor = lTextColor;
pPage->SetFillColor(oColor.r, oColor.g, oColor.b); pPage->SetFillColor(oColor.r, oColor.g, oColor.b);
...@@ -351,14 +292,14 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -351,14 +292,14 @@ void CPdfRenderer::CCommandManager::Flush()
if (nTextAlpha != pText->GetAlpha()) if (nTextAlpha != pText->GetAlpha())
{ {
oContText.Flush(pPage); oTextLine.Flush(pPage);
nTextAlpha = pText->GetAlpha(); nTextAlpha = pText->GetAlpha();
pPage->SetFillAlpha(nTextAlpha); pPage->SetFillAlpha(nTextAlpha);
} }
if (abs(dTextSpace - pText->GetSpace()) > 0.001) if (abs(dTextSpace - pText->GetSpace()) > 0.001)
{ {
oContText.Flush(pPage); oTextLine.Flush(pPage);
dTextSpace = pText->GetSpace(); dTextSpace = pText->GetSpace();
pPage->SetCharSpace(dTextSpace); pPage->SetCharSpace(dTextSpace);
} }
...@@ -371,12 +312,13 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -371,12 +312,13 @@ void CPdfRenderer::CCommandManager::Flush()
unsigned int unLen = pText->GetCodesLen(); unsigned int unLen = pText->GetCodesLen();
double dX = pText->GetX(); double dX = pText->GetX();
double dY = pText->GetY(); double dY = pText->GetY();
double dWidth = ((CFontCidTrueType*)pText->GetFont())->GetWidth(ushCode) / 1000.0 * pText->GetSize(); double dTextSize = pText->GetSize();
double dWidth = ((CFontCidTrueType*)pText->GetFont())->GetWidth(ushCode) / 1000.0 * dTextSize;
if (!oContText.Add(pCodes, unLen, dX, dY, dWidth)) if (!oTextLine.Add(pCodes, unLen, dX, dY, dWidth, dTextSize))
{ {
oContText.Flush(pPage); oTextLine.Flush(pPage);
if (!oContText.Add(pCodes, unLen, dX, dY, dWidth)) if (!oTextLine.Add(pCodes, unLen, dX, dY, dWidth, dTextSize))
{ {
pPage->DrawText(dX, dY, pCodes, unLen); pPage->DrawText(dX, dY, pCodes, unLen);
} }
...@@ -385,7 +327,7 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -385,7 +327,7 @@ void CPdfRenderer::CCommandManager::Flush()
//pPage->DrawText(pText->GetX(), pText->GetY(), pText->GetCodes(), pText->GetCodesLen()); //pPage->DrawText(pText->GetX(), pText->GetY(), pText->GetCodes(), pText->GetCodesLen());
} }
oContText.Flush(pPage); oTextLine.Flush(pPage);
pPage->EndText(); pPage->EndText();
} }
...@@ -434,7 +376,7 @@ CPdfRenderer::CPdfRenderer(CApplicationFonts* pAppFonts) : m_oCommandManager(thi ...@@ -434,7 +376,7 @@ CPdfRenderer::CPdfRenderer(CApplicationFonts* pAppFonts) : m_oCommandManager(thi
return; return;
} }
//m_pDocument->SetCompressionMode(COMP_ALL); m_pDocument->SetCompressionMode(COMP_ALL);
m_bValid = true; m_bValid = true;
m_dPageHeight = 297; m_dPageHeight = 297;
......
...@@ -127,8 +127,9 @@ ...@@ -127,8 +127,9 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\DesktopEditor\freetype-2.5.2\include;..\DesktopEditor\agg-2.4\include;..\DesktopEditor\cximage\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
......
...@@ -920,14 +920,13 @@ void TestMetafile() ...@@ -920,14 +920,13 @@ void TestMetafile()
} }
void TestOnlineBin() void TestOnlineBin()
{ {
std::wstring wsFolderPath = L"D://Test Files//Txt//Text//"; std::wstring wsFolderPath = L"D://Test Files//Txt//IvanovaVeronica//";
std::wstring wsTempFolder = L"D://Test Files//Temp//"; std::wstring wsTempFolder = L"D://Test Files//Temp//";
CApplicationFonts oFonts; CApplicationFonts oFonts;
oFonts.Initialize(); oFonts.Initialize();
clock_t oBeginTime = clock(); clock_t oBeginTime = clock();
double dPx2Mm = 25.4 / 96; double dPx2Mm = 25.4 / 96;
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"txt"); std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"txt");
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++) for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
...@@ -946,7 +945,6 @@ void TestOnlineBin() ...@@ -946,7 +945,6 @@ void TestOnlineBin()
clock_t oEndTime = clock(); clock_t oEndTime = clock();
double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC; double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
printf("%f\n", dElapsedSecs); printf("%f\n", dElapsedSecs);
} }
void main() void main()
......
...@@ -135,8 +135,9 @@ ...@@ -135,8 +135,9 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\DesktopEditor\freetype-2.5.2\include;..\..\DesktopEditor\agg-2.4\include;..\..\DesktopEditor\cximage\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
#pragma comment(lib, "Ws2_32.lib") #pragma comment(lib, "Ws2_32.lib")
#else #else
#pragma comment(lib, "../x64/Release/PdfWriter.lib") #pragma comment(lib, "../x64/Release/PdfWriter.lib")
#pragma comment(lib, "../../../DesktopEditor/Qt_build/graphics/project/release/graphics.lib") #pragma comment(lib, "../../DesktopEditor/Qt_build/graphics/project/release/graphics.lib")
#pragma comment(lib, "../../ASCOfficeUtils/ASCOfficeUtilsLib/Win/x64/Release/ASCOfficeUtilsLib.lib")
#pragma comment(lib, "Ws2_32.lib")
#endif #endif
......
...@@ -925,9 +925,20 @@ namespace PdfWriter ...@@ -925,9 +925,20 @@ namespace PdfWriter
MoveTextPos(dX, dY); MoveTextPos(dX, dY);
ShowText(sText, unLen); ShowText(sText, unLen);
} }
void CPage::DrawTextArray(double dXpos, double dYpos, const BYTE** ppTexts, unsigned int* pLens, unsigned int unCount, double* pShifts) void CPage::DrawTextLine(const CTextLine* pTextLine)
{ {
if (!pTextLine)
return;
int nCount = pTextLine->m_vWords.size();
if (nCount <= 0)
return;
CheckGrMode(grmode_TEXT); CheckGrMode(grmode_TEXT);
double dXpos = pTextLine->m_dX;
double dYpos = pTextLine->m_dY;
double dX = 0.0; double dX = 0.0;
double dY = 0.0; double dY = 0.0;
...@@ -943,15 +954,28 @@ namespace PdfWriter ...@@ -943,15 +954,28 @@ namespace PdfWriter
} }
MoveTextPos(dX, dY); MoveTextPos(dX, dY);
if (1 == nCount)
{
CTextWord* pWord = pTextLine->m_vWords.at(0);
ShowText(pWord->m_pText, pWord->m_nIndex * 2);
}
else
{
CTextWord* pWord = NULL;
double dShift = 0;
m_pStream->WriteChar('['); m_pStream->WriteChar('[');
for (unsigned int unIndex = 0; unIndex < unCount; unIndex++) for (int nIndex = 0; nIndex < nCount; nIndex++)
{ {
WriteText(ppTexts[unIndex], pLens[unIndex]); pWord = pTextLine->m_vWords.at(nIndex);
if (unIndex != unCount - 1) WriteText(pWord->m_pText, pWord->m_nIndex * 2);
m_pStream->WriteReal(pShifts[unIndex]); if (nIndex != nCount - 1)
{
dShift = pTextLine->m_vShifts.at(nIndex);
m_pStream->WriteReal(dShift);
}
} }
m_pStream->WriteStr("]TJ\012"); m_pStream->WriteStr("]TJ\012");
}
} }
void CPage::SetCharSpace(double dValue) void CPage::SetCharSpace(double dValue)
{ {
...@@ -1217,4 +1241,98 @@ namespace PdfWriter ...@@ -1217,4 +1241,98 @@ namespace PdfWriter
{ {
Add("Group", pDict); Add("Group", pDict);
} }
//----------------------------------------------------------------------------------------
// CTextWord
//----------------------------------------------------------------------------------------
CTextWord::CTextWord()
{
m_nIndex = 0;
}
bool CTextWord::Add(unsigned char* pCodes, unsigned int unLen, double dX, double dY, double dWidth)
{
if (2 != unLen)
return false;
if (0 == m_nIndex)
{
m_pText[0] = pCodes[0];
m_pText[1] = pCodes[1];
m_nIndex++;
m_dStartX = dX;
m_dStartY = dY;
m_dCurX = dX + dWidth;
}
else
{
if (abs(dY - m_dStartY) > 0.001 || abs(dX - m_dCurX) > 0.01)
return false;
m_pText[m_nIndex * 2 + 0] = pCodes[0];
m_pText[m_nIndex * 2 + 1] = pCodes[1];
m_nIndex++;
m_dCurX = dX + dWidth;
}
return true;
}
//----------------------------------------------------------------------------------------
// CTextLine
//----------------------------------------------------------------------------------------
CTextLine::CTextLine()
{
}
CTextLine::~CTextLine()
{
Clear();
}
bool CTextLine::Add(unsigned char* pCodes, unsigned int unLen, double dX, double dY, double dWidth, double dSize)
{
if (2 != unLen)
return false;
if (0 == m_vWords.size())
{
CTextWord* pText = new CTextWord();
if (!pText || !pText->Add(pCodes, unLen, dX, dY, dWidth))
return false;
m_vWords.push_back(pText);
m_dX = dX;
m_dY = dY;
return true;
}
if (abs(dY - m_dY) > 0.001)
return false;
CTextWord* pLastText = m_vWords.at(m_vWords.size() - 1);
if (pLastText->Add(pCodes, unLen, dX, dY, dWidth))
return true;
CTextWord* pText = new CTextWord();
if (!pText || !pText->Add(pCodes, unLen, dX, dY, dWidth))
return false;
m_vWords.push_back(pText);
double dShift = (pLastText->m_dCurX - dX) * 1000 / dSize;
m_vShifts.push_back(dShift);
return true;
}
void CTextLine::Flush(CPage* pPage)
{
pPage->DrawTextLine(this);
Clear();
}
void CTextLine::Clear()
{
for (int nIndex = 0, nCount = m_vWords.size(); nIndex < nCount; nIndex++)
{
CTextWord* pText = m_vWords.at(nIndex);
RELEASEOBJECT(pText);
}
m_vWords.clear();
m_vShifts.clear();
}
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define _PDF_WRITER_SRC_PAGES_H #define _PDF_WRITER_SRC_PAGES_H
#include "Objects.h" #include "Objects.h"
#include <vector>
#ifdef DrawText #ifdef DrawText
#undef DrawText #undef DrawText
...@@ -19,6 +20,8 @@ namespace PdfWriter ...@@ -19,6 +20,8 @@ namespace PdfWriter
class CShading; class CShading;
class CImageTilePattern; class CImageTilePattern;
class CDocument; class CDocument;
class CTextLine;
class CTextWord;
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
// CPageTree // CPageTree
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
...@@ -96,9 +99,7 @@ namespace PdfWriter ...@@ -96,9 +99,7 @@ namespace PdfWriter
void SetFontAndSize(CFontDict* pFont, double dSize); void SetFontAndSize(CFontDict* pFont, double dSize);
void SetTextRenderingMode(ETextRenderingMode eMode); void SetTextRenderingMode(ETextRenderingMode eMode);
void SetTextMatrix(double dM11, double dM12, double dM21, double dM22, double dX, double dY); void SetTextMatrix(double dM11, double dM12, double dM21, double dM22, double dX, double dY);
void DrawTextLine(const CTextLine* pTextLine);
void DrawTextArray(double dX, double dY, const BYTE** ppTexts, unsigned int* pLens, unsigned int unCount, double* pShifts);
void ExecuteXObject(CXObject* pXObject); void ExecuteXObject(CXObject* pXObject);
void DrawImage(CImageDict* pImage, double dX, double dY, double dWidth, double dHeight); void DrawImage(CImageDict* pImage, double dX, double dY, double dWidth, double dHeight);
...@@ -152,6 +153,53 @@ namespace PdfWriter ...@@ -152,6 +153,53 @@ namespace PdfWriter
CDictObject* m_pPatterns; CDictObject* m_pPatterns;
unsigned int m_unPatternsCount; unsigned int m_unPatternsCount;
}; };
//----------------------------------------------------------------------------------------
// CTextWord
//----------------------------------------------------------------------------------------
class CTextWord
{
public:
CTextWord();
bool Add(unsigned char* pCodes, unsigned int unLen, double dX, double dY, double dWidth);
private:
unsigned char m_pText[200];
int m_nIndex;
double m_dStartX;
double m_dStartY;
double m_dCurX;
friend class CTextLine;
friend class CPage;
};
//----------------------------------------------------------------------------------------
// CTextLine
//----------------------------------------------------------------------------------------
class CTextLine
{
public:
CTextLine();
~CTextLine();
bool Add(unsigned char* pCodes, unsigned int unLen, double dX, double dY, double dWidth, double dFontSize);
void Flush(CPage* pPage);
private:
void Clear();
private:
std::vector<CTextWord*> m_vWords;
std::vector<double> m_vShifts;
double m_dX;
double m_dY;
friend class CPage;
};
} }
#endif // _PDF_WRITER_SRC_PAGES_H #endif // _PDF_WRITER_SRC_PAGES_H
......
...@@ -587,7 +587,8 @@ namespace PdfWriter ...@@ -587,7 +587,8 @@ namespace PdfWriter
unsigned int unRemainBytes = m_nBufferSize - Tell(); unsigned int unRemainBytes = m_nBufferSize - Tell();
if (unRemainBytes < unSize) if (unRemainBytes < unSize)
{ {
Shrink(unSize); unsigned int unShrinkSize = max(unSize, 4096);
Shrink(unShrinkSize);
} }
MemCpy(m_pCur, pBuffer, unSize); MemCpy(m_pCur, pBuffer, unSize);
m_pCur += unSize; m_pCur += unSize;
......
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