mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Write Base14 fonts to pdf
This commit is contained in:
@ -891,7 +891,8 @@ bool CPdfEditor::EditPage(int nPageIndex)
|
||||
//TODO добавление шрифтов FreeText в общий m_pAppAplication чтобы writer мог использовать шрифты из reader
|
||||
oAnnot.free(); oSubtype.free();
|
||||
oTemp.arrayGetNF(nIndex, &oAnnot);
|
||||
pReader->AnnotFonts(&oAnnot);
|
||||
std::map<std::wstring, std::wstring> mapFont = pReader->AnnotFonts(&oAnnot);
|
||||
m_mFonts.insert(mapFont.begin(), mapFont.end());
|
||||
DictToCDictObject(&oAnnot, pArray, false, "");
|
||||
oAnnot.free();
|
||||
}
|
||||
@ -1292,3 +1293,18 @@ void CPdfEditor::EndMarkedContent()
|
||||
{
|
||||
pWriter->GetPage()->EndMarkedContent();
|
||||
}
|
||||
bool CPdfEditor::IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bItalic, std::wstring& wsFontPath)
|
||||
{
|
||||
std::map<std::wstring, std::wstring>::iterator it = m_mFonts.find(wsFontName);
|
||||
if (it == m_mFonts.end())
|
||||
return false;
|
||||
wsFontPath = it->second;
|
||||
if (wsFontName == L"Courier-Oblique")
|
||||
{
|
||||
bItalic = true;
|
||||
return true;
|
||||
}
|
||||
if (wsFontName == L"Symbol")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -56,12 +56,14 @@ public:
|
||||
bool IsEditPage();
|
||||
void AddShapeXML(const std::string& sXML);
|
||||
void EndMarkedContent();
|
||||
bool IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bItalic, std::wstring& wsFontPath);
|
||||
|
||||
private:
|
||||
void GetPageTree(XRef* xref, Object* pPagesRefObj);
|
||||
|
||||
std::wstring wsSrcFile;
|
||||
std::wstring wsPassword;
|
||||
std::map<std::wstring, std::wstring> m_mFonts;
|
||||
|
||||
CPdfReader* pReader;
|
||||
CPdfWriter* pWriter;
|
||||
|
||||
@ -883,7 +883,24 @@ HRESULT CPdfFile::put_FontName(const std::wstring& wsName)
|
||||
return S_FALSE;
|
||||
std::wstring wsFontName = wsName;
|
||||
if (m_pInternal->pEditor && wsFontName.find(L"Embedded: ") == 0)
|
||||
{
|
||||
wsFontName.erase(0, 10);
|
||||
bool bBold = false, bItalic = false;
|
||||
std::wstring wsFontPath;
|
||||
if (m_pInternal->pEditor->IsBase14(wsFontName, bBold, bItalic, wsFontPath))
|
||||
{
|
||||
m_pInternal->pWriter->AddFont(wsFontName, bBold, bItalic, wsFontPath, 0);
|
||||
if (bBold || bItalic)
|
||||
{
|
||||
LONG lStyle = 0;
|
||||
if (bBold)
|
||||
lStyle |= 1;
|
||||
if (bItalic)
|
||||
lStyle |= 2;
|
||||
put_FontStyle(lStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
return m_pInternal->pWriter->put_FontName(wsFontName);
|
||||
}
|
||||
HRESULT CPdfFile::get_FontPath(std::wstring* wsPath)
|
||||
|
||||
@ -170,7 +170,6 @@ HEADERS += \
|
||||
SrcWriter/Utils.h \
|
||||
SrcWriter/Metadata.h \
|
||||
SrcWriter/ICCProfile.h \
|
||||
SrcWriter/AnnotRenderer.h \
|
||||
SrcWriter/States.h
|
||||
|
||||
SOURCES += \
|
||||
@ -199,7 +198,6 @@ SOURCES += \
|
||||
SrcWriter/Streams.cpp \
|
||||
SrcWriter/Utils.cpp \
|
||||
SrcWriter/Metadata.cpp \
|
||||
SrcWriter/AnnotRenderer.cpp \
|
||||
SrcWriter/States.cpp
|
||||
|
||||
# PdfFile
|
||||
|
||||
@ -948,9 +948,9 @@ BYTE* CPdfReader::GetWidgets()
|
||||
oRes.ClearWithoutAttack();
|
||||
return bRes;
|
||||
}
|
||||
void CPdfReader::AnnotFonts(Object* pRefAnnot)
|
||||
std::map<std::wstring, std::wstring> CPdfReader::AnnotFonts(Object* pRefAnnot)
|
||||
{
|
||||
PdfReader::AnnotMarkup::SetFont(m_pPDFDocument, pRefAnnot, m_pFontManager, m_pFontList);
|
||||
return PdfReader::AnnotMarkup::SetFont(m_pPDFDocument, pRefAnnot, m_pFontManager, m_pFontList, 3);
|
||||
}
|
||||
BYTE* CPdfReader::GetWidgetFonts(int nTypeFonts)
|
||||
{
|
||||
|
||||
@ -82,7 +82,7 @@ public:
|
||||
BYTE* GetAPWidget (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nWidget = -1, const char* sView = NULL, const char* sBView = NULL);
|
||||
BYTE* GetAPAnnots (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot = -1, const char* sView = NULL);
|
||||
BYTE* GetButtonIcon(int nBackgroundColor, int nPageIndex, bool bBase64 = false, int nBWidget = -1, const char* sIView = NULL);
|
||||
void AnnotFonts(Object* pRefAnnot);
|
||||
std::map<std::wstring, std::wstring> AnnotFonts(Object* pRefAnnot);
|
||||
|
||||
private:
|
||||
PDFDoc* m_pPDFDocument;
|
||||
|
||||
@ -42,7 +42,6 @@
|
||||
#include "SrcWriter/FontTT.h"
|
||||
#include "SrcWriter/Destination.h"
|
||||
#include "SrcWriter/Field.h"
|
||||
#include "SrcWriter/AnnotRenderer.h"
|
||||
|
||||
#include "../DesktopEditor/graphics/Image.h"
|
||||
#include "../DesktopEditor/graphics/structures.h"
|
||||
@ -168,6 +167,7 @@ CPdfWriter::CPdfWriter(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA, IRend
|
||||
m_dPageWidth = 210;
|
||||
m_pPage = NULL;
|
||||
m_pFont = NULL;
|
||||
m_pFont14 = NULL;
|
||||
m_lClipMode = 0;
|
||||
|
||||
m_unFieldsCounter = 0;
|
||||
@ -740,6 +740,20 @@ HRESULT CPdfWriter::CommandDrawTextCHAR2(unsigned int* pUnicodes, const unsigned
|
||||
if (!IsPageValid())
|
||||
return S_FALSE;
|
||||
|
||||
if (m_bNeedUpdateTextFont)
|
||||
{
|
||||
if (!UpdateFont())
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (m_pFont14)
|
||||
{
|
||||
unsigned char* pCodes = new unsigned char[2];
|
||||
pCodes[0] = 0;
|
||||
pCodes[1] = *pUnicodes & 0xFF;
|
||||
return DrawText(pCodes, 2, dX, dY) ? S_OK : S_FALSE;
|
||||
}
|
||||
|
||||
unsigned char* pCodes = EncodeGID(unGid, pUnicodes, unUnicodeCount);
|
||||
if (!pCodes)
|
||||
return DrawTextToRenderer(&unGid, 1, dX, dY) ? S_OK : S_FALSE;
|
||||
@ -2047,6 +2061,7 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
pFreeTextAnnot->SetIT(pFTPr->GetIT());
|
||||
if (nFlags & (1 << 21))
|
||||
pFreeTextAnnot->SetIC(pFTPr->GetIC());
|
||||
/*
|
||||
std::vector<CAnnotFieldInfo::CMarkupAnnotPr::CFontData*> arrRC = pPr->GetRC();
|
||||
double dFontSize = 10.0;
|
||||
if (!arrRC.empty())
|
||||
@ -2063,6 +2078,7 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
if (m_bNeedUpdateTextFont)
|
||||
UpdateFont();
|
||||
pFreeTextAnnot->SetDA(m_pFont, dFontSize, oInfo.GetC());
|
||||
*/
|
||||
if (nFlags & (1 << 22))
|
||||
{
|
||||
PdfWriter::CPage* pCurPage = m_pPage;
|
||||
@ -2900,7 +2916,7 @@ bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, cons
|
||||
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, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY));
|
||||
pText->SetFont(m_pFont);
|
||||
pText->SetFont(m_pFont14 ? m_pFont : m_pFont);
|
||||
pText->SetSize(m_oFont.GetSize());
|
||||
pText->SetColor(m_oBrush.GetColor1());
|
||||
pText->SetAlpha((BYTE)m_oBrush.GetAlpha1());
|
||||
@ -2934,14 +2950,62 @@ bool CPdfWriter::PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen
|
||||
m_oPath.AddText(m_pFont, pCodes, unLen * 2, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY), m_oFont.GetSize(), MM_2_PT(m_oFont.GetCharSpace()));
|
||||
return true;
|
||||
}
|
||||
int CPdfWriter::IsBase14(const std::wstring& wsName)
|
||||
{
|
||||
if (wsName == L"Helvetica")
|
||||
return 0;
|
||||
if (wsName == L"Helvetica-Bold")
|
||||
return 1;
|
||||
if (wsName == L"Helvetica-Oblique")
|
||||
return 2;
|
||||
if (wsName == L"Helvetice-BoldOblique")
|
||||
return 3;
|
||||
if (wsName == L"Courier")
|
||||
return 4;
|
||||
if (wsName == L"Courier-Bold")
|
||||
return 5;
|
||||
if (wsName == L"Courier-Oblique")
|
||||
return 6;
|
||||
if (wsName == L"Courier-BoldOblique")
|
||||
return 7;
|
||||
if (wsName == L"Times")
|
||||
return 8;
|
||||
if (wsName == L"Times-Bold")
|
||||
return 9;
|
||||
if (wsName == L"Times-Oblique")
|
||||
return 10;
|
||||
if (wsName == L"Times-BoldOblique")
|
||||
return 11;
|
||||
if (wsName == L"Symbol")
|
||||
return 12;
|
||||
if (wsName == L"ZapfDingbats")
|
||||
return 13;
|
||||
return -1;
|
||||
}
|
||||
bool CPdfWriter::GetBaseFont14(const std::wstring& wsFontName, int nBase14)
|
||||
{
|
||||
std::wstring wsFontPath = m_oFont.GetPath();
|
||||
LONG lFaceIndex = m_oFont.GetFaceIndex();
|
||||
if (!FindFontPath(wsFontName, m_oFont.IsBold(), m_oFont.IsItalic(), wsFontPath, lFaceIndex))
|
||||
return false;
|
||||
if (!m_pFontManager->LoadFontFromFile(wsFontPath, lFaceIndex, m_oFont.GetSize(), 72, 72))
|
||||
return false;
|
||||
m_pFont14 = m_pDocument->CreateFont14((PdfWriter::EStandard14Fonts)nBase14);
|
||||
return !!m_pFont14;
|
||||
}
|
||||
bool CPdfWriter::UpdateFont()
|
||||
{
|
||||
m_bNeedUpdateTextFont = false;
|
||||
m_pFont14 = NULL;
|
||||
std::wstring wsFontPath = m_oFont.GetPath();
|
||||
LONG lFaceIndex = m_oFont.GetFaceIndex();
|
||||
if (L"" == wsFontPath)
|
||||
{
|
||||
if (!GetFontPath(m_oFont.GetName(), m_oFont.IsBold(), m_oFont.IsItalic(), wsFontPath, lFaceIndex))
|
||||
std::wstring wsFontName = m_oFont.GetName();
|
||||
int nBase14 = IsBase14(wsFontName);
|
||||
if (nBase14 >= 0 && GetBaseFont14(wsFontName, nBase14))
|
||||
return true;
|
||||
if (!GetFontPath(wsFontName, m_oFont.IsBold(), m_oFont.IsItalic(), wsFontPath, lFaceIndex))
|
||||
{
|
||||
m_pFont = NULL;
|
||||
return false;
|
||||
@ -2968,9 +3032,16 @@ bool CPdfWriter::UpdateFont()
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool CPdfWriter::GetFontPath(const std::wstring &wsFontName, const bool &bBold, const bool &bItalic, std::wstring& wsFontPath, LONG& lFaceIndex)
|
||||
void CPdfWriter::AddFont(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic, const std::wstring& wsFontPath, const LONG& lFaceIndex)
|
||||
{
|
||||
std::wstring _wsFontPath;
|
||||
LONG _lFaceIndex;
|
||||
if (FindFontPath(wsFontName, bBold, bItalic, _wsFontPath, _lFaceIndex))
|
||||
return;
|
||||
m_vFonts.push_back(TFontInfo(wsFontName, bBold, bItalic, wsFontPath, lFaceIndex));
|
||||
}
|
||||
bool CPdfWriter::FindFontPath(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic, std::wstring& wsFontPath, LONG& lFaceIndex)
|
||||
{
|
||||
bool bFind = false;
|
||||
for (int nIndex = 0, nCount = m_vFonts.size(); nIndex < nCount; nIndex++)
|
||||
{
|
||||
TFontInfo& oInfo = m_vFonts.at(nIndex);
|
||||
@ -2978,10 +3049,14 @@ bool CPdfWriter::GetFontPath(const std::wstring &wsFontName, const bool &bBold,
|
||||
{
|
||||
wsFontPath = oInfo.wsFontPath;
|
||||
lFaceIndex = oInfo.lFaceIndex;
|
||||
bFind = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CPdfWriter::GetFontPath(const std::wstring &wsFontName, const bool &bBold, const bool &bItalic, std::wstring& wsFontPath, LONG& lFaceIndex)
|
||||
{
|
||||
bool bFind = FindFontPath(wsFontName, bBold, bItalic, wsFontPath, lFaceIndex);
|
||||
|
||||
if (!bFind)
|
||||
{
|
||||
@ -3027,7 +3102,7 @@ PdfWriter::CFontCidTrueType* CPdfWriter::GetFont(const std::wstring& wsFontPath,
|
||||
}
|
||||
|
||||
std::wstring wsFontType = m_pFontManager->GetFontType();
|
||||
if (L"TrueType" == wsFontType || L"OpenType" == wsFontType || L"CFF" == wsFontType)
|
||||
if (L"TrueType" == wsFontType || L"OpenType" == wsFontType || L"CFF" == wsFontType || L"Type 1" == wsFontType)
|
||||
pFont = m_pDocument->CreateCidTrueTypeFont(wsFontPath, lFaceIndex);
|
||||
}
|
||||
|
||||
|
||||
@ -217,6 +217,7 @@ public:
|
||||
HRESULT EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWidgetsInfo* pFieldInfo, const std::wstring& wsTempDirectory);
|
||||
PdfWriter::CDocument* GetDocument();
|
||||
PdfWriter::CPage* GetPage();
|
||||
void AddFont(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic, const std::wstring& wsFontPath, const LONG& lFaceIndex);
|
||||
|
||||
private:
|
||||
PdfWriter::CImageDict* LoadImage(Aggplus::CImage* pImage, BYTE nAlpha);
|
||||
@ -224,7 +225,10 @@ private:
|
||||
bool DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY);
|
||||
bool DrawTextToRenderer(const unsigned int* unGid, const unsigned int& unLen, const double& dX, const double& dY);
|
||||
bool PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen, const double& dX, const double& dY, const unsigned int* pGids = NULL);
|
||||
int IsBase14(const std::wstring& wsFontName);
|
||||
bool GetBaseFont14(const std::wstring& wsFontName, int nBase14);
|
||||
bool UpdateFont();
|
||||
bool FindFontPath(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic, std::wstring& wsFontPath, LONG& lFaceIndex);
|
||||
bool GetFontPath(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic, std::wstring& wsFontPath, LONG& lFaceIndex);
|
||||
PdfWriter::CFontCidTrueType* GetFont(const std::wstring& wsFontPath, const LONG& lFontIndex);
|
||||
PdfWriter::CFontCidTrueType* GetFont(const std::wstring& wsFontName, const bool& bBold, const bool& bItalic);
|
||||
@ -252,6 +256,7 @@ private:
|
||||
PdfWriter::CDocument* m_pDocument;
|
||||
PdfWriter::CPage* m_pPage;
|
||||
PdfWriter::CFontCidTrueType* m_pFont;
|
||||
PdfWriter::CFont14* m_pFont14;
|
||||
PdfWriter::CShading* m_pShading;
|
||||
PdfWriter::CExtGrState* m_pShadingExtGrState;
|
||||
|
||||
|
||||
@ -2354,12 +2354,12 @@ bool FindFonts(Object* oStream, int nDepth, Object* oResFonts)
|
||||
oXObject.free();
|
||||
return false;
|
||||
}
|
||||
std::vector<std::wstring> AnnotMarkup::SetFont(PDFDoc* pdfDoc, Object* oAnnotRef, NSFonts::IFontManager* pFontManager, CPdfFontList *pFontList, int nTypeFonts)
|
||||
std::map<std::wstring, std::wstring> AnnotMarkup::SetFont(PDFDoc* pdfDoc, Object* oAnnotRef, NSFonts::IFontManager* pFontManager, CPdfFontList *pFontList, int nTypeFonts)
|
||||
{
|
||||
Object oAnnot, oObj;
|
||||
XRef* pXref = pdfDoc->getXRef();
|
||||
oAnnotRef->fetch(pXref, &oAnnot);
|
||||
std::vector<std::wstring> arrFontFreeText;
|
||||
std::map<std::wstring, std::wstring> arrFontFreeText;
|
||||
|
||||
Object oAP, oN, oR, oFonts;
|
||||
if (!oAnnot.dictLookup("AP", &oAP)->isDict() || !oAP.dictLookup("N", &oN)->isStream())
|
||||
@ -2389,6 +2389,7 @@ std::vector<std::wstring> AnnotMarkup::SetFont(PDFDoc* pdfDoc, Object* oAnnotRef
|
||||
std::string sFontName, sActual;
|
||||
bool bBold = false, bItalic = false;
|
||||
std::wstring sFontPath = GetFontData(pdfDoc, pFontManager, pFontList, &oFonts, &oFontRef, nTypeFonts, sFontName, sActual, bBold, bItalic);
|
||||
std::wstring wsFontName = UTF8_TO_U(sFontName);
|
||||
if (sFontPath.empty())
|
||||
{
|
||||
oFontRef.free();
|
||||
@ -2407,7 +2408,7 @@ std::vector<std::wstring> AnnotMarkup::SetFont(PDFDoc* pdfDoc, Object* oAnnotRef
|
||||
for (int nIndex = 0; nIndex < arrFontList->size(); ++nIndex)
|
||||
{
|
||||
if (((*arrFontList)[nIndex]->m_wsFontPath == sFontPath ||
|
||||
(*arrFontList)[nIndex]->m_wsFontName == UTF8_TO_U(sFontName)) &&
|
||||
(*arrFontList)[nIndex]->m_wsFontName == wsFontName) &&
|
||||
(*arrFontList)[nIndex]->m_bBold == (bBold ? 1 : 0) &&
|
||||
(*arrFontList)[nIndex]->m_bItalic == (bItalic ? 1 : 0))
|
||||
{
|
||||
@ -2417,7 +2418,6 @@ std::vector<std::wstring> AnnotMarkup::SetFont(PDFDoc* pdfDoc, Object* oAnnotRef
|
||||
}
|
||||
if (bNew)
|
||||
pAppFontList->Add(sFontPath, pFontStream);
|
||||
arrFontFreeText.push_back(sFontPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2425,6 +2425,7 @@ std::vector<std::wstring> AnnotMarkup::SetFont(PDFDoc* pdfDoc, Object* oAnnotRef
|
||||
if (pFontStream->CreateFromFile(sFontPath))
|
||||
pAppFontList->Add(sFontPath, pFontStream);
|
||||
}
|
||||
arrFontFreeText[wsFontName] = sFontPath;
|
||||
}
|
||||
|
||||
oAP.free(); oN.free(); oR.free(); oFonts.free();
|
||||
@ -2435,10 +2436,8 @@ std::vector<std::wstring> AnnotMarkup::SetFont(PDFDoc* pdfDoc, Object* oAnnotRef
|
||||
std::map<std::wstring, std::wstring> AnnotMarkup::SetFont(PDFDoc* pdfDoc, Object* oAnnotRef, NSFonts::IFontManager* pFontManager, CPdfFontList* pFontList, std::vector<CAnnotMarkup::CFontData*>& arrRC, int nTypeFonts)
|
||||
{
|
||||
std::map<std::wstring, std::wstring> mRes;
|
||||
if (arrRC.empty())
|
||||
return mRes;
|
||||
|
||||
std::vector<std::wstring> arrFontFreeText = SetFont(pdfDoc, oAnnotRef, pFontManager, pFontList, nTypeFonts);
|
||||
std::map<std::wstring, std::wstring> arrFontFreeText = SetFont(pdfDoc, oAnnotRef, pFontManager, pFontList, nTypeFonts);
|
||||
|
||||
CFontList* pAppFontList = (CFontList*)pFontManager->GetApplication()->GetList();
|
||||
for (int i = 0; i < arrRC.size(); ++i)
|
||||
@ -2504,7 +2503,8 @@ std::map<std::wstring, std::wstring> AnnotMarkup::SetFont(PDFDoc* pdfDoc, Object
|
||||
NSFonts::CFontInfo* pFontInfo = pAppFontList->GetByParams(oFontSelect);
|
||||
if (pFontInfo && !pFontInfo->m_wsFontPath.empty())
|
||||
{
|
||||
bool bFreeText = std::find(arrFontFreeText.begin(), arrFontFreeText.end(), pFontInfo->m_wsFontPath) != arrFontFreeText.end();
|
||||
std::wstring sFontPath = pFontInfo->m_wsFontPath;
|
||||
bool bFreeText = std::find_if(arrFontFreeText.begin(), arrFontFreeText.end(), [&sFontPath](auto&& p) { return p.second == sFontPath; }) != arrFontFreeText.end();
|
||||
std::wstring wsFontBaseName = pFontInfo->m_wsFontName;
|
||||
if (wsFontBaseName.length() > 7 && wsFontBaseName.at(6) == '+')
|
||||
{
|
||||
|
||||
@ -364,7 +364,7 @@ private:
|
||||
};
|
||||
namespace AnnotMarkup
|
||||
{
|
||||
std::vector<std::wstring> SetFont(PDFDoc* pdfDoc, Object* oAnnotRef, NSFonts::IFontManager* pFontManager, CPdfFontList *pFontList, int nTypeFonts = 3);
|
||||
std::map<std::wstring, std::wstring> SetFont(PDFDoc* pdfDoc, Object* oAnnotRef, NSFonts::IFontManager* pFontManager, CPdfFontList *pFontList, int nTypeFonts = 3);
|
||||
std::map<std::wstring, std::wstring> SetFont(PDFDoc* pdfDoc, Object* oAnnotRef, NSFonts::IFontManager* pFontManager, CPdfFontList *pFontList, std::vector<CAnnotMarkup::CFontData*>& arrRC, int nTypeFonts = 3);
|
||||
std::vector<CAnnotMarkup::CFontData*> ReadRC(const std::string& sRC);
|
||||
}
|
||||
|
||||
@ -1,664 +0,0 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#include "AnnotRenderer.h"
|
||||
|
||||
#include "../../DesktopEditor/graphics/GraphicsPath.h"
|
||||
|
||||
#define MM_2_PT(X) ((X) * 72.0 / 25.4)
|
||||
#define PT_2_MM(X) ((X) * 25.4 / 72.0)
|
||||
|
||||
#define LONG_2_BOOL(X) ((X) ? true : false)
|
||||
|
||||
namespace PdfWriter
|
||||
{
|
||||
CAnnotRenderer::CAnnotRenderer(NSFonts::IApplicationFonts* pAppFonts)
|
||||
{
|
||||
m_pAppFonts = pAppFonts;
|
||||
m_bNeedUpdateTextFont = true;
|
||||
}
|
||||
CAnnotRenderer::~CAnnotRenderer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// тип рендерера-----------------------------------------------------------------------------
|
||||
HRESULT CAnnotRenderer::get_Type(LONG* lType)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
//-------- Функции для работы со страницей --------------------------------------------------
|
||||
HRESULT CAnnotRenderer::NewPage()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_Height(double* dHeight)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_Height(const double& dHeight)
|
||||
{
|
||||
m_dPageHeight = dHeight;
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_Width(double* dWidth)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_Width(const double& dWidth)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_DpiX(double* dDpiX)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_DpiY(double* dDpiY)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// pen --------------------------------------------------------------------------------------
|
||||
HRESULT CAnnotRenderer::get_PenColor(LONG* lColor)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenColor(const LONG& lColor)
|
||||
{
|
||||
m_oPen.SetColor(lColor);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_PenAlpha(LONG* lAlpha)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenAlpha(const LONG& lAlpha)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_PenSize(double* dSize)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenSize(const double& dSize)
|
||||
{
|
||||
m_oPen.SetSize(dSize);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_PenDashStyle(BYTE* nDashStyle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenDashStyle(const BYTE& nDashStyle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_PenLineStartCap(BYTE* nCapStyle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenLineStartCap(const BYTE& nCapStyle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_PenLineEndCap(BYTE* nCapStyle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenLineEndCap(const BYTE& nCapStyle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_PenLineJoin(BYTE* nJoinStyle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenLineJoin(const BYTE& nJoinStyle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_PenDashOffset(double* dOffset)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenDashOffset(const double& dOffset)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_PenAlign(LONG* lAlign)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenAlign(const LONG& lAlign)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_PenMiterLimit(double* dMiter)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_PenMiterLimit(const double& dMiter)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PenDashPattern(double* pPattern, LONG lCount)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// brush ------------------------------------------------------------------------------------
|
||||
HRESULT CAnnotRenderer::get_BrushType(LONG* lType)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushType(const LONG& lType)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushColor1(LONG* lColor)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushColor1(const LONG& lColor)
|
||||
{
|
||||
if (lColor != m_oBrush.GetColor1())
|
||||
m_oBrush.SetColor1(lColor);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushAlpha1(LONG* lAlpha)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushAlpha1(const LONG& lAlpha)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushColor2(LONG* lColor)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushColor2(const LONG& lColor)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushAlpha2(LONG* lAlpha)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushAlpha2(const LONG& lAlpha)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushTexturePath(std::wstring* wsPath)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushTexturePath(const std::wstring& wsPath)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushTextureImage(Aggplus::CImage** pImage)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushTextureImage(Aggplus::CImage* pImage)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushTextureMode(LONG* lMode)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushTextureMode(const LONG& lMode)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushTextureAlpha(LONG* lAlpha)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushTextureAlpha(const LONG& lAlpha)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushTransform(Aggplus::CMatrix& oMatrix)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushTransform(const Aggplus::CMatrix& oMatrix)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_BrushLinearAngle(double* dAngle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushLinearAngle(const double& dAngle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_BrushGradientColors(LONG* pColors, double* pPositions, LONG lCount)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// font -------------------------------------------------------------------------------------
|
||||
HRESULT CAnnotRenderer::get_FontName(std::wstring* wsName)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_FontName(const std::wstring& wsName)
|
||||
{
|
||||
if (wsName != m_oFont.GetName())
|
||||
{
|
||||
m_oFont.SetName(wsName);
|
||||
m_bNeedUpdateTextFont = true;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_FontPath(std::wstring* wsPath)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_FontPath(const std::wstring& wsPath)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_FontSize(double* dSize)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_FontSize(const double& dSize)
|
||||
{
|
||||
if (fabs(dSize - m_oFont.GetSize()) > 0.001)
|
||||
m_oFont.SetSize(dSize);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_FontStyle(LONG* lStyle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_FontStyle(const LONG& lStyle)
|
||||
{
|
||||
if (lStyle != m_oFont.GetStyle())
|
||||
{
|
||||
m_oFont.SetStyle(lStyle);
|
||||
m_bNeedUpdateTextFont = true;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_FontStringGID(INT* bGid)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_FontStringGID(const INT& bGid)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_FontCharSpace(double* dSpace)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_FontCharSpace(const double& dSpace)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::get_FontFaceIndex(int* lFaceIndex)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_FontFaceIndex(const int& lFaceIndex)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
//-------- Функции для вывода текста --------------------------------------------------------
|
||||
HRESULT CAnnotRenderer::CommandDrawTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::CommandDrawText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::CommandDrawTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::CommandDrawTextCHAR2 (unsigned int* pUnicodes, const unsigned int& unUnicodeCount, const unsigned int& unGid, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
unsigned char* pCodes = EncodeGID(unGid, pUnicodes, unUnicodeCount);
|
||||
if (!pCodes)
|
||||
return DrawTextToRenderer(&unGid, 1, dX, dY) ? S_OK : S_FALSE;
|
||||
return DrawText(pCodes, 2, dX, dY) ? S_OK : S_FALSE;
|
||||
}
|
||||
|
||||
//-------- Маркеры для команд ---------------------------------------------------------------
|
||||
HRESULT CAnnotRenderer::BeginCommand(const DWORD& lType)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::EndCommand(const DWORD& dwType)
|
||||
{
|
||||
/*
|
||||
if (c_nClipType == dwType)
|
||||
{
|
||||
m_oCommandManager.Flush();
|
||||
m_pPage->GrSave();
|
||||
m_lClipDepth++;
|
||||
UpdateTransform();
|
||||
|
||||
m_oPath.Clip(m_pPage, c_nClipRegionTypeEvenOdd & m_lClipMode);
|
||||
}
|
||||
else if (c_nResetClipType == dwType)
|
||||
{
|
||||
m_oCommandManager.Flush();
|
||||
while (m_lClipDepth)
|
||||
{
|
||||
m_pPage->GrRestore();
|
||||
m_lClipDepth--;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
//-------- Функции для работы с Graphics Path -----------------------------------------------
|
||||
HRESULT CAnnotRenderer::PathCommandMoveTo(const double& dX, const double& dY)
|
||||
{
|
||||
m_oPath.MoveTo(MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY));
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandLineTo(const double& dX, const double& dY)
|
||||
{
|
||||
m_oPath.LineTo(MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY));
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandLinesTo(double* pPoints, const int& nCount)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe)
|
||||
{
|
||||
m_oPath.CurveTo(MM_2_PT(dX1), MM_2_PT(m_dPageHeight - dY1), MM_2_PT(dX2), MM_2_PT(m_dPageHeight - dY2), MM_2_PT(dXe), MM_2_PT(m_dPageHeight - dYe));
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandCurvesTo(double* pPoints, const int& nCount)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandClose()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandEnd()
|
||||
{
|
||||
m_oPath.Clear();
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::DrawPath(const LONG& lType)
|
||||
{
|
||||
/*
|
||||
m_oCommandManager.Flush();
|
||||
|
||||
bool bStroke = LONG_2_BOOL(lType & c_nStroke);
|
||||
bool bFill = LONG_2_BOOL(lType & c_nWindingFillMode);
|
||||
bool bEoFill = LONG_2_BOOL(lType & c_nEvenOddFillMode);
|
||||
|
||||
m_pPage->GrSave();
|
||||
UpdateTransform();
|
||||
|
||||
if (bStroke)
|
||||
UpdatePen();
|
||||
|
||||
std::wstring sTextureOldPath = L"";
|
||||
std::wstring sTextureTmpPath = L"";
|
||||
|
||||
if (bFill || bEoFill)
|
||||
{
|
||||
if (c_BrushTypeTexture == m_oBrush.GetType())
|
||||
{
|
||||
sTextureOldPath = m_oBrush.GetTexturePath();
|
||||
sTextureTmpPath = GetDownloadFile(sTextureOldPath, wsTempDirectory);
|
||||
|
||||
if (!sTextureTmpPath.empty())
|
||||
m_oBrush.SetTexturePath(sTextureTmpPath);
|
||||
}
|
||||
|
||||
UpdateBrush(pAppFonts, wsTempDirectory);
|
||||
}
|
||||
|
||||
if (!m_pShading)
|
||||
{
|
||||
m_oPath.Draw(m_pPage, bStroke, bFill, bEoFill);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bFill || bEoFill)
|
||||
{
|
||||
m_pPage->GrSave();
|
||||
m_oPath.Clip(m_pPage, bEoFill);
|
||||
|
||||
if (NULL != m_pShadingExtGrState)
|
||||
m_pPage->SetExtGrState(m_pShadingExtGrState);
|
||||
|
||||
m_pPage->DrawShading(m_pShading);
|
||||
m_pPage->GrRestore();
|
||||
}
|
||||
|
||||
if (bStroke)
|
||||
m_oPath.Draw(m_pPage, bStroke, false, false);
|
||||
}
|
||||
|
||||
m_pPage->GrRestore();
|
||||
|
||||
if (!sTextureTmpPath.empty())
|
||||
{
|
||||
m_oBrush.SetTexturePath(sTextureOldPath);
|
||||
|
||||
if (NSFile::CFileBinary::Exists(sTextureTmpPath))
|
||||
NSFile::CFileBinary::Remove(sTextureTmpPath);
|
||||
}
|
||||
|
||||
*/
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandStart()
|
||||
{
|
||||
m_oPath.Clear();
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandGetCurrentPoint(double* dX, double* dY)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::PathCommandTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
//-------- Функции для вывода изображений ---------------------------------------------------
|
||||
HRESULT CAnnotRenderer::DrawImage(IGrObject* pImage, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// transform --------------------------------------------------------------------------------
|
||||
HRESULT CAnnotRenderer::SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY)
|
||||
{
|
||||
m_oTransform.Set(dM11, dM12, dM21, dM22, dX, dY);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::ResetTransform()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// clip ------------------------------------------------------------------------------------
|
||||
HRESULT CAnnotRenderer::get_ClipMode(LONG* lMode)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::put_ClipMode(const LONG& lMode)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// additiaonal params ----------------------------------------------------------------------
|
||||
HRESULT CAnnotRenderer::CommandLong(const LONG& lType, const LONG& lCommand)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::CommandDouble(const LONG& lType, const double& dCommand)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CAnnotRenderer::CommandString(const LONG& lType, const std::wstring& sCommand)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// внутренние функции ----------------------------------------------------------------------
|
||||
bool CAnnotRenderer::DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool CAnnotRenderer::DrawTextToRenderer(const unsigned int* unGid, const unsigned int& unLen, const double& dX, const double& dY)
|
||||
{
|
||||
Aggplus::CGraphicsPathSimpleConverter simplifier;
|
||||
simplifier.SetRenderer(this);
|
||||
m_pFontManager->LoadFontByName(m_oFont.GetName(), m_oFont.GetSize(), (int)m_oFont.GetStyle(), 72.0, 72.0);
|
||||
PathCommandEnd();
|
||||
if (simplifier.PathCommandText2(L"", (const int*)unGid, unLen, m_pFontManager, dX, dY, 0, 0))
|
||||
{
|
||||
DrawPath(c_nWindingFillMode);
|
||||
PathCommandEnd();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CAnnotRenderer::UpdateFont()
|
||||
{
|
||||
/*
|
||||
m_bNeedUpdateTextFont = false;
|
||||
std::wstring wsFontPath = m_oFont.GetPath();
|
||||
LONG lFaceIndex = m_oFont.GetFaceIndex();
|
||||
if (L"" == wsFontPath)
|
||||
{
|
||||
if (!GetFontPath(m_oFont.GetName(), m_oFont.IsBold(), m_oFont.IsItalic(), wsFontPath, lFaceIndex))
|
||||
{
|
||||
m_pFont = NULL;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_oFont.SetNeedDoBold(false);
|
||||
m_oFont.SetNeedDoItalic(false);
|
||||
|
||||
m_pFont = NULL;
|
||||
if (L"" != wsFontPath)
|
||||
{
|
||||
m_pFont = GetFont(wsFontPath, lFaceIndex);
|
||||
if (m_pFont)
|
||||
{
|
||||
if (m_oFont.IsItalic() && !m_pFont->IsItalic())
|
||||
m_oFont.SetNeedDoItalic(true);
|
||||
|
||||
if (m_oFont.IsBold() && !m_pFont->IsBold())
|
||||
m_oFont.SetNeedDoBold(true);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
void UpdateTransform()
|
||||
{
|
||||
|
||||
}
|
||||
unsigned char* CAnnotRenderer::EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount)
|
||||
{
|
||||
if (m_bNeedUpdateTextFont)
|
||||
{
|
||||
if (!UpdateFont())
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!m_pFont)
|
||||
return NULL;
|
||||
|
||||
unsigned char* pCodes = new unsigned char[2];
|
||||
if (!pCodes)
|
||||
return NULL;
|
||||
|
||||
unsigned short ushCode = m_pFont->EncodeGID(unGID, pUnicodes, unUnicodesCount);
|
||||
pCodes[0] = (ushCode >> 8) & 0xFF;
|
||||
pCodes[1] = ushCode & 0xFF;
|
||||
return pCodes;
|
||||
}
|
||||
}
|
||||
@ -1,196 +0,0 @@
|
||||
/*
|
||||
* (c) Copyright Ascensio System SIA 2010-2023
|
||||
*
|
||||
* This program is a free software product. You can redistribute it and/or
|
||||
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||
* version 3 as published by the Free Software Foundation. In accordance with
|
||||
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||
* of any third-party rights.
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||
*
|
||||
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
|
||||
* street, Riga, Latvia, EU, LV-1050.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of the Program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU AGPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||
* grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||
* well as technical writing content are licensed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
*
|
||||
*/
|
||||
#ifndef _PDF_WRITER_SRC_ANNOT_RENDERER_H
|
||||
#define _PDF_WRITER_SRC_ANNOT_RENDERER_H
|
||||
|
||||
#include "../../DesktopEditor/graphics/IRenderer.h"
|
||||
#include "../../DesktopEditor/graphics/pro/Fonts.h"
|
||||
|
||||
#include "States.h"
|
||||
#include "FontCidTT.h"
|
||||
|
||||
namespace PdfWriter
|
||||
{
|
||||
class CAnnotRenderer : public IRenderer
|
||||
{
|
||||
public:
|
||||
CAnnotRenderer(NSFonts::IApplicationFonts* pAppFonts);
|
||||
virtual ~CAnnotRenderer();
|
||||
|
||||
public:
|
||||
// тип рендерера-----------------------------------------------------------------------------
|
||||
virtual HRESULT get_Type(LONG* lType);
|
||||
//-------- Функции для работы со страницей --------------------------------------------------
|
||||
virtual HRESULT NewPage();
|
||||
virtual HRESULT get_Height(double* dHeight);
|
||||
virtual HRESULT put_Height(const double& dHeight);
|
||||
virtual HRESULT get_Width(double* dWidth);
|
||||
virtual HRESULT put_Width(const double& dWidth);
|
||||
virtual HRESULT get_DpiX(double* dDpiX);
|
||||
virtual HRESULT get_DpiY(double* dDpiY);
|
||||
|
||||
// pen --------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_PenColor(LONG* lColor);
|
||||
virtual HRESULT put_PenColor(const LONG& lColor);
|
||||
virtual HRESULT get_PenAlpha(LONG* lAlpha);
|
||||
virtual HRESULT put_PenAlpha(const LONG& lAlpha);
|
||||
virtual HRESULT get_PenSize(double* dSize);
|
||||
virtual HRESULT put_PenSize(const double& dSize);
|
||||
virtual HRESULT get_PenDashStyle(BYTE* nDashStyle);
|
||||
virtual HRESULT put_PenDashStyle(const BYTE& nDashStyle);
|
||||
virtual HRESULT get_PenLineStartCap(BYTE* nCapStyle);
|
||||
virtual HRESULT put_PenLineStartCap(const BYTE& nCapStyle);
|
||||
virtual HRESULT get_PenLineEndCap(BYTE* nCapStyle);
|
||||
virtual HRESULT put_PenLineEndCap(const BYTE& nCapStyle);
|
||||
virtual HRESULT get_PenLineJoin(BYTE* nJoinStyle);
|
||||
virtual HRESULT put_PenLineJoin(const BYTE& nJoinStyle);
|
||||
virtual HRESULT get_PenDashOffset(double* dOffset);
|
||||
virtual HRESULT put_PenDashOffset(const double& dOffset);
|
||||
virtual HRESULT get_PenAlign(LONG* lAlign);
|
||||
virtual HRESULT put_PenAlign(const LONG& lAlign);
|
||||
virtual HRESULT get_PenMiterLimit(double* dMiter);
|
||||
virtual HRESULT put_PenMiterLimit(const double& dMiter);
|
||||
virtual HRESULT PenDashPattern(double* pPattern, LONG lCount);
|
||||
|
||||
// brush ------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_BrushType(LONG* lType);
|
||||
virtual HRESULT put_BrushType(const LONG& lType);
|
||||
virtual HRESULT get_BrushColor1(LONG* lColor);
|
||||
virtual HRESULT put_BrushColor1(const LONG& lColor);
|
||||
virtual HRESULT get_BrushAlpha1(LONG* lAlpha);
|
||||
virtual HRESULT put_BrushAlpha1(const LONG& lAlpha);
|
||||
virtual HRESULT get_BrushColor2(LONG* lColor);
|
||||
virtual HRESULT put_BrushColor2(const LONG& lColor);
|
||||
virtual HRESULT get_BrushAlpha2(LONG* lAlpha);
|
||||
virtual HRESULT put_BrushAlpha2(const LONG& lAlpha);
|
||||
virtual HRESULT get_BrushTexturePath(std::wstring* wsPath);
|
||||
virtual HRESULT put_BrushTexturePath(const std::wstring& wsPath);
|
||||
virtual HRESULT get_BrushTextureImage(Aggplus::CImage** pImage);
|
||||
virtual HRESULT put_BrushTextureImage(Aggplus::CImage* pImage);
|
||||
virtual HRESULT get_BrushTextureMode(LONG* lMode);
|
||||
virtual HRESULT put_BrushTextureMode(const LONG& lMode);
|
||||
virtual HRESULT get_BrushTextureAlpha(LONG* lAlpha);
|
||||
virtual HRESULT put_BrushTextureAlpha(const LONG& lAlpha);
|
||||
virtual HRESULT get_BrushTransform(Aggplus::CMatrix& oMatrix);
|
||||
virtual HRESULT put_BrushTransform(const Aggplus::CMatrix& oMatrix);
|
||||
virtual HRESULT get_BrushLinearAngle(double* dAngle);
|
||||
virtual HRESULT put_BrushLinearAngle(const double& dAngle);
|
||||
virtual HRESULT BrushRect(const INT& nVal, const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight);
|
||||
virtual HRESULT BrushBounds(const double& dLeft, const double& dTop, const double& dWidth, const double& dHeight);
|
||||
virtual HRESULT put_BrushGradientColors(LONG* pColors, double* pPositions, LONG lCount);
|
||||
|
||||
// font -------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_FontName(std::wstring* wsName);
|
||||
virtual HRESULT put_FontName(const std::wstring& wsName);
|
||||
virtual HRESULT get_FontPath(std::wstring* wsPath);
|
||||
virtual HRESULT put_FontPath(const std::wstring& wsPath);
|
||||
virtual HRESULT get_FontSize(double* dSize);
|
||||
virtual HRESULT put_FontSize(const double& dSize);
|
||||
virtual HRESULT get_FontStyle(LONG* lStyle);
|
||||
virtual HRESULT put_FontStyle(const LONG& lStyle);
|
||||
virtual HRESULT get_FontStringGID(INT* bGid);
|
||||
virtual HRESULT put_FontStringGID(const INT& bGid);
|
||||
virtual HRESULT get_FontCharSpace(double* dSpace);
|
||||
virtual HRESULT put_FontCharSpace(const double& dSpace);
|
||||
virtual HRESULT get_FontFaceIndex(int* lFaceIndex);
|
||||
virtual HRESULT put_FontFaceIndex(const int& lFaceIndex);
|
||||
|
||||
//-------- Функции для вывода текста --------------------------------------------------------
|
||||
virtual HRESULT CommandDrawTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
virtual HRESULT CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
virtual HRESULT CommandDrawText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
virtual HRESULT CommandDrawTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
virtual HRESULT CommandDrawTextCHAR2 (unsigned int* unUnicode, const unsigned int& unUnicodeCount, const unsigned int& unGid, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
|
||||
//-------- Маркеры для команд ---------------------------------------------------------------
|
||||
virtual HRESULT BeginCommand(const DWORD& lType);
|
||||
virtual HRESULT EndCommand(const DWORD& lType);
|
||||
|
||||
//-------- Функции для работы с Graphics Path -----------------------------------------------
|
||||
virtual HRESULT PathCommandMoveTo(const double& dX, const double& dY);
|
||||
virtual HRESULT PathCommandLineTo(const double& dX, const double& dY);
|
||||
virtual HRESULT PathCommandLinesTo(double* pPoints, const int& nCount);
|
||||
virtual HRESULT PathCommandCurveTo(const double& dX1, const double& dY1, const double& dX2, const double& dY2, const double& dXe, const double& dYe);
|
||||
virtual HRESULT PathCommandCurvesTo(double* pPoints, const int& nCount);
|
||||
virtual HRESULT PathCommandArcTo(const double& dX, const double& dY, const double& dW, const double& dH, const double& dStartAngle, const double& dSweepAngle);
|
||||
virtual HRESULT PathCommandClose();
|
||||
virtual HRESULT PathCommandEnd();
|
||||
virtual HRESULT DrawPath(const LONG& lType);
|
||||
virtual HRESULT PathCommandStart();
|
||||
virtual HRESULT PathCommandGetCurrentPoint(double* dX, double* dY);
|
||||
virtual HRESULT PathCommandTextCHAR (const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
virtual HRESULT PathCommandTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
virtual HRESULT PathCommandText (const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
virtual HRESULT PathCommandTextEx (const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int nGidsCount, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
|
||||
//-------- Функции для вывода изображений ---------------------------------------------------
|
||||
virtual HRESULT DrawImage(IGrObject* pImage, const double& dX, const double& dY, const double& dW, const double& dH);
|
||||
virtual HRESULT DrawImageFromFile(const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha = 255);
|
||||
|
||||
// transform --------------------------------------------------------------------------------
|
||||
virtual HRESULT SetTransform(const double& dM11, const double& dM12, const double& dM21, const double& dM22, const double& dX, const double& dY);
|
||||
virtual HRESULT GetTransform(double* dM11, double* dM12, double* dM21, double* dM22, double* dX, double* dY);
|
||||
virtual HRESULT ResetTransform();
|
||||
|
||||
// clip ------------------------------------------------------------------------------------
|
||||
virtual HRESULT get_ClipMode(LONG* lMode);
|
||||
virtual HRESULT put_ClipMode(const LONG& lMode);
|
||||
|
||||
// additiaonal params ----------------------------------------------------------------------
|
||||
virtual HRESULT CommandLong(const LONG& lType, const LONG& lCommand);
|
||||
virtual HRESULT CommandDouble(const LONG& lType, const double& dCommand);
|
||||
virtual HRESULT CommandString(const LONG& lType, const std::wstring& sCommand);
|
||||
|
||||
private:
|
||||
bool DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY);
|
||||
bool DrawTextToRenderer(const unsigned int* unGid, const unsigned int& unLen, const double& dX, const double& dY);
|
||||
bool UpdateFont();
|
||||
void UpdateTransform();
|
||||
unsigned char* EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount);
|
||||
|
||||
private:
|
||||
NSFonts::IApplicationFonts* m_pAppFonts;
|
||||
NSFonts::IFontManager* m_pFontManager;
|
||||
|
||||
CFontCidTrueType* m_pFont;
|
||||
|
||||
CPenState m_oPen;
|
||||
CBrushState m_oBrush;
|
||||
CFontState m_oFont;
|
||||
CPath m_oPath;
|
||||
CTransform m_oTransform;
|
||||
bool m_bNeedUpdateTextFont;
|
||||
double m_dPageHeight;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _PDF_WRITER_SRC_ANNOT_RENDERER_H
|
||||
@ -30,6 +30,7 @@
|
||||
*
|
||||
*/
|
||||
#include "Font14.h"
|
||||
#include "Document.h"
|
||||
|
||||
namespace PdfWriter
|
||||
{
|
||||
@ -57,4 +58,4 @@ namespace PdfWriter
|
||||
Add("Subtype", "Type1");
|
||||
Add("BaseFont", c_sStandardFontNames[(int)eType]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,4 +50,4 @@ namespace PdfWriter
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _PDF_WRITER_SRC_FONT14_H
|
||||
#endif // _PDF_WRITER_SRC_FONT14_H
|
||||
|
||||
Reference in New Issue
Block a user