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()
double dPrevY = -1000;
unsigned short ushPrevCode = 0;
class CContiniousText
{
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;
CTextLine oTextLine;
for (int nIndex = 0; nIndex < nCommandsCount; nIndex++)
{
pText = (CRendererTextCommand*)m_vCommands.at(nIndex);
......@@ -335,7 +276,7 @@ void CPdfRenderer::CCommandManager::Flush()
if (pTextFont != pText->GetFont() || abs(dTextSize - pText->GetSize()) > 0.001)
{
oContText.Flush(pPage);
oTextLine.Flush(pPage);
pTextFont = pText->GetFont();
dTextSize = pText->GetSize();
pPage->SetFontAndSize(pTextFont, dTextSize);
......@@ -343,7 +284,7 @@ void CPdfRenderer::CCommandManager::Flush()
if (lTextColor != pText->GetColor())
{
oContText.Flush(pPage);
oTextLine.Flush(pPage);
lTextColor = pText->GetColor();
TColor oColor = lTextColor;
pPage->SetFillColor(oColor.r, oColor.g, oColor.b);
......@@ -351,14 +292,14 @@ void CPdfRenderer::CCommandManager::Flush()
if (nTextAlpha != pText->GetAlpha())
{
oContText.Flush(pPage);
oTextLine.Flush(pPage);
nTextAlpha = pText->GetAlpha();
pPage->SetFillAlpha(nTextAlpha);
}
if (abs(dTextSpace - pText->GetSpace()) > 0.001)
{
oContText.Flush(pPage);
oTextLine.Flush(pPage);
dTextSpace = pText->GetSpace();
pPage->SetCharSpace(dTextSpace);
}
......@@ -366,17 +307,18 @@ void CPdfRenderer::CCommandManager::Flush()
//------------------------------------
unsigned char* pCodes = pText->GetCodes();
unsigned short ushCode = (pCodes[0] << 8) + pCodes[1];
unsigned int unLen = pText->GetCodesLen();
double dX = pText->GetX();
double dY = pText->GetY();
double dWidth = ((CFontCidTrueType*)pText->GetFont())->GetWidth(ushCode) / 1000.0 * pText->GetSize();
if (!oContText.Add(pCodes, unLen, dX, dY, dWidth))
unsigned char* pCodes = pText->GetCodes();
unsigned short ushCode = (pCodes[0] << 8) + pCodes[1];
unsigned int unLen = pText->GetCodesLen();
double dX = pText->GetX();
double dY = pText->GetY();
double dTextSize = pText->GetSize();
double dWidth = ((CFontCidTrueType*)pText->GetFont())->GetWidth(ushCode) / 1000.0 * dTextSize;
if (!oTextLine.Add(pCodes, unLen, dX, dY, dWidth, dTextSize))
{
oContText.Flush(pPage);
if (!oContText.Add(pCodes, unLen, dX, dY, dWidth))
oTextLine.Flush(pPage);
if (!oTextLine.Add(pCodes, unLen, dX, dY, dWidth, dTextSize))
{
pPage->DrawText(dX, dY, pCodes, unLen);
}
......@@ -385,7 +327,7 @@ void CPdfRenderer::CCommandManager::Flush()
//pPage->DrawText(pText->GetX(), pText->GetY(), pText->GetCodes(), pText->GetCodesLen());
}
oContText.Flush(pPage);
oTextLine.Flush(pPage);
pPage->EndText();
}
......@@ -434,7 +376,7 @@ CPdfRenderer::CPdfRenderer(CApplicationFonts* pAppFonts) : m_oCommandManager(thi
return;
}
//m_pDocument->SetCompressionMode(COMP_ALL);
m_pDocument->SetCompressionMode(COMP_ALL);
m_bValid = true;
m_dPageHeight = 297;
......
......@@ -127,8 +127,9 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\DesktopEditor\freetype-2.5.2\include;..\DesktopEditor\agg-2.4\include;..\DesktopEditor\cximage\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
......
......@@ -920,14 +920,13 @@ void TestMetafile()
}
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//";
CApplicationFonts oFonts;
oFonts.Initialize();
clock_t oBeginTime = clock();
double dPx2Mm = 25.4 / 96;
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"txt");
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
......@@ -946,7 +945,6 @@ void TestOnlineBin()
clock_t oEndTime = clock();
double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
printf("%f\n", dElapsedSecs);
}
void main()
......
......@@ -135,8 +135,9 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\DesktopEditor\freetype-2.5.2\include;..\..\DesktopEditor\agg-2.4\include;..\..\DesktopEditor\cximage\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
......
......@@ -16,7 +16,9 @@
#pragma comment(lib, "Ws2_32.lib")
#else
#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
......
......@@ -925,9 +925,20 @@ namespace PdfWriter
MoveTextPos(dX, dY);
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);
double dXpos = pTextLine->m_dX;
double dYpos = pTextLine->m_dY;
double dX = 0.0;
double dY = 0.0;
......@@ -943,15 +954,28 @@ namespace PdfWriter
}
MoveTextPos(dX, dY);
m_pStream->WriteChar('[');
for (unsigned int unIndex = 0; unIndex < unCount; unIndex++)
if (1 == nCount)
{
WriteText(ppTexts[unIndex], pLens[unIndex]);
if (unIndex != unCount - 1)
m_pStream->WriteReal(pShifts[unIndex]);
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('[');
for (int nIndex = 0; nIndex < nCount; nIndex++)
{
pWord = pTextLine->m_vWords.at(nIndex);
WriteText(pWord->m_pText, pWord->m_nIndex * 2);
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)
{
......@@ -1217,4 +1241,98 @@ namespace PdfWriter
{
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 @@
#define _PDF_WRITER_SRC_PAGES_H
#include "Objects.h"
#include <vector>
#ifdef DrawText
#undef DrawText
......@@ -19,6 +20,8 @@ namespace PdfWriter
class CShading;
class CImageTilePattern;
class CDocument;
class CTextLine;
class CTextWord;
//----------------------------------------------------------------------------------------
// CPageTree
//----------------------------------------------------------------------------------------
......@@ -96,9 +99,7 @@ namespace PdfWriter
void SetFontAndSize(CFontDict* pFont, double dSize);
void SetTextRenderingMode(ETextRenderingMode eMode);
void SetTextMatrix(double dM11, double dM12, double dM21, double dM22, double dX, double dY);
void DrawTextArray(double dX, double dY, const BYTE** ppTexts, unsigned int* pLens, unsigned int unCount, double* pShifts);
void DrawTextLine(const CTextLine* pTextLine);
void ExecuteXObject(CXObject* pXObject);
void DrawImage(CImageDict* pImage, double dX, double dY, double dWidth, double dHeight);
......@@ -152,6 +153,53 @@ namespace PdfWriter
CDictObject* m_pPatterns;
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
......
......@@ -587,7 +587,8 @@ namespace PdfWriter
unsigned int unRemainBytes = m_nBufferSize - Tell();
if (unRemainBytes < unSize)
{
Shrink(unSize);
unsigned int unShrinkSize = max(unSize, 4096);
Shrink(unShrinkSize);
}
MemCpy(m_pCur, pBuffer, 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