Save work on string measure support (Issue #17)

This commit is contained in:
Michael R Sweet
2023-12-04 18:54:33 -05:00
parent 86281750e5
commit 4919783da5
4 changed files with 52 additions and 8 deletions

View File

@@ -7,10 +7,6 @@
// information.
//
//
// Include necessary headers...
//
#include "pdfio-private.h"
#include "pdfio-content.h"
#include "ttf.h"
@@ -1064,6 +1060,27 @@ pdfioContentTextEnd(pdfio_stream_t *st) // I - Stream
}
//
// 'pdfioContextTextMeasure()' - Measure a text string and return its width.
//
double // O - Width
pdfioContextTextMeasure(
pdfio_obj_t *font, // I - Font object created by @link pdfioFileCreateFontObjFromFile@
const char *s, // I - UTF-8 string
double size) // I - Font size/height
{
ttf_t *ttf = (ttf_t *)_pdfioObjGetExtension(font);
// TrueType font data
ttf_rect_t extents; // Text extents
ttfGetExtents(ttf, size, s, &extents);
return (extents.right - extents.left);
}
//
// 'pdfioContentTextMoveLine()' - Move to the next line and offset.
//