Skip to content

Commit

Permalink
Merge pull request 'COfficeDrawingPageParams' (#98) from feature/pdf-…
Browse files Browse the repository at this point in the history
…params into develop

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/98
  • Loading branch information
K0R0L committed Nov 18, 2024
2 parents c83e50d + c1b0102 commit 4bf363f
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 12 deletions.
14 changes: 13 additions & 1 deletion DesktopEditor/graphics/pro/officedrawingfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ enum OfficeDrawingFileType
odftUndefined = 255
};

struct COfficeDrawingPageParams
{
bool m_bNeedDrawAnnotation;

COfficeDrawingPageParams() : m_bNeedDrawAnnotation(true){}

void SetDrawAnnotation(bool bDraw)
{
m_bNeedDrawAnnotation = bDraw;
}
};

class GRAPHICS_DECL IOfficeDrawingFile
{
public:
Expand Down Expand Up @@ -70,7 +82,7 @@ class GRAPHICS_DECL IOfficeDrawingFile
// Pages info/draw
virtual int GetPagesCount() = 0;
virtual void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY) = 0;
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak) = 0;
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak, COfficeDrawingPageParams* pParams = NULL) = 0;

// Common methods/wrappers on GetPageInfo + DrawPageOnRenderer
virtual unsigned char* ConvertToPixels(int nPageIndex, int nRasterW, int nRasterH,
Expand Down
2 changes: 1 addition & 1 deletion DjVuFile/DjVu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void CDjVuFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, d
if (m_pImplementation)
m_pImplementation->GetPageInfo(nPageIndex, pdWidth, pdHeight, pdDpiX, pdDpiY);
}
void CDjVuFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
void CDjVuFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak, COfficeDrawingPageParams* pParams)
{
if (m_pImplementation)
m_pImplementation->DrawPageOnRenderer(pRenderer, nPageIndex, pBreak);
Expand Down
2 changes: 1 addition & 1 deletion DjVuFile/DjVu.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DJVU_DECL_EXPORT CDjVuFile : public IOfficeDrawingFile

virtual int GetPagesCount();
virtual void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak, COfficeDrawingPageParams* pParams = NULL);
virtual std::wstring GetInfo();

void ConvertToPdf(const std::wstring& path);
Expand Down
3 changes: 2 additions & 1 deletion PdfFile/PdfFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,12 @@ bool CPdfFile::ValidMetaData()
return false;
return m_pInternal->pReader->ValidMetaData();
}
void CPdfFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
void CPdfFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak, COfficeDrawingPageParams* pParams)
{
if (!m_pInternal->pReader)
return;
pRenderer->CommandLong(c_nPenWidth0As1px, 1);
m_pInternal->pReader->SetParams(pParams);
m_pInternal->pReader->DrawPageOnRenderer(pRenderer, nPageIndex, pBreak);
}
std::wstring CPdfFile::GetInfo()
Expand Down
2 changes: 1 addition & 1 deletion PdfFile/PdfFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PDFFILE_DECL_EXPORT CPdfFile : public IOfficeDrawingFile, public IRenderer

virtual int GetPagesCount();
virtual void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak, COfficeDrawingPageParams* pParams = NULL);
virtual std::wstring GetInfo();
virtual BYTE* GetStructure();
virtual BYTE* GetLinks(int nPageIndex);
Expand Down
11 changes: 10 additions & 1 deletion PdfFile/PdfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ CPdfReader::CPdfReader(NSFonts::IApplicationFonts* pAppFonts)
SetCMapFile(NSFile::GetProcessDirectory() + L"/cmap.bin");
#else
globalParams->setDrawFormFields(gFalse);
//globalParams->setDrawAnnotations(gFalse);
globalParams->setDrawAnnotations(gFalse);
SetCMapMemory(NULL, 0);
#endif

Expand Down Expand Up @@ -448,6 +448,15 @@ void CPdfReader::Close()
RELEASEOBJECT(m_pPDFDocument);
m_mFonts.clear();
}
void CPdfReader::SetParams(COfficeDrawingPageParams* pParams)
{
if (!pParams)
return;

GBool bDraw = pParams->m_bNeedDrawAnnotation ? gTrue : gFalse;
globalParams->setDrawFormFields(bDraw);
globalParams->setDrawAnnotations(bDraw);
}

int CPdfReader::GetError()
{
Expand Down
1 change: 1 addition & 0 deletions PdfFile/PdfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class CPdfReader

void Close();

void SetParams(COfficeDrawingPageParams* pParams);
std::wstring GetTempDirectory();
void SetTempDirectory(const std::wstring& directory);

Expand Down
6 changes: 2 additions & 4 deletions PdfFile/lib/xpdf/Page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
obj.free();

// draw (non-form) annotations
if (globalParams->getDrawAnnotations()) {
if (true) {
annotList = new Annots(doc, getAnnots(&obj));
obj.free();
annotList->generateAnnotAppearances();
Expand All @@ -392,12 +392,10 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
if (abortCheckCbk && (*abortCheckCbk)(abortCheckCbkData)) {
break;
}
#ifdef BUILDING_WASM_MODULE
sType = annotList->getAnnot(i)->getType();
if (sType->cmp("Link") == 0 || sType->cmp("FileAttachment") == 0 ||
if (globalParams->getDrawAnnotations() || sType->cmp("Link") == 0 || sType->cmp("FileAttachment") == 0 ||
sType->cmp("Sound") == 0 || sType->cmp("Movie") == 0 || sType->cmp("Screen") == 0 || sType->cmp("PrinterMark") == 0 ||
sType->cmp("TrapNet") == 0 || sType->cmp("Watermark") == 0 || sType->cmp("3D") == 0 || sType->cmp("Redact") == 0)
#endif
annotList->getAnnot(i)->draw(gfx, printing);
}
}
Expand Down
2 changes: 1 addition & 1 deletion XpsFile/XpsFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void CXpsFile::GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, do
*pdDpiX = 25.4;
*pdDpiY = 25.4;
}
void CXpsFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
void CXpsFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak, COfficeDrawingPageParams* pParams)
{
if (!m_pInternal->m_pDocument)
return;
Expand Down
2 changes: 1 addition & 1 deletion XpsFile/XpsFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class XPS_DECL_EXPORT CXpsFile : public IOfficeDrawingFile

virtual int GetPagesCount();
virtual void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY);
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak);
virtual void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak, COfficeDrawingPageParams* pParams = NULL);
virtual std::wstring GetInfo();

#ifndef DISABLE_PDF_CONVERTATION
Expand Down

0 comments on commit 4bf363f

Please sign in to comment.