///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
// All rights reserved.
//
// This software and its documentation and related materials are owned by
// the Alliance. The software may only be incorporated into application
// programs owned by members of the Alliance, subject to a signed
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable
// trade secrets of the Alliance and its suppliers. The software is also
// protected by copyright law and international treaty provisions. Application
// programs incorporating this software must include the following statement
// with their copyright notices:
//
// This application incorporates Open Design Alliance software pursuant to a license
// agreement with Open Design Alliance.
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
// All rights reserved.
//
// By use of this software, its documentation or related materials, you
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// PdfExportParamsHolder.h : definition of the PdfExportParamsHolder class
//
///////////////////////////////////////////////////////////////////////////////
#ifndef PDF_EXPORT_PARAMS_HOLDER_DEFINED
#define PDF_EXPORT_PARAMS_HOLDER_DEFINED
#include "PdfExportParams.h"
#define STL_USING_MAP
#define STL_USING_STRING
#include "OdaSTL.h"
#include "PdfDocument.h"
#include "PdfIContentCommands.h"
#include "PdfFontOptimizer.h"
#include "PdfType3Optimizer.h"
#include "PdfPageDictionary.h"
#include "2dExportUtils.h"
/** \details
A data type that represents a smart pointer to an OdGsBaseModel object.
*/
typedef OdSmartPtr OdGsBaseModelPtr;
/** \details
Contains declarations for exporting to 2D PDF.
*/
namespace TD_PDF_2D_EXPORT {
/** \details
A data type that represents a map of frozen layers (name - layer object).
*/
typedef std::map FrozenLayerMap;
/** \details
This class implements exporting to PDF.
*/
class PdfExportParamsHolder
{
// Members
//
PDFDocument &m_Document; // PDF document for implementing the export process.
PDFIContentCommands *m_pContentCommands; // Pointer to the content commands for a PDF document.
PDFPageDictionary *m_pCurPage;
PDFExportParams m_Params; // PDF export parameters.
PDFFontOptimizer &m_FontOptimizer; // Font optimization options for a PDF document.
PDFType3Optimizer &m_Type3Optimizer; // Type optimization options for a PDF document.
FrozenLayerMap m_OffLayers; // Names of all invisible layers contained in a PDF document.
FrozenLayerMap m_FrozenLayers;
OdStringArray* m_BookmarkNames; // Names for bookmarks.
OdGePoint3dArray* m_BookmarkPoints; // Points for bookmarks.
public:
/** \details
Creates a new instance of the PdfExportParamsHolder class.
\param document [in] A PDFDocument object.
\param font_optimizer [in] A PDFFontOptimizer object.
\param type_3_optimizer [in] A PDFType3Optimizer object.
*/
PdfExportParamsHolder(PDFDocument& document, PDFFontOptimizer& font_optimizer, PDFType3Optimizer& type_3_optimizer);
/** \details
Destroys the instance of the PdfExportParamsHolder class.
*/
virtual ~PdfExportParamsHolder();
// Implementation
/** \details
Retrieves page parameters for a specified layout.
\param pLayout [in] A pointer to the layout.
\param pageParams [out] A reference to the OdGsPageParams object where the page parameters are written after a successful method call.
\returns A value of the PDFResultEx enumeration that is equal to exOk if the method is successful or an appropriate error code otherwise.
\remarks
* Returns a set of page parameters for a specified layout (specified within the pLayout parameter).
* Also returns the result of getting page parameters (an instance of the PDFResultEx enumeration).
* Page parameters are written to the pageParams parameter (a reference to an object of the OdGsPageParams class).
* getPageParamsFromLayout() is a static method.
*/
PDFResultEx getPageParamsFromLayout(OdRxObject* pLayout, OdGsPageParams& pageParams) const;
/** \details
Initiates PDF export with specified parameters.
\param pParams [in] A reference to the PDFExportParams class instance containing export parameter values.
\returns A value of the PDFResultEx enumeration that is equal to exOk if the method is successful or an appropriate error code otherwise.
\remarks
* Initiates PDF export with specified parameters (passed using the pParams parameter).
* Returns an instance of the PDFResultEx class as the result of the initiation.
*/
PDFResultEx init(const PDFExportParams &pParams);
/** \details
Shows all layers of the database.
\param pDb [in] A raw pointer to the database object.
\param pCtx [in] A raw pointer to the OdGiContext object associated with the context object
\remarks
Layers are determined in the m_Params member variable.
*/
void prepareLayers(OdDbBaseDatabase* pDb, OdGiContext* pCtx);
/** \details
Retrieves the PDFDocument object that is used for the PDF export.
\returns A reference to a PDFDocument object (m_Document member variable).
*/
PDFDocument &document()
{
return m_Document;
}
/** \details
Retrieves the PDFFontOptimizer class instance that is used for the PDF export.
\returns A reference to a PDFFontOptimizer class instance that is contained in the m_FontOptimizer member variable.
*/
PDFFontOptimizer &getFontOptimizer() { return m_FontOptimizer; }
/** \details
Retrieves the PDFType3Optimizer object that represents the type optimization options for the PDF export.
\returns A reference to a PDFType3Optimizer object that is contained in the m_Type3Optimizer property value.
*/
PDFType3Optimizer &getType3Optimizer() { return m_Type3Optimizer; }
/** \details
Retrieves a pointer to a PDFIContentCommands object that can be used for handling a PDF document created as the result of the export process.
\returns A pointer to a PDFIContentCommands object.
*/
PDFIContentCommands *ContentCommands()
{
return m_pContentCommands;
}
/** \details
Sets a new PDFIContentCommands object that can be used for handling a PDF document created as the result of the export process.
\param content_commands [in] A pointer to a PDFIContentCommands object.
*/
void setContentCommands(PDFIContentCommands * content_commands)
{
m_pContentCommands = content_commands;
}
/** \details
Sets a new current page for the PDF export process.
\param current_page [in] A pointer to a PDFPageDictionary object that represents the current page.
*/
void setCurrentPage(PDFPageDictionary * current_page)
{
m_pCurPage = current_page;
}
/** \details
Requests the current page for the PDF export process.
\returns A pointer to a PDFPageDictionary object that represents the current page.
*/
PDFPageDictionary *CurrentPage()
{
return m_pCurPage;
}
/** \details
Retrieves the PDF export parameters.
\returns A constant reference to a PDFExportParams object that contains the PDF export options.
\remarks
* PDF export options are stored in the m_Params property.
* Returned PDF export options are read-only.
*/
const PDFExportParams& getParams() const
{
return m_Params;
}
/** \details
Retrieves the PDF export parameters.
\returns A reference to a PDFExportParams object that contains the PDF export options.
\remarks
* PDF export options are stored in the m_Params property.
* Any modification of the returned object causes respective changes in the PDF export options within the object.
*/
PDFExportParams& getParams()
{
return m_Params;
}
/** \details
Retrieves the color palette used for the PDF export.
\returns A pointer to the array of ODCOLORREF values that represent the color palette.
*/
const ODCOLORREF* getPalette() const
{
return m_Params.palette();
}
/** \details
Checks whether the layer with a specified name is visible.
\param layerName [in] A string that contains the layer name.
\returns
Returns true if the layer with the specified name (passed in the layerName parameter) is visible in the origin PDF document, or false otherwise.
If the specified layer doesn't exist, returns false.
*/
bool isLayerOriginallyVisible(const OdString &layerName) const;
/** \details
Retrieves frozen layers.
\returns A map that contains frozen layers specified with their names.
*/
const FrozenLayerMap& getFrozenLayers() const
{
return m_FrozenLayers;
}
/** \details
Adds frozen layer to map.
\param layerName [in] A name of the layer.
\returns true if layer has been added, false otherwise
*/
bool addFrozenLayer(const OdString& layerName);
/** \details
Retrieves a database from the array of databases with a specified index.
\param index [in] An unsigned 32-bit integer value that contains the array index.
\returns A smart pointer to the OdDbBaseDatabase object.
\remarks
If the database array is empty, only the database that is used is returned.
*/
OdDbBaseDatabasePtr getDatabase(OdUInt32 index) const
{
if(!m_Params.databases().size())
return m_Params.database();
OdRxObjectPtrArray paramDBs = m_Params.databases();
OdPDF::OdDbToPdfWrapperIfacePtr pDbWrap = dynamic_cast(paramDBs[index].get());
if(pDbWrap)
return pDbWrap->getDatabase();
else
return m_Params.databases().at(index);
}
/** \details
Sets new bookmark names for the PDF export process.
\param names [in] A pointer to a string array that contains bookmark names.
*/
void setBookmarkNames(OdStringArray* names) { m_BookmarkNames = names; }
/** \details
Retrieves the bookmark names.
\returns A pointer to a string array that contains bookmark names.
*/
OdStringArray* getBookmarkNames() { return m_BookmarkNames; }
/** \details
Sets new bookmark points for the PDF export process.
\param points [in] A pointer to the array of 3D points that represent the bookmark points.
*/
void setBookmarksPoints(OdGePoint3dArray* points) { m_BookmarkPoints = points; }
/** \details
Retrieves the bookmark points.
\returns A pointer to the array of 3D points that represent the bookmark points.
*/
OdGePoint3dArray* getBookmarksPoints() const { return m_BookmarkPoints; }
};
/** \details
A class that implements a pointer to an PdfExportParamsHolder object.
*/
class PdfExportParamsHolderPointer
{
PdfExportParamsHolder *m_ParamsHolder;
public:
/** \details
Retrieves a raw pointer to the PdfExportParamsHolder object.
\returns A pointer to the PdfExportParamsHolder object.
\remarks
If the internal raw pointer is NULL, the method throws the eNullPtr exception.
*/
PdfExportParamsHolder* safeGetPointer() const
{
if (NULL == m_ParamsHolder)
throw OdError(::eNullPtr);
return m_ParamsHolder;
}
/** \details
Creates a specific pointer for a PdfExportParamsHolder object from a raw pointer.
\param params_holder [in] A raw pointer.
*/
PdfExportParamsHolderPointer(PdfExportParamsHolder* params_holder)
: m_ParamsHolder(params_holder)
{
}
/** \details
Destroys the pointer to the PdfExportParamsHolder object.
*/
~PdfExportParamsHolderPointer()
{
}
/** \details
The "arrow" operator for a pointer to the PdfExportParamsHolder object.
\returns A raw pointer to the PdfExportParamsHolder object.
*/
PdfExportParamsHolder* operator->() { return safeGetPointer(); }
/** \details
The "arrow" operator for a pointer to the PdfExportParamsHolder object.
\returns A raw pointer to the PdfExportParamsHolder object.
*/
const PdfExportParamsHolder* operator->() const { return safeGetPointer(); }
/** \details
The operator that casts this pointer to the PdfExportParamsHolder object to a raw pointer to the PdfExportParamsHolder object.
\returns A raw pointer to the PdfExportParamsHolder object.
*/
operator PdfExportParamsHolder*() { return safeGetPointer(); }
/** \details
The operator that casts this pointer to the PdfExportParamsHolder object to a raw pointer to the PdfExportParamsHolder object.
\returns A raw pointer to the PdfExportParamsHolder object.
*/
operator const PdfExportParamsHolder*() const { return safeGetPointer(); }
};
}
#endif //PDF_EXPORT_PARAMS_HOLDER_DEFINED