使用 PoDoFo 访问 /差异数组
Accessing /Differences array with PoDoFo
这个问题是关于PoDoFo库的一个具体问题。
如何访问字体资源的编码字典中的/Differences
数组条目?
从Tf
运算符读取字体名称后,我可以通过PoDoFo::PdfPage::GetFromResources
获取字体。但是,虽然PdfFont
类有PoDoFo::PdfFont::GetEncoding
,但我看不出您将如何从那里进入/Differences
数组。
来自PDFSpec(我只担心类型1字体(:
编码
(可选(字体字符编码的规范,如果 不同于其内置编码。编码的值应为 预定义编码的名称(MacRomanEncoding, MacExpertEncoding,或WinAnsiEncoding,如附录D(或 编码字典,应指定与字体的差异 内置编码或来自指定的预定义编码(请参阅 9.6.6, "字符编码"(。
这是否意味着从PoDoFo::PdfFont::GetEncoding
返回的PdfEncoding
对象包含差异数组(如果有的话(?
(我刚才在PoDoFo邮件列表中询问过,但在这里发帖看看是否有了解PoDoFo
和pdfs的人可以提供帮助(。
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(
您对最后一种情况感兴趣。因此,如果您手头的编码对象是 PdfDifference Encoding 的实例,则可以使用:
/** 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(
一旦你有一个指向PoDoFo::PdfFont
的指针,你就可以通过调用GetObject
来访问底层对象,因为它从PoDoFo::P dfElement继承了它。从那里调用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);
}
}
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组的地址分配给变量并删除
- 从C++本机插件更新Vector3数组
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 数组索引的值没有增加
- 将对象数组的引用传递给函数
- 为char数组调整zlib-zpipe
- 2D数组来自文本输入,中间有空格
- std::向量与传递值的动态数组
- 在c++中用vector填充一个简单的动态数组
- 使用strcpy将char数组的元素复制到另一个数组
- 使用指针从C++中的数组中获取最大值
- C++使用整数的压缩数组初始化对象
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '