使用libharu库可以获取文字坐标的代码例子
时间: 2023-03-14 09:28:11 浏览: 125
您可以参考以下libharu库的例子:
```c++
#include <hpdf.h>int main (void)
{
HPDF_Doc pdf;
HPDF_Font font;
HPDF_Page page;
HPDF_REAL tw;
HPDF_REAL x;
HPDF_REAL y;
HPDF_Point points[4]; pdf = HPDF_New (NULL, NULL);
if (!pdf) {
printf ("error: cannot create PdfDoc object\n");
return 1;
} /* 添加一页 */
page = HPDF_AddPage (pdf); font = HPDF_GetFont (pdf, "Helvetica", NULL); /* 设置文本位置 */
HPDF_Page_SetFontAndSize (page, font, 20);
tw = HPDF_Page_TextWidth (page, "ABCabc123");
x = (HPDF_Page_GetWidth (page) - tw) / 2;
y = HPDF_Page_GetHeight (page) / 2;
HPDF_Page_BeginText (page);
HPDF_Page_TextOut (page, x, y, "ABCabc123");
HPDF_Page_EndText (page); /* 获取文本坐标 */
points[0].x = x;
points[0].y = y;
points[1].x = x + tw;
points[1].y = y;
HPDF_Page_GetTextPos (page, points + 2, points + 3); // 其它代码 HPDF_Free (pdf); return 0;
}
```
阅读全文