/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // // PdfTTFontData.h // /////////////////////////////////////////////////////////////////////////////// #ifndef _PDF_TTFONTDATA_INCLUDED_ #define _PDF_TTFONTDATA_INCLUDED_ #include "Int32Array.h" #include "UInt16Array.h" #include "Int16Array.h" #include "Gi/GiTextStyle.h" class OdFont; /** \details */ namespace TD_PDF { struct pdf_tt_cmap; struct pdf_tt_cmap_sub; struct pdf_tt_hmtx_elem; struct pdf_tt_hhea; struct pdf_tt_head; struct pdf_tt_os2; struct pdf_tt_post; struct pdf_tt_pclt; struct pdf_tt_name; struct pdf_tt_nameRecord; /** \details This class implements the font data for PDF export. */ class PDFTTFontData { public: enum TTFCharSet { kANSI_CHARSET = 0x00, kDEFAULT_CHARSET = 0x01, kSYMBOL_CHARSET = 0x02, kMAC_CHARSET = 0x4D, kSHIFTJIS_CHARSET = 0x80, kHANGEUL_CHARSET = 0x81, kGB2312_CHARSET = 0x86, kCHINESEBIG5_CHARSET = 0x88, kGREEK_CHARSET = 0xA1, kTURKISH_CHARSET = 0xA2, kVIETNAMESE_CHARSET = 0xA3, kHEBREW_CHARSET = 0xB1, kARABIC_CHARSET = 0xB2, kBALTIC_CHARSET = 0xBA, kRUSSIAN_CHARSET = 0xCC, kTHAI_CHARSET = 0xDE, kEASTEUROPE_CHARSET = 0xEE, kOEM_CHARSET = 0xFF }; //enums below (TTFPlatformIDs, TTFEncodingIDMicrosoft and TTFEncodingIDUnicode) see https://developer.apple.com/fonts/TrueType-Reference-Manual enum TTFPlatformIDs { kPlatformUnicode = 0, //Indicates Unicode version. kPlatformMacintosh = 1, //Script Manager code. (declared as deprecated in https://learn.microsoft.com/en-us/typography/opentype/spec/cmap but not in https://developer.apple.com/fonts/TrueType-Reference-Manual) kPlatformISO = 2, //Deprecated, do not use. kPlatformMicrosoft = 3 //Microsoft encoding. }; enum TTFEncodingIDMicrosoft { kEncSymbol = 0, //Symbol kEncUnicodeUCS2 = 1, //Unicode BMP-only (UCS-2). Fonts that support only Unicode BMP characters (U+0000 to U+FFFF) on the Windows platform must use encoding 1 with a format 4 subtable kEncShiftJIS = 2, //Shift-JIS kEncPRC = 3, //PRC kEncBig5 = 4, //BigFive kEncWansung = 5, //Wansung (This id is absent in https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html, but here https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html //we can see: "For information on Microsoft platform-specific encoding identifiers, consult the OpenType specification(https://learn.microsoft.com/en-us/typography/opentype/spec/)" so let it be.) kEncJohab = 6, //Johab /*codes 7-9 are reserved*/ kEncUnicodeUCS4 = 10 //Unicode full repertoire. Fonts that support Unicode supplementary-plane characters (U+10000 to U+10FFFF) on the Windows platform must use encoding 10 with a format 12 subtable. }; enum TTFEncodingIDUnicode { kEncUnicode10 = 0, //Unicode 1.0 semantics — deprecated kEncUnicode11 = 1, //Unicode 1.1 semantics — deprecated kEncISOIEC10646 = 2, //ISO/IEC 10646 semantics — deprecated kEncUnicode20BMP = 3, //Unicode 2.0 and onwards semantics, Unicode BMP only (the same as TTFEncodingIDMicrosoft::kUnicodeUCS2). Should be used in conjunction with 'cmap' subtable formats 4 or 6 kEncUnicode20UCS4 = 4, //Unicode 2.0 and onwards semantics, Unicode full repertoire (the same as TTFEncodingIDMicrosoft::kUnicodeUCS4). Should be used in conjunction with subtable formats 10 or 12 kEncUnicodeVS = 5, //Unicode Variation Sequences — for use with subtable format 14 kEncUnicode20UCS4_13 = 6 //Unicode full repertoire — for use with subtable format 13 }; enum TTFFontStretch { kUltraCondensed = 1, kExtraCondensed = 2, kCondensed = 3, kSemiCondensed = 4, kNormal = 5, kSemiExpanded = 6, kExpanded = 7, kExtraExpanded = 8, kUltraExpanded = 9 }; enum TTFCopyright { kInstallable = 0 , // Fonts with this setting indicate that they may be embedded and permanently // installed on the remote system by an application. The user of the remote // system acquires the identical rights, obligations and licenses for that font // as the original purchaser of the font, and is subject to the same end-user // license agreement, copyright, design patent, and/or trademark as was the original purchaser. kRestrictedLicense = 2, // Fonts that have this bit set must not be modified, embedded or exchanged // in any manner without first obtaining permission of the legal owner // Note: For Restricted License embedding to take effect, it must be the only level of embedding selected. kPreviewPrint = 4, // Fonts with this bit set indicate that they may be embedded within documents // but must only be installed temporarily on the remote system. Any document // which includes a Preview & Print embedded font must be opened "read-only;" // the application must not allow the user to edit the document; it can only // be viewed and/or printed. kEditable = 8, // Fonts with this bit set indicate that they may be embedded in documents, // but must only be installed temporarily on the remote system. In contrast // to Preview & Print fonts, documents containing Editable fonts may be opened // "read-write;" editing is permitted, and changes may be saved. kNoSubsetting = 0x0100, // When this bit is set, the font may not be subsetted prior to // embedding.Other embedding restrictions specified in bits 0 - 3 and 9 also apply. kBitmapEmbeddingOnly = 0x0200, // When this bit is set, only bitmaps contained in the font may be embedded. // No outline data may be embedded. If there are no bitmaps available in the font, then the font // is considered unembeddable and the embedding services will fail. Other embedding restrictions // specified in bits 0 - 3 and 8 also apply. kUndefined = 0xFF // TTF hasn't OS/2 table }; enum TFFWidthClass { kwThin = 100, kwExtraLight = 200, kwLight = 300, kwNormal = 400, kwMedium = 500, kwSemiDold = 600, kwBold = 700, kwExtraBold = 800, kwBlack = 900 }; protected: TTFEncodingIDMicrosoft getEncodingByCharSet() const; bool getFontNameFromNameTable(OdAnsiString &fontName, OdUInt16 recType) const; bool fontNameFromRecord(OdAnsiString& fontName, pdf_tt_name& name, pdf_tt_nameRecord* pRecord) const; bool parseCmapSubTable(const pdf_tt_cmap_sub* cmapSub, OdUInt16 subtableIndex) const; OdResult getCmapSubTable() const; bool CID2GIDMap4(OdUInt16 maxChar, OdUInt16Array& map, bool bSwap) const; bool CID2GIDMap12(OdUInt16 maxChar, OdUInt16Array& map, bool bSwap) const; bool getPOST(pdf_tt_post &post) const; bool getHEAD(pdf_tt_head &head) const; bool getHHEA(pdf_tt_hhea &hhea) const; bool getHMTX(pdf_tt_hmtx_elem* &pHMTX, OdUInt16 numberOfHMetrics) const; bool getCMAP(pdf_tt_cmap &cmap, pdf_tt_cmap_sub* &cmapSub) const; bool getOS2(pdf_tt_os2 &os2) const; bool getPCLT(pdf_tt_pclt &pclt) const; public: PDFTTFontData(); ~PDFTTFontData(); void init(const OdFont* pFont, const OdGiTextStyle* pTextStyle); OdResult set(const OdFont *pFont, const OdGiTextStyle* pTextStyle); const OdInt32 *BBox() const { return m_dBBox; } double Descent() const { return m_dDescent; } double Ascent() const { return m_dDescent; } double Ascender() const { return m_dAscent; } bool FontDescriptorFlags(OdInt32 &nFlags) const; double StemV() const { return m_dStemV; } bool getFontName(OdAnsiString &fontName) const; TTFCopyright getCopyright() const; bool fontCanBeEmbedded(bool& bAllowedEdit) const; OdAnsiString getFontStretch() const; bool getWidthClass(TFFWidthClass &widthClass) const; bool getItalicAngle(double &dItalicAngle) const; bool getCapHeight(double &dCapHeight) const; bool getXHeight(double &dXHeight) const; bool isBold() const; bool isItalic() const; bool isUnicodeTable() const; bool getWidthsByCharSet(OdInt32Array& nWidths, OdUInt8 nStartChar = 0, OdUInt8 nEndChar = 255) const; bool getCID2GIDMap(OdUInt16 maxChar, OdUInt16Array& map, bool bSwap) const; bool getCID2W(OdUInt16 maxChar, OdInt16Array& nWidths) const; private: const OdFont *m_pFont; const OdGiTextStyle* m_pTextStyle; OdInt32 m_dBBox[4] = {}; double m_dDescent; double m_dAscent; OdInt32 m_nFontDescriptorFlags; double m_dStemV; double m_dUnitsPerEM; mutable TTFCharSet m_nCharSet; mutable OdInt8 *m_pCMap; mutable OdUInt16 m_TableType; mutable bool m_bNonUnicodeCmapTable; static OdUInt32 nHEAD;// = *((OdUInt32*)&"head"); static OdUInt32 nGLYF;// = *((OdUInt32*)&"glyf"); static OdUInt32 nHHEA;// = *((OdUInt32*)&"hhea"); static OdUInt32 nHMTX;// = *((OdUInt32*)&"hmtx"); static OdUInt32 nCMAP;// = *((OdUInt32*)&"cmap"); static OdUInt32 nNAME;// = *((OdUInt32*)&"name"); static OdUInt32 nOS2;// = *((OdUInt32*)&"OS/2"); static OdUInt32 nPOST;// = *((OdUInt32*)&"post"); static OdUInt32 nPCLT;// = *((OdUInt32*)&"PCLT"); }; } #endif // _PDF_TTFONTDATA_INCLUDED_