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

Реализована функция отрисовки текста, выставления шрифта (только если он...

Реализована функция отрисовки текста, выставления шрифта (только если он TrueType), выставления трансформа.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@63156 954022d7-b5bf-4e40-9824-e11837661b57
parent 8bb23352
...@@ -3,18 +3,39 @@ ...@@ -3,18 +3,39 @@
#include "Src/Document.h" #include "Src/Document.h"
#include "Src/Pages.h" #include "Src/Pages.h"
#include "Src/Image.h" #include "Src/Image.h"
#include "Src/Font.h"
#include "Src/FontCidTT.h"
#include "../DesktopEditor/graphics/Image.h" #include "../DesktopEditor/graphics/Image.h"
#include "../DesktopEditor/raster/BgraFrame.h" #include "../DesktopEditor/raster/BgraFrame.h"
#include "../DesktopEditor/cximage/CxImage/ximage.h" #include "../DesktopEditor/cximage/CxImage/ximage.h"
#include "../DesktopEditor/fontengine/ApplicationFonts.h"
#include "../DesktopEditor/fontengine/FontManager.h"
#define MM_2_PT(X) ((X) * 72.0 / 25.4) #define MM_2_PT(X) ((X) * 72.0 / 25.4)
#define PT_2_MM(X) ((X) * 25.4 / 72.0) #define PT_2_MM(X) ((X) * 25.4 / 72.0)
#ifdef DrawText
#undef DrawText
#endif
using namespace PdfWriter; using namespace PdfWriter;
CPdfRenderer::CPdfRenderer() #define HI_SURROGATE_START 0xD800
#define HI_SURROGATE_END 0xDBFF
#define LO_SURROGATE_START 0xDC00
#define LO_SURROGATE_END 0xDFFF
CPdfRenderer::CPdfRenderer(CApplicationFonts* pAppFonts)
{ {
m_pAppFonts = pAppFonts;
//
m_pFontManager = pAppFonts->GenerateFontManager();
CFontsCache* pMeasurerCache = new CFontsCache();
pMeasurerCache->SetStreams(pAppFonts->GetStreams());
m_pFontManager->SetOwnerCache(pMeasurerCache);
m_pDocument = new CDocument(); m_pDocument = new CDocument();
if (!m_pDocument || !m_pDocument->CreateNew()) if (!m_pDocument || !m_pDocument->CreateNew())
{ {
...@@ -26,11 +47,12 @@ CPdfRenderer::CPdfRenderer() ...@@ -26,11 +47,12 @@ CPdfRenderer::CPdfRenderer()
m_dPageHeight = 297; m_dPageHeight = 297;
m_dPageWidth = 210; m_dPageWidth = 210;
m_pPage = NULL; m_pPage = NULL;
m_pFont = NULL;
} }
CPdfRenderer::~CPdfRenderer() CPdfRenderer::~CPdfRenderer()
{ {
if (m_pDocument) RELEASEOBJECT(m_pDocument);
delete m_pDocument; RELEASEINTERFACE(m_pFontManager);
} }
void CPdfRenderer::SaveToFile(const std::wstring& wsPath) void CPdfRenderer::SaveToFile(const std::wstring& wsPath)
{ {
...@@ -407,7 +429,77 @@ HRESULT CPdfRenderer::CommandDrawTextCHAR(const LONG& lUnicode, const double& dX ...@@ -407,7 +429,77 @@ HRESULT CPdfRenderer::CommandDrawTextCHAR(const LONG& lUnicode, const double& dX
} }
HRESULT CPdfRenderer::CommandDrawText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset) HRESULT CPdfRenderer::CommandDrawText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset)
{ {
// TODO: if (!IsPageValid() || !wsUnicodeText.size())
return S_FALSE;
m_pPage->GrSave();
UpdateTransform();
UpdateFont();
if (!m_pFont)
return S_FALSE;
unsigned int* pUnicodes = new unsigned int[wsUnicodeText.size()];
if (!pUnicodes)
return S_FALSE;
unsigned int* pOutput = pUnicodes;
unsigned int unLen = 0;
if (2 == sizeof(wchar_t))
{
const wchar_t* wsEnd = wsUnicodeText.c_str() + wsUnicodeText.size();
wchar_t* wsInput = (wchar_t*)wsUnicodeText.c_str();
wchar_t wLeading, wTrailing;
unsigned int unCode;
while (wsInput < wsEnd)
{
wLeading = *wsInput++;
if (wLeading < 0xD800 || wLeading > 0xDFFF)
{
pUnicodes[unLen++] = (unsigned int)wLeading;
}
else if (wLeading >= 0xDC00)
{
//
continue;
}
else
{
unCode = (wLeading & 0x3FF) << 10;
wTrailing = *wsInput++;
if (wTrailing < 0xDC00 || wTrailing > 0xDFFF)
{
//
continue;
}
else
{
pUnicodes[unLen++] = (unCode | (wTrailing & 0x3FF) + 0x10000);
}
}
}
}
else
{
unLen = wsUnicodeText.size();
for (unsigned int unIndex = 0; unIndex < unLen; unIndex++)
{
pUnicodes[unIndex] = (unsigned int)wsUnicodeText.at(unIndex);
}
}
unsigned char* pCodes = m_pFont->EncodeString(pUnicodes, unLen);
delete[] pUnicodes;
m_pPage->BeginText();
m_pPage->SetFontAndSize(m_pFont, m_oFont.GetSize());
m_pPage->DrawText(MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY), pCodes, unLen * 2);
m_pPage->EndText();
m_pPage->GrRestore();
return S_OK; return S_OK;
} }
HRESULT CPdfRenderer::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags) HRESULT CPdfRenderer::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH, const double& dBaselineOffset, const DWORD& dwFlags)
...@@ -568,17 +660,22 @@ HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const d ...@@ -568,17 +660,22 @@ HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const d
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
HRESULT CPdfRenderer::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY) HRESULT CPdfRenderer::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY)
{ {
// TODO: m_oTransform.Set(dM11, dM12, dM21, dM22, dX, dY);
return S_OK; return S_OK;
} }
HRESULT CPdfRenderer::GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY) HRESULT CPdfRenderer::GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY)
{ {
// TODO: *dM11 = m_oTransform.m11;
*dM12 = m_oTransform.m12;
*dM21 = m_oTransform.m21;
*dM22 = m_oTransform.m22;
*dX = m_oTransform.dx;
*dY = m_oTransform.dy;
return S_OK; return S_OK;
} }
HRESULT CPdfRenderer::ResetTransform() HRESULT CPdfRenderer::ResetTransform()
{ {
// TODO: m_oTransform.Reset();
return S_OK; return S_OK;
} }
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
...@@ -625,10 +722,14 @@ HRESULT CPdfRenderer::DrawImage1bpp(Pix* pImageBuffer, const unsigned int& unWid ...@@ -625,10 +722,14 @@ HRESULT CPdfRenderer::DrawImage1bpp(Pix* pImageBuffer, const unsigned int& unWid
if (!IsPageValid() || !pImageBuffer) if (!IsPageValid() || !pImageBuffer)
return S_OK; return S_OK;
// TODO: m_pPage->GrSave();
UpdateTransform();
CImageDict* pPdfImage = m_pDocument->CreateImage(); CImageDict* pPdfImage = m_pDocument->CreateImage();
pPdfImage->LoadBW(pImageBuffer, unWidth, unHeight); pPdfImage->LoadBW(pImageBuffer, unWidth, unHeight);
m_pPage->DrawImage(pPdfImage, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY - dH), MM_2_PT(dW), MM_2_PT(dH)); m_pPage->DrawImage(pPdfImage, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY - dH), MM_2_PT(dW), MM_2_PT(dH));
m_pPage->GrRestore();
return S_OK; return S_OK;
} }
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
...@@ -674,4 +775,36 @@ bool CPdfRenderer::DrawImage(Aggplus::CImage* pImage, const double& dX, const do ...@@ -674,4 +775,36 @@ bool CPdfRenderer::DrawImage(Aggplus::CImage* pImage, const double& dX, const do
return true; return true;
} }
void CPdfRenderer::UpdateFont()
{
std::wstring& wsFontPath = m_oFont.GetPath();
LONG lFaceIndex = m_oFont.GetFaceIndex();
if (L"" == wsFontPath)
{
CFontSelectFormat oFontSelect;
oFontSelect.wsName = new std::wstring(m_oFont.GetName());
oFontSelect.bItalic = new INT(m_oFont.IsItalic() ? 0 : 1);
oFontSelect.bItalic = new INT(m_oFont.IsBold() ? 0 : 1);
CFontInfo* pFontInfo = m_pFontManager->GetFontInfoByParams(oFontSelect);
wsFontPath = pFontInfo->m_wsFontPath;
lFaceIndex = pFontInfo->m_lIndex;
}
m_pFont = NULL;
if (L"" != wsFontPath)
{
// TODO: , TrueType, OpenType
LONG lFaceIndex = m_oFont.GetFaceIndex();
m_pFontManager->LoadFontFromFile(wsFontPath, lFaceIndex, 10, 72, 72);
std::wstring wsFontType = m_pFontManager->GetFontType();
if (L"TrueType" == wsFontType || L"OpenType" == wsFontType || L"CFF" == wsFontType)
m_pFont = m_pDocument->CreateTrueTypeFont(wsFontPath, lFaceIndex);
}
}
void CPdfRenderer::UpdateTransform()
{
CTransform& t = m_oTransform;
m_pPage->Concat(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));
}
This diff is collapsed.
...@@ -851,9 +851,13 @@ std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstrin ...@@ -851,9 +851,13 @@ std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstrin
} }
return vwsNames; return vwsNames;
} }
void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, const int nType) void ConvertFolder(std::wstring wsFolderPath, const int nType)
{ {
CPdfRenderer oRenderer; CApplicationFonts oFonts;
oFonts.Initialize();
MetaFile::CMetaFile oMetaFile(&oFonts);
CPdfRenderer oRenderer(&oFonts);
oMetaFile.Close(); oMetaFile.Close();
...@@ -865,6 +869,7 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co ...@@ -865,6 +869,7 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co
case MetaFile::c_lMetaWmf: sExt = L"wmf"; break; case MetaFile::c_lMetaWmf: sExt = L"wmf"; break;
case MetaFile::c_lMetaSvm: sExt = L"svm"; break; case MetaFile::c_lMetaSvm: sExt = L"svm"; break;
} }
double dPx2Mm = 25.4 / 96;
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, sExt); std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, sExt);
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++) for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
{ {
...@@ -874,14 +879,17 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co ...@@ -874,14 +879,17 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co
wsFilePath.append(vFiles.at(nIndex)); wsFilePath.append(vFiles.at(nIndex));
if (oMetaFile.LoadFromFile(wsFilePath.c_str())) if (oMetaFile.LoadFromFile(wsFilePath.c_str()))
{ {
double dW = 210; double dW, dH, dX, dY;
double dH = 297; oMetaFile.GetBounds(&dX, &dY, &dW, &dH);
//double dW, dH, dX, dY;
//oMetaFile.GetBounds(&dX, &dY, &dW, &dH); dW *= dPx2Mm;
dH *= dPx2Mm;
dX *= dPx2Mm;
dY *= dPx2Mm;
oRenderer.put_Width(dW); oRenderer.put_Width(dW);
oRenderer.put_Height(dH); oRenderer.put_Height(dH);
oMetaFile.DrawOnRenderer(&oRenderer, 0, 0, dW, dH); oMetaFile.DrawOnRenderer(&oRenderer, -dX, -dY, dW, dH);
oMetaFile.Close(); oMetaFile.Close();
} }
...@@ -892,11 +900,7 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co ...@@ -892,11 +900,7 @@ void ConvertFolder(MetaFile::CMetaFile &oMetaFile, std::wstring wsFolderPath, co
} }
void TestMetafile() void TestMetafile()
{ {
CApplicationFonts oFonts; ConvertFolder(L"D://Test Files//Emf//", MetaFile::c_lMetaEmf);
oFonts.Initialize();
MetaFile::CMetaFile oMetaFile(&oFonts);
ConvertFolder(oMetaFile, L"D://Test Files//Emf//", MetaFile::c_lMetaEmf);
} }
void main() void main()
......
...@@ -105,6 +105,7 @@ namespace PdfWriter ...@@ -105,6 +105,7 @@ namespace PdfWriter
m_vExtGrStates.clear(); m_vExtGrStates.clear();
m_vPages.clear(); m_vPages.clear();
m_vShadings.clear(); m_vShadings.clear();
m_vTTFonts.clear();
} }
bool CDocument::SaveToFile(const std::wstring& wsPath) bool CDocument::SaveToFile(const std::wstring& wsPath)
{ {
...@@ -372,7 +373,19 @@ namespace PdfWriter ...@@ -372,7 +373,19 @@ namespace PdfWriter
} }
CFontCidTrueType* CDocument::CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex) CFontCidTrueType* CDocument::CreateTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex)
{ {
return new CFontCidTrueType(m_pXref, this, wsFontPath, unIndex); for (int nIndex = 0, nCount = m_vTTFonts.size(); nIndex < nCount; nIndex++)
{
TFontInfo& oInfo = m_vTTFonts.at(nIndex);
if (wsFontPath == oInfo.wsPath && unIndex == oInfo.unIndex)
return oInfo.pFont;
}
CFontCidTrueType* pFont = new CFontCidTrueType(m_pXref, this, wsFontPath, unIndex);
if (!pFont)
return NULL;
m_vTTFonts.push_back(TFontInfo(wsFontPath, unIndex, pFont));
return pFont;
} }
char* CDocument::GetTTFontTag() char* CDocument::GetTTFontTag()
{ {
......
...@@ -81,6 +81,21 @@ namespace PdfWriter ...@@ -81,6 +81,21 @@ namespace PdfWriter
CDictObject* CreatePageLabel(EPageNumStyle eStyle, unsigned int unFirstPage, const char* sPrefix); CDictObject* CreatePageLabel(EPageNumStyle eStyle, unsigned int unFirstPage, const char* sPrefix);
private: private:
struct TFontInfo
{
TFontInfo(const std::wstring& path, const unsigned int& index, CFontCidTrueType* font)
{
wsPath = path;
unIndex = index;
pFont = font;
}
std::wstring wsPath;
unsigned int unIndex;
CFontCidTrueType* pFont;
};
CCatalog* m_pCatalog; CCatalog* m_pCatalog;
COutline* m_pOutlines; COutline* m_pOutlines;
CXref* m_pXref; CXref* m_pXref;
...@@ -98,6 +113,7 @@ namespace PdfWriter ...@@ -98,6 +113,7 @@ namespace PdfWriter
char m_sTTFontTag[8]; // 6 символов + '+' + 0x00 ("BAAAAA+/0") char m_sTTFontTag[8]; // 6 символов + '+' + 0x00 ("BAAAAA+/0")
CJbig2Global* m_pJbig2; CJbig2Global* m_pJbig2;
std::vector<CShading*> m_vShadings; std::vector<CShading*> m_vShadings;
std::vector<TFontInfo> m_vTTFonts;
friend class CFontCidTrueType; friend class CFontCidTrueType;
}; };
......
...@@ -23,10 +23,10 @@ namespace PdfWriter ...@@ -23,10 +23,10 @@ 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);
EFontType GetFontType() EFontType GetFontType()
{ {
return fontCIDType2; return fontCIDType2;
} }
private: private:
......
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