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

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

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63292 954022d7-b5bf-4e40-9824-e11837661b57
parent 97c3e9ed
...@@ -245,6 +245,70 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -245,6 +245,70 @@ void CPdfRenderer::CCommandManager::Flush()
BYTE nTextAlpha = 255; BYTE nTextAlpha = 255;
double dTextSpace = 0; double dTextSpace = 0;
double dPrevX = -1000;
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;
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);
...@@ -271,6 +335,7 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -271,6 +335,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);
pTextFont = pText->GetFont(); pTextFont = pText->GetFont();
dTextSize = pText->GetSize(); dTextSize = pText->GetSize();
pPage->SetFontAndSize(pTextFont, dTextSize); pPage->SetFontAndSize(pTextFont, dTextSize);
...@@ -278,6 +343,7 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -278,6 +343,7 @@ void CPdfRenderer::CCommandManager::Flush()
if (lTextColor != pText->GetColor()) if (lTextColor != pText->GetColor())
{ {
oContText.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);
...@@ -285,18 +351,41 @@ void CPdfRenderer::CCommandManager::Flush() ...@@ -285,18 +351,41 @@ void CPdfRenderer::CCommandManager::Flush()
if (nTextAlpha != pText->GetAlpha()) if (nTextAlpha != pText->GetAlpha())
{ {
oContText.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);
dTextSpace = pText->GetSpace(); dTextSpace = pText->GetSpace();
pPage->SetCharSpace(dTextSpace); pPage->SetCharSpace(dTextSpace);
} }
pPage->DrawText(pText->GetX(), pText->GetY(), pText->GetCodes(), pText->GetCodesLen() * 2);
//------------------------------------
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))
{
oContText.Flush(pPage);
if (!oContText.Add(pCodes, unLen, dX, dY, dWidth))
{
pPage->DrawText(dX, dY, pCodes, unLen);
}
}
//-----------------------------------
//pPage->DrawText(pText->GetX(), pText->GetY(), pText->GetCodes(), pText->GetCodesLen());
} }
oContText.Flush(pPage);
pPage->EndText(); pPage->EndText();
} }
...@@ -319,6 +408,10 @@ void CPdfRenderer::CCommandManager::SetTransform(const CTransform& oTransform) ...@@ -319,6 +408,10 @@ void CPdfRenderer::CCommandManager::SetTransform(const CTransform& oTransform)
{ {
m_oTransform = oTransform; m_oTransform = oTransform;
} }
void CPdfRenderer::CCommandManager::SetTransform(const double& m11, const double& m12, const double& m21, const double& m22, const double& dx, const double& dy)
{
m_oTransform.Set(m11, m12, m21, m22, dx, dy);
}
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
// //
// CPdfRenderer // CPdfRenderer
...@@ -879,12 +972,15 @@ HRESULT CPdfRenderer::CommandDrawText(const std::wstring& wsUnicodeText, const d ...@@ -879,12 +972,15 @@ HRESULT CPdfRenderer::CommandDrawText(const std::wstring& wsUnicodeText, const d
unsigned char* pCodes = m_pFont->EncodeString(pUnicodes, unLen); unsigned char* pCodes = m_pFont->EncodeString(pUnicodes, unLen);
delete[] pUnicodes; delete[] pUnicodes;
CTransform& t = m_oTransform;
m_oCommandManager.SetTransform(t.m11, -t.m12, -t.m21, t.m22, MM_2_PT(t.dx + t.m21 * m_dPageHeight), MM_2_PT(m_dPageHeight - m_dPageHeight * t.m22 - t.dy));
CRendererTextCommand* pText = m_oCommandManager.AddText(pCodes, unLen * 2, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY)); CRendererTextCommand* pText = m_oCommandManager.AddText(pCodes, unLen * 2, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY));
pText->SetFont(m_pFont); pText->SetFont(m_pFont);
pText->SetSize(m_oFont.GetSize()); pText->SetSize(m_oFont.GetSize());
pText->SetColor(m_oBrush.GetColor1()); pText->SetColor(m_oBrush.GetColor1());
pText->SetAlpha((BYTE)m_oBrush.GetAlpha1()); pText->SetAlpha((BYTE)m_oBrush.GetAlpha1());
pText->SetCharSpace(m_oFont.GetCharSpace()); pText->SetCharSpace(MM_2_PT(m_oFont.GetCharSpace()));
return S_OK; return S_OK;
} }
......
...@@ -1450,6 +1450,7 @@ private: ...@@ -1450,6 +1450,7 @@ private:
CRendererTextCommand* AddText(unsigned char* pCodes, unsigned int nLen, const double& dX, const double& dY); CRendererTextCommand* AddText(unsigned char* pCodes, unsigned int nLen, const double& dX, const double& dY);
void Flush(); void Flush();
void SetTransform(const CTransform& oTransform); void SetTransform(const CTransform& oTransform);
void SetTransform(const double& m11, const double& m12, const double& m21, const double& m22, const double& dx, const double& dy);
private: private:
void Add(CRendererCommandBase* pCommand); void Add(CRendererCommandBase* pCommand);
void Clear(); void Clear();
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include "../../DesktopEditor/fontengine/ApplicationFonts.h" #include "../../DesktopEditor/fontengine/ApplicationFonts.h"
#include "../../DesktopEditor/raster/Metafile/MetaFile.h" #include "../../DesktopEditor/raster/Metafile/MetaFile.h"
#include <vector> #include <vector>
#include <ctime>
#ifdef DrawText #ifdef DrawText
...@@ -924,6 +926,8 @@ void TestOnlineBin() ...@@ -924,6 +926,8 @@ void TestOnlineBin()
CApplicationFonts oFonts; CApplicationFonts oFonts;
oFonts.Initialize(); oFonts.Initialize();
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++)
...@@ -938,6 +942,11 @@ void TestOnlineBin() ...@@ -938,6 +942,11 @@ void TestOnlineBin()
printf("%d of %d %S\n", nIndex, vFiles.size(), vFiles.at(nIndex).c_str()); printf("%d of %d %S\n", nIndex, vFiles.size(), vFiles.at(nIndex).c_str());
} }
clock_t oEndTime = clock();
double dElapsedSecs = double(oEndTime - oBeginTime) / CLOCKS_PER_SEC;
printf("%f\n", dElapsedSecs);
} }
void main() void main()
...@@ -957,4 +966,7 @@ void main() ...@@ -957,4 +966,7 @@ void main()
//TestDocument9(); //TestDocument9();
//TestMetafile(); //TestMetafile();
TestOnlineBin(); TestOnlineBin();
char q;
std::cin >> q;
} }
...@@ -107,11 +107,44 @@ namespace PdfWriter ...@@ -107,11 +107,44 @@ namespace PdfWriter
m_pToUnicodeStream = pToUnicodeDict->GetStream(); m_pToUnicodeStream = pToUnicodeDict->GetStream();
CreateCIDFont2(pFont); CreateCIDFont2(pFont);
//-----------------------------------------------------------------------------------------
FT_Init_FreeType(&m_pLibrary);
NSFile::CFileBinary oFile;
oFile.OpenFile(m_wsFontPath, false);
DWORD lFileSize = oFile.SizeFile();
m_pFaceMemory = new FT_Byte[lFileSize];
if (!m_pFaceMemory)
{
FT_Done_FreeType(m_pLibrary);
return;
}
NSFile::CFileBinary::ReadAllBytes(m_wsFontPath, &m_pFaceMemory, lFileSize);
FT_New_Memory_Face(m_pLibrary, m_pFaceMemory, lFileSize, m_unFontIndex, &m_pFace);
if (!m_pFace)
{
FT_Done_FreeType(m_pLibrary);
delete[] m_pFaceMemory;
m_pFaceMemory = NULL;
return;
}
} }
CFontCidTrueType::~CFontCidTrueType() CFontCidTrueType::~CFontCidTrueType()
{ {
if (m_pFontFile) if (m_pFontFile)
delete m_pFontFile; delete m_pFontFile;
if (m_pFace)
FT_Done_Face(m_pFace);
if (m_pLibrary)
FT_Done_FreeType(m_pLibrary);
if (m_pFaceMemory)
delete[] m_pFaceMemory;
} }
void CFontCidTrueType::CreateCIDFont2(CDictObject* pFont) void CFontCidTrueType::CreateCIDFont2(CDictObject* pFont)
{ {
...@@ -181,11 +214,39 @@ namespace PdfWriter ...@@ -181,11 +214,39 @@ namespace PdfWriter
} }
else else
{ {
m_mUnicodeToCode.insert(std::pair<unsigned int, unsigned short>(pUnicodes[unIndex], m_ushCodesCount)); unsigned int unUnicode = pUnicodes[unIndex];
ushCode = m_ushCodesCount; ushCode = m_ushCodesCount;
m_vUnicodes.push_back(pUnicodes[unIndex]);
m_ushCodesCount++; m_ushCodesCount++;
m_mUnicodeToCode.insert(std::pair<unsigned int, unsigned short>(unUnicode, ushCode));
m_vUnicodes.push_back(unUnicode);
unsigned short ushGID = GetGID(m_pFace, unUnicode);
m_vCodeToGid.push_back(ushGID);
//
m_mGlyphs.insert(std::pair<unsigned short, bool>(ushGID, true));
// (CompositeGlyf), (subglyfs)
if (0 == FT_Load_Glyph(m_pFace, ushGID, FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE))
{
for (int nSubIndex = 0; nSubIndex < m_pFace->glyph->num_subglyphs; nSubIndex++)
{
FT_Int nSubGID;
FT_UInt unFlags;
FT_Int nArg1;
FT_Int nArg2;
FT_Matrix oMatrix;
FT_Get_SubGlyph_Info(m_pFace->glyph, nSubIndex, &nSubGID, &unFlags, &nArg1, &nArg2, &oMatrix);
m_mGlyphs.insert(std::pair<unsigned short, bool>(nSubGID, true));
}
if (0 != m_pFace->units_per_EM)
m_vWidths.push_back((unsigned int)m_pFace->glyph->metrics.horiAdvance * 1000 / m_pFace->units_per_EM);
else
m_vWidths.push_back((unsigned int)m_pFace->glyph->metrics.horiAdvance);
}
} }
pEncodedString[2 * unIndex + 0] = (ushCode >> 8) & 0xFF; pEncodedString[2 * unIndex + 0] = (ushCode >> 8) & 0xFF;
...@@ -193,6 +254,13 @@ namespace PdfWriter ...@@ -193,6 +254,13 @@ namespace PdfWriter
} }
return pEncodedString; return pEncodedString;
} }
unsigned int CFontCidTrueType::GetWidth(unsigned short ushCode)
{
if (ushCode >= m_vWidths.size())
return 0;
return m_vWidths.at(ushCode);
}
void CFontCidTrueType::BeforeWrite() void CFontCidTrueType::BeforeWrite()
{ {
if (m_pFontFile) if (m_pFontFile)
...@@ -321,6 +389,7 @@ namespace PdfWriter ...@@ -321,6 +389,7 @@ namespace PdfWriter
FT_Done_Face(pFace); FT_Done_Face(pFace);
FT_Done_FreeType(pLibrary); FT_Done_FreeType(pLibrary);
delete[] pMemory;
*ppCodeToGid = pCodeToGID; *ppCodeToGid = pCodeToGID;
*ppWidths = pWidths; *ppWidths = pWidths;
......
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include "../../DesktopEditor/fontengine/FontManager.h"
#include "../../DesktopEditor/common/File.h"
#include FT_TRUETYPE_TABLES_H
namespace PdfWriter namespace PdfWriter
{ {
class CXref; class CXref;
...@@ -23,6 +27,7 @@ namespace PdfWriter ...@@ -23,6 +27,7 @@ namespace PdfWriter
CFontCidTrueType(CXref* pXref, CDocument* pDocument, const std::wstring& wsFontPath, unsigned int unIndex); CFontCidTrueType(CXref* pXref, CDocument* pDocument, const std::wstring& wsFontPath, unsigned int unIndex);
~CFontCidTrueType(); ~CFontCidTrueType();
unsigned char* EncodeString(unsigned int* pUnicodes, unsigned int unLen); unsigned char* EncodeString(unsigned int* pUnicodes, unsigned int unLen);
unsigned int GetWidth(unsigned short ushCode);
EFontType GetFontType() EFontType GetFontType()
{ {
return fontCIDType2; return fontCIDType2;
...@@ -51,6 +56,14 @@ namespace PdfWriter ...@@ -51,6 +56,14 @@ namespace PdfWriter
unsigned short m_ushCodesCount; // unsigned short m_ushCodesCount; //
std::map<unsigned int, unsigned short> m_mUnicodeToCode; // -> std::map<unsigned int, unsigned short> m_mUnicodeToCode; // ->
std::vector<unsigned int> m_vUnicodes; // -> std::vector<unsigned int> m_vUnicodes; // ->
std::vector<unsigned short> m_vCodeToGid;
std::vector<unsigned int> m_vWidths;
std::map<unsigned short, bool> m_mGlyphs;
FT_Library m_pLibrary;
FT_Face m_pFace;
FT_Byte* m_pFaceMemory;
}; };
} }
......
...@@ -925,6 +925,34 @@ namespace PdfWriter ...@@ -925,6 +925,34 @@ 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)
{
CheckGrMode(grmode_TEXT);
double dX = 0.0;
double dY = 0.0;
if (0 == m_oTextMatrix.m11)
{
dY = (dXpos - m_oTextMatrix.x) / m_oTextMatrix.m21;
dX = (dYpos - m_oTextMatrix.y - (dXpos - m_oTextMatrix.x) * m_oTextMatrix.m22 / m_oTextMatrix.m21) / m_oTextMatrix.m12;
}
else
{
dY = (dYpos - m_oTextMatrix.y - (dXpos - m_oTextMatrix.x) * m_oTextMatrix.m12 / m_oTextMatrix.m11) / (m_oTextMatrix.m22 - m_oTextMatrix.m21 * m_oTextMatrix.m12 / m_oTextMatrix.m11);
dX = (dXpos - m_oTextMatrix.x - dY * m_oTextMatrix.m21) / m_oTextMatrix.m11;
}
MoveTextPos(dX, dY);
m_pStream->WriteChar('[');
for (unsigned int unIndex = 0; unIndex < unCount; unIndex++)
{
WriteText(ppTexts[unIndex], pLens[unIndex]);
if (unIndex != unCount - 1)
m_pStream->WriteReal(pShifts[unIndex]);
}
m_pStream->WriteStr("]TJ\012");
}
void CPage::SetCharSpace(double dValue) void CPage::SetCharSpace(double dValue)
{ {
// Operator : Tc // Operator : Tc
......
...@@ -97,6 +97,9 @@ namespace PdfWriter ...@@ -97,6 +97,9 @@ namespace PdfWriter
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 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);
void SetPatternColorSpace(CImageTilePattern* pPattern); void SetPatternColorSpace(CImageTilePattern* pPattern);
......
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