2

这个问题是关于PoDoFo库的具体问题。

如何访问/Differences字体资源的编码字典中的数组条目?

Tf操作员那里读取字体名称后,我可以通过PoDoFo::PdfPage::GetFromResources. 但是,虽然PdfFont课程有PoDoFo::PdfFont::GetEncoding,但我看不到您将如何/Differences从那里到达数组。

来自 PDFSpec(我只担心 Type 1 Fonts):

编码

(可选)字体的字符编码规范(如果不同于其内置编码)。Encoding 的值应为预定义编码的名称(MacRomanEncoding、MacExpertEncoding 或 WinAnsiEncoding,如附件 D 中所述)或应指定与字体内置编码或指定预定义编码的差异的编码字典(参见9.6.6,“字符编码”)。

这是否意味着从PdfEncoding返回的对象PoDoFo::PdfFont::GetEncoding包含差异数组(如果有的话)?

(我刚才在 PoDoFo 邮件列表上问过,但在这里发帖看看有没有PoDoFopdf 知识的人可以提供帮助)。

4

2 回答 2

2

PoDoFo 知道许多不同类型的编码类,参见。编码对象工厂:

if (pObject->IsName ())
{
    const PdfName & rName = pObject->GetName ();
    if (rName == PdfName ("WinAnsiEncoding"))
        return PdfEncodingFactory::GlobalWinAnsiEncodingInstance ();
    else if (rName == PdfName ("MacRomanEncoding"))
        return PdfEncodingFactory::GlobalMacRomanEncodingInstance ();
    else if (rName == PdfName ("StandardEncoding"))      // OC 13.08.2010
        return PdfEncodingFactory::GlobalStandardEncodingInstance ();
    else if (rName == PdfName ("MacExpertEncoding"))     // OC 13.08.2010 TODO solved
        return PdfEncodingFactory::GlobalMacExpertEncodingInstance ();
    else if (rName == PdfName ("SymbolEncoding"))        // OC 13.08.2010
        return PdfEncodingFactory::GlobalSymbolEncodingInstance ();
    else if (rName == PdfName ("ZapfDingbatsEncoding"))  // OC 13.08.2010
        return PdfEncodingFactory::GlobalZapfDingbatsEncodingInstance ();
    else if (rName == PdfName ("Identity-H"))
        return new PdfIdentityEncoding ();
}
else if (pObject->HasStream ())     // Code for /ToUnicode object 
{
    return new PdfCMapEncoding(pObject);
}
else if (pObject->IsDictionary ())
{
    return new PdfDifferenceEncoding (pObject);
}

(PoDoFo/src/doc/PdfEncodingObjectFactory.cpp)

您对最后一个案例感兴趣。因此,如果您手头的编码对象是 PdfDifferenceEncoding 的一个实例,您可以使用:

/** PdfDifferenceEncoding is an encoding, which is based
 *  on either the fonts encoding or a predefined encoding
 *  and defines differences to this base encoding.
 */
class PODOFO_DOC_API PdfDifferenceEncoding : public PdfEncoding, private PdfElement {
 public:
[...]
    /** 
     * Get read-only access to the object containing the actual
     * differences.
     *
     * \returns the container with the actual differences
     */
    inline const PdfEncodingDifference & GetDifferences() const;
[...]
};

(PoDoFo/src/doc/PdfDifferenceEncoding.h)

PdfDifferenceEncoding在同一个头类中声明并提供一些有趣的方法:

/** A helper class for PdfDifferenceEncoding that
 *  can be used to create a differences array.
 */
class PODOFO_DOC_API PdfEncodingDifference {
    struct TDifference {
        int         nCode;
        PdfName     name;
        pdf_utf16be unicodeValue;
    };

    typedef std::vector<TDifference>                 TVecDifferences;
    typedef std::vector<TDifference>::iterator       TIVecDifferences;
    typedef std::vector<TDifference>::const_iterator TCIVecDifferences;

 public: 
    /** Create a PdfEncodingDifference object.
     */
    PdfEncodingDifference();

    /** Copy a PdfEncodingDifference object.
     */
    PdfEncodingDifference( const PdfEncodingDifference & rhs );

    /** Copy a PdfEncodingDifference object.
     */
    const PdfEncodingDifference & operator=( const PdfEncodingDifference & rhs );

    /** Add a difference to the object.
     * 
     *  \param nCode unicode code point of the difference (0 to 255 are legal values)
     *
     *  \see AddDifference if you know the name of the code point
     *       use the overload below which is faster
     */
    void AddDifference( int nCode );

    /** Add a difference to the object.
     * 
     *  \param nCode unicode code point of the difference (0 to 255 are legal values)
     *  \param rName name of the different code point or .notdef if none
     */
    void AddDifference( int nCode, const PdfName & rName );

    /** Tests if the specified code is part of the 
     *  differences.
     *
     *  \param nCode test if the given code is part of the differences
     *  \param rName write the associated name into this object if the 
     *               code is part of the difference
     *  \param rValue write the associated unicode value of the name to this value 
     *
     *  \returns true if the code is part of the difference
     */
    bool Contains( int nCode, PdfName & rName, pdf_utf16be & rValue ) const;

    /** Convert the PdfEncodingDifference to an array
     *
     *  \param rArray write to this array
     */
    void ToArray( PdfArray & rArray );

    /** Get the number of differences in this object.
     *  If the user added .notdef as a difference it is 
     *  counted, even it is no real difference in the final encoding.
     *  
     *  \returns the number of differences in this object
     */
    inline size_t GetCount() const;

 private:
    struct DifferenceComparatorPredicate {
        public:
          inline bool operator()( const TDifference & rDif1, 
                                  const TDifference & rDif2 ) const { 
              return rDif1.nCode < rDif2.nCode;
          }
    };

    TVecDifferences m_vecDifferences;
};

(PoDoFo/src/doc/PdfDifferenceEncoding.h)

于 2013-06-14T09:34:42.787 回答
1

一旦你有了一个指向 a 的指针PoDoFo::PdfFont,你就可以通过调用来访问底层对象,GetObject因为它继承自PoDoFo::PdfElement。从那里调用GetIndirectKey("Encoding")以获取指向包含差异数组的编码字典的指针并将其传递给PoDoFo::PdfDifferenceEncoding构造函数。

PoDoFo::PdfObject* fntobj = fnt->GetObject();
if (fntobj)
{
    PoDoFo::PdfObject* fntdic = fntobj->GetIndirectKey("Encoding");
    if (fntdic)
    {
        PoDoFo::PdfDifferenceEncoding diff(fntdic);
        PoDoFo::PdfArray diffarray;
        PoDoFo::PdfEncodingDifference d(diff.GetDifferences());
        d.ToArray(diffarray);
    }
}
于 2013-06-15T21:47:05.007 回答