40#include "desktop/save_pdf/font_haru.h"
41#include "desktop/font.h"
45static bool haru_nsfont_init(HPDF_Doc *pdf, HPDF_Page *page,
46 const char *
string,
char **string_nt,
int length);
49 const char *
string,
size_t length,
53 const char *
string,
size_t length,
54 int x,
size_t *char_offset,
int *actual_x);
57 const char *
string,
size_t length,
58 int x,
size_t *char_offset,
int *actual_x);
64 haru_nsfont_position_in_string,
74static void error_handler(HPDF_STATUS error_no, HPDF_STATUS detail_no,
78 "ERROR: in font_haru \n\terror_no=%x\n\tdetail_no=%d\n",
80 (HPDF_UINT)detail_no);
86static bool haru_nsfont_init(HPDF_Doc *pdf, HPDF_Page *page,
87 const char *
string,
char **string_nt,
int length)
90 *pdf = HPDF_New(error_handler, NULL);
95 *page = HPDF_AddPage(*pdf);
102 *string_nt = malloc((length + 1) *
sizeof(
char));
103 if (*string_nt == NULL) {
108 memcpy(*string_nt,
string, length);
109 (*string_nt)[length] =
'\0';
123 const char *
string,
size_t length,
129 HPDF_REAL width_real;
136 if (!haru_nsfont_init(&pdf, &page,
string, &string_nt, length))
145 width_real = HPDF_Page_TextWidth(page, string_nt);
148#ifdef FONT_HARU_DEBUG
150 "Measuring string: %s ; Calculated width: %f %i", string_nt,
173 const char *
string,
size_t length,
174 int x,
size_t *char_offset,
int *actual_x)
180 HPDF_REAL real_width;
182 if (!haru_nsfont_init(&pdf, &page,
string, &string_nt, length))
185 if (HPDF_Page_SetWidth(page, x) != HPDF_OK
193 offset = HPDF_Page_MeasureText(page, string_nt, x,
194 HPDF_FALSE, &real_width);
198 *char_offset = offset;
200 assert(fabs(real_width - x) < FLT_EPSILON);
202 *char_offset = offset - 1;
206 *actual_x = real_width;
208#ifdef FONT_HARU_DEBUG
210 "Position in string: %s at x: %i; Calculated position: %i",
234 const char *
string,
size_t length,
235 int x,
size_t *char_offset,
int *actual_x)
240 HPDF_REAL real_width;
244 if (!haru_nsfont_init(&pdf, &page,
string, &string_nt, length))
247 if (HPDF_Page_SetWidth(page, x) != HPDF_OK
254 offset = HPDF_Page_MeasureText(page, string_nt, x,
255 HPDF_TRUE, &real_width);
257#ifdef FONT_HARU_DEBUG
259 "Splitting string: %s for width: %i ; Calculated position: %i Calculated real_width: %f",
265 *char_offset = offset - 1;
268 *actual_x = real_width;
292 HPDF_Doc doc, HPDF_Page page,
293 HPDF_Font *font, HPDF_REAL *font_size)
307 strcpy(font_name,
"Times");
311 strcpy(font_name,
"Courier");
314 strcpy(font_name,
"Helvetica");
319 strcpy(font_name,
"Times");
324 if (fstyle->
weight == 700) {
325 strcat(font_name,
"-Bold");
331 strcat(font_name,
"-");
333 strcat(font_name,
"Italic");
335 strcat(font_name,
"Oblique");
340 if (roman && !styled && !bold)
341 strcat(font_name,
"-Roman");
343#ifdef FONT_HARU_DEBUG
344 NSLOG(netsurf, INFO,
"Setting font: %s", font_name);
350 size *= pdf_text_scale;
357 if (size > HPDF_MAX_FONTSIZE)
358 size = HPDF_MAX_FONTSIZE;
363 pdf_font = HPDF_GetFont(doc, font_name,
"StandardEncoding");
364 if (pdf_font == NULL)
369 if (font == NULL || font_size == NULL)
370 HPDF_Page_SetFontAndSize(page, pdf_font, size);
bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, HPDF_Doc doc, HPDF_Page page, HPDF_Font *font, HPDF_REAL *font_size)
const struct font_functions haru_nsfont
void haru_nsfont_set_scale(float s)
#define NSLOG(catname, level, logmsg, args...)
@ PLOT_FONT_FAMILY_CURSIVE
@ PLOT_FONT_FAMILY_SANS_SERIF
@ PLOT_FONT_FAMILY_FANTASY
@ PLOT_FONT_FAMILY_MONOSPACE
#define PLOT_STYLE_SCALE
Scaling factor for plot styles.
Interface to utility string handling.
plot_font_generic_family_t family
Generic family to plot with.
plot_font_flags_t flags
Font flags.
plot_style_fixed size
Font size, in pt.
int weight
Font weight: value in range [100,900] as per CSS.
Option reading and saving interface.
#define DEFAULT_EXPORT_SCALE