JAGPDF在c++中的对齐测试
JAGPDF in C++ aligning test
有人在c++上使用jagPDF吗?
我正试着从http://www.jagpdf.org/doc/index.htm提供的手册中学习如何使用它。不幸的是,他们所有的例子都是用Python编写的。有时候适应c++并不是什么大问题,但有时候却令人困惑。
例如,我试图学习如何对齐文本,这在教程中是在文本对齐。找到padding后,将padding放入文本行的函数是:
canvas.text(txt, [padding / 2.0], [0])
查找该函数的引用,翻译表为:
[py] text(txt_u, offsets, positions)
[c++] void text(Char const* txt_u, Double const* offsets, UInt offsets_length, Int const* positions, UInt positions_length);
参数:
- txt_u:零终止字符串。
- offsets:以字形空间表示的字形偏移量(即以文本空间单位的千分之一表示)。
- offsets_length:偏移量的数目。
- position:将txt_u中的字形偏移与字形索引相关联。
- positions_length:位置数。
我已经尝试了一些东西,但我还没有弄清楚c++在Python上需要的两个额外输入参数。如果有人使用过jagPDF并知道如何在c++中实现它,我将不胜感激。
这是我第一次接触JagPDF。有一节文本对齐,但代码是用Python编写的。
在c++中应该是这样:
// line width
pdf::Double line_width = 597.6;
// text to show
pdf::Char *txt = "Everything should be made as simple as possible, but no simpler.";
// calculate text width
pdf::Double text_width = font.advance(txt);
// calculate gap - difference in line_width and text_width
pdf::Double gap = line_width - text_width;
// calculate the text padding
pdf::Double padding = -1000.0 / font.size() * gap;
// create array with paddings - I set all padings, but is used only 1
pdf::Double const pp[] = { padding, padding / 2.0 }; // index 0 for right alignment, 1 for center
// not sure what are positions, but need for function `text()` - set as Doc to zero (0)
pdf::Int const dd[] = { 0};
// get canvas where the text is written
pdf::Canvas canvas = doc.page().canvas();
// start text block
canvas.text_start(0, 480);
// set font
canvas.text_font(font);
// right alignment text
canvas.text(txt, pp, 1, dd, 1);
canvas.text_translate_line(0, font.height());
// center alignment text
canvas.text(txt, &pp[1], 1, dd, 1);
canvas.text_translate_line(0, font.height());
// finish text block
canvas.text_end();
希望有所帮助
相关文章:
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- 如何创建一个QTableWidgetItem,用长文本右对齐,左边有省略号
- 我可以检测和更改 gcc/g++ 中结构的当前数据对齐设置吗?
- 64位机器上的C++内存对齐
- 为什么我可以将变量存储在不是其最小对齐方式的倍数的地址?
- 使 std::vector 分配对齐内存的现代方法
- C++ cout 将双精度对齐到精度 2 并正确对齐
- 在 64 位边界上对齐C++结构数组?
- 使用 g++7 构建的代码在访问未对齐的内存时崩溃
- 在 capnp FlatArrayMessageReader 的对齐内存缓冲区中接收 zmq 消息
- 是否值得对齐变量?
- 初始化派生结构的基部分/意外打包派生结构字段以对齐基结构的间隙
- 对齐和对齐的实际用例C++关键字
- 如何减少代码的运行时间以对齐文本?
- 指向包含对齐 C 结构C++类的 C 指针的对齐问题
- Linux C++ 中的页面对齐内存分配
- C++ 类层次结构中的"对齐"是什么意思?
- 测试与浮点对齐
- 如何使用此宏测试是否对齐内存
- JAGPDF在c++中的对齐测试