/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// #ifndef ODTTFFONTSCACHE_INCLUDED #define ODTTFFONTSCACHE_INCLUDED #include "TD_PackPush.h" #include "RxObject.h" #include "Gi/GiTextStyle.h" #include "OdVector.h" #include "Ge/GeMatrix3d.h" #include "Gi/GiConveyorGeometry.h" #include "Gi/GiEmptyGeometry.h" #include "ThreadsCounter.h" #include "SharedPtr.h" #include "Tr/TrVisTexture.h" #define STL_USING_MAP #include "OdaSTL.h" class OdGsFiler; #ifdef OD_TTFFONTSCACHE_SHAREABLENAMESPACE namespace OD_TTFFONTSCACHE_SHAREABLENAMESPACE { #endif // OD_TTFFONTSCACHE_SHAREABLENAMESPACE // Callbacks interface for OdTtfFontsCache //DOM-IGNORE-BEGIN /** \details */ class OdTtfFontsCacheCallback { public: virtual OdRxObjectPtr tfcNewMetafile(void *pSessionId) = 0; virtual OdGiConveyorGeometry *tfcBeginMetafile(OdRxObject *pMetafile, void *pSessionId) = 0; virtual void tfcFinalizeMetafile(OdRxObject *pMetafile, void *pSessionId) = 0; virtual void tfcPlayMetafile(const OdGeMatrix3d &xForm, const OdRxObject *pMetafile, void *pSessionId) const = 0; virtual bool tfcSaveMetafile(const OdRxObject* /*pMetafile*/, OdGsFiler * /*pFiler*/) { return false; } virtual OdRxObjectPtr tfcLoadMetafile(OdGsFiler * /*pFiler*/) { return OdRxObjectPtr(); } }; //DOM-IGNORE-END // OdTtfFontsCache /** \details */ class OdTtfFontsCache : public OdRxObject, public OdTtfFontsCacheCallback { public: /** Key for entire font. */ typedef std::pair FontKey; /** Key for font character */ typedef OdUInt32 CharKey; protected: /** Character cache */ struct CharCache { /** Character metafile. */ OdRxObjectPtr m_pMetafile; /** Side movement multiplier. */ double m_sideMult; OdTrVisRawTexturePtr m_pTexture;//Detailed texture that supports text rotation }; /** Map for characters cache. */ typedef std::map CharMap; /** Font cache. */ struct FontCache { /** Pointer to font. */ OdFont *m_pFont; /** Cache data. */ CharMap m_cache; /** Pointer to Mutex. */ OdMutexPtr m_mutex; /** \details Default constructor for the FontCache struct. */ FontCache() : m_pFont(NULL) { } /** \details Constructor for the FontCache struct. Creates an instance with the specified font data. \param pFont [in] Pointer to font data. */ FontCache(OdFont *pFont) : m_pFont(pFont) { } }; /** Map for fonts. */ typedef std::map > FontMap; FontMap m_cache; OdTtfFontsCacheCallback *m_pCallback; /** Alias map. */ typedef std::map AliasMap; AliasMap m_aliases; /** MTRegen mutex. */ OdMutexPtr m_mutex; // Also generates character textures during vectorization bool m_bGenerateTexture = false; // Generated texture size OdUInt32 m_nTextureSize = 64; // Additional character thickness OdUInt32 m_nAdditionalThickness = 0; public: /** Information about vectorized text (can be stored inside Gs cache). */ struct TextInfo { /** Key for font. */ FontKey m_fontKey; /** String of text. */ OdVector > m_textString; /** Initial transformation. */ OdGeMatrix3d m_baseTransform; /** Scaled step direction for each character. */ OdGeVector3d m_stepDir; }; public: /** \details Default constructor for the OdTtfFontsCache class. */ OdTtfFontsCache(); /** \details Constructor for the OdTtfFontsCache class. \param pCallback [in] Callback. */ OdTtfFontsCache(OdTtfFontsCacheCallback *pCallback); /** \details Destructor for the OdTtfFontsCache class. */ ~OdTtfFontsCache() override; ODRX_USING_HEAP_OPERATORS(OdRxObject); /** \details Creates an OdTtfFontsCache instance. \returns Smart pointer to the created instance. */ static OdSmartPtr createObject(); /** \details Creates an OdTtfFontsCache instance. \param pCallback [in] Callback. \returns Smart pointer to the created instance. */ static OdSmartPtr createObject(OdTtfFontsCacheCallback *pCallback); void setCallback(OdTtfFontsCacheCallback *pCallback); OdTtfFontsCacheCallback *callback() const { return m_pCallback; } /** \details Initialize cache and process (returns false if this specific text couldn't be processed) \param position [in] Position of the text. \param u [in] U parameter of the text. \param v [in] V parameter of the text. \param pMsg [in] Message string. \param nLength [in] Message length. \param bRaw [in] Flag that specifies whether escape sequences, such as %%P, will not be converted to special characters. \param pTextStyle [in] Pointer to the TextStyle for the text. \param pDrawContext [in] Pointer to the conveyor context. \param textOutInfo [in/out] Information about vectorized text. \param pSessionId [in] Pointer to the session Id. \returns true if the text is processed successfully, false otherwise. */ bool processText(const OdGePoint3d &position, const OdGeVector3d &u, const OdGeVector3d &v, const OdChar *pMsg, OdInt32 nLength, bool bRaw, const OdGiTextStyle *pTextStyle, OdGiConveyorContext *pDrawContext, TextInfo &textOutInfo, void *pSessionId = NULL); /** \details Plays characters cache. \param textInInfo [in] Information about vectorized text. \param pSessionId [in] Pointer to the session Id. */ void playText(const TextInfo &textInInfo, void *pSessionId = NULL) const; /** \details Plays characters cache. \param fontKey [in] Key for font. \param pText [in] Pointer to an array of characters that compose text. \param nText [in] Number characters in the array. \param baseXform [in] Initial transformation. \param sideVec [in] Scaled step direction for each character. \param pSessionId [in] Pointer to the session Id. */ void playText(const FontKey &fontKey, const CharKey *pText, OdUInt32 nText, const OdGeMatrix3d &baseXform, const OdGeVector3d &sideVec, void *pSessionId = NULL) const; /** \details Clears entire cache. */ void clearCache(); // GsState cache processing /** \details Saves font cache to the specified filer. \param pFiler [out] Pointer to a filer to which to save the cache. \returns true if saved successfully, false otherwise. */ bool saveFontCache(OdGsFiler *pFiler) const; /** \details Loads font cache from the specified filer. \param pFiler [in] Pointer to a filer from which to load the cache. \param pDb [in] Pointer to a database that is used for loading font file(s) for a text style. \returns true if loaded successfully, false otherwise. */ bool loadFontCache(OdGsFiler *pFiler, OdDbBaseDatabase *pDb); bool saveFontCacheObject(OdGsFiler *pFiler, OdUInt64 fontKey); bool loadFontCacheObject(OdGsFiler *pFiler, OdDbBaseDatabase *pDb); void enableTextureGeneration(bool bEnable) { m_bGenerateTexture = bEnable; } void setTextureSize(OdUInt32 nSize) { m_nTextureSize = nSize; } void setAdditionalThickness(OdUInt32 n) { m_nAdditionalThickness = n; } protected: void createFontKey(const OdGiTextStyle *pTextStyle, FontKey &fontKey, OdTextProperties *pTextProperties = NULL) const; virtual OdUInt64 getFontKey(const OdGiTextStyle *pTextStyle) const; FontCache &getFontCache(FontKey &fontKey, OdFont *pFont); OdRxObjectPtr createTextIterator(OdGiConveyorContext *pDrawContext, const OdChar* textString, int length, bool raw, const OdGiTextStyle* pTextStyle) const; void procCharacter(OdFont *pFont, FontKey &fontKey, FontCache &fontCache, CharKey chr, OdTextProperties& textProperties, void *pSessionId); // Stub implementation OdRxObjectPtr tfcNewMetafile(void * /*pSessionId*/) override { return OdRxObjectPtr(); } OdGiConveyorGeometry *tfcBeginMetafile(OdRxObject * /*pMetafile*/, void * /*pSessionId*/) override { return &OdGiEmptyGeometry::kVoid; } virtual void tfcFinalizeMetafileExt(FontKey & /*fontKey*/, CharKey /*chr*/, OdRxObject * /*pMetafile*/, void * /*pSessionId*/) { } void tfcFinalizeMetafile(OdRxObject * /*pMetafile*/, void * /*pSessionId*/) override { } void tfcPlayMetafile(const OdGeMatrix3d & /*xForm*/, const OdRxObject * /*pMetafile*/, void * /*pSessionId*/) const override { } }; /** \details A data type that represents a smart pointer to an object. */ typedef OdSmartPtr OdTtfFontsCachePtr; // Inlines section inline void OdTtfFontsCache::setCallback(OdTtfFontsCacheCallback *pCallback) { m_pCallback = pCallback; } #ifdef OD_TTFFONTSCACHE_SHAREABLENAMESPACE } #endif // OD_TTFFONTSCACHE_SHAREABLENAMESPACE #include "TD_PackPop.h" #endif // ODTTFFONTSCACHE_INCLUDED