PDF-Make
view release on metacpan or search on metacpan
src/pdfmake_encoding.c view on Meta::CPAN
if (font->type == PDFMAKE_FONT_TRUETYPE ||
font->type == PDFMAKE_FONT_CID_TRUETYPE) {
if (font->ttf) {
units_per_em = font->ttf->units_per_em;
advance_width = pdfmake_ttf_glyph_advance(font->ttf, glyph_id);
}
} else if (font->type == PDFMAKE_FONT_TYPE1) {
/* Standard 14: widths are already in 1/1000 em */
advance_width = pdfmake_std14_width(font->std14_id, glyph_id);
units_per_em = 1000;
}
return (advance_width * font_size) / units_per_em;
}
double pdfmake_text_string_width(
pdfmake_text_state_t *ts,
const uint8_t *text,
size_t len)
{
double width;
const uint8_t *p;
const uint8_t *end;
uint32_t unicode;
uint16_t glyph_id;
double glyph_width;
if (!ts || !text || !ts->font) return 0.0;
width = 0.0;
p = text;
end = text + len;
while (p < end) {
unicode = utf8_decode(&p, end);
if (unicode == 0xFFFD) continue;
glyph_id = pdfmake_text_unicode_to_glyph(ts->font, unicode);
glyph_width = pdfmake_text_glyph_advance(ts->font, glyph_id,
ts->font_size);
width += glyph_width;
width += ts->char_spacing;
/* Word spacing for ASCII space */
if (unicode == 0x0020) {
width += ts->word_spacing;
}
}
/* Apply horizontal scaling */
width *= ts->horiz_scale;
return width;
}
/*============================================================================
* Font encoding API (Phase 2)
*
* Resolves a font's /Encoding to a byte->Unicode map, applying /Differences
* overlays via the Adobe Glyph List.
*==========================================================================*/
#include "pdfmake_font_encoding.h"
#include "pdfmake_glyphlist.h"
/* Fill a 256-entry map from a base table (0xFFFF = undefined in the
* existing tables; translate to 0 for the new API). */
static void fill_from_table(pdfmake_font_encoding_t *enc,
const uint16_t *src)
{
int i;
uint16_t v;
for (i = 0; i < 256; i++) {
v = src[i];
enc->map[i] = (v == 0xFFFF) ? 0 : v;
}
}
void pdfmake_font_encoding_init_standard(pdfmake_font_encoding_t *enc) {
fill_from_table(enc, pdfmake_encoding_standard);
}
void pdfmake_font_encoding_init_winansi(pdfmake_font_encoding_t *enc) {
fill_from_table(enc, pdfmake_encoding_winansi);
}
void pdfmake_font_encoding_init_macroman(pdfmake_font_encoding_t *enc) {
fill_from_table(enc, pdfmake_encoding_macroman);
}
void pdfmake_font_encoding_init_macexpert(pdfmake_font_encoding_t *enc) {
/* MacExpertEncoding has no full table here â approximate with Standard.
* This is rare in modern PDFs. */
fill_from_table(enc, pdfmake_encoding_standard);
}
void pdfmake_font_encoding_init_symbol(pdfmake_font_encoding_t *enc) {
fill_from_table(enc, pdfmake_encoding_symbol);
}
void pdfmake_font_encoding_init_zapfdingbats(pdfmake_font_encoding_t *enc) {
fill_from_table(enc, pdfmake_encoding_zapfdingbats);
}
int pdfmake_font_encoding_init_by_name(pdfmake_font_encoding_t *enc,
const char *name)
{
if (!enc) return 0;
if (!name) {
pdfmake_font_encoding_init_winansi(enc);
return 0;
}
if (strcmp(name, "StandardEncoding") == 0) {
pdfmake_font_encoding_init_standard(enc); return 1;
}
if (strcmp(name, "WinAnsiEncoding") == 0) {
pdfmake_font_encoding_init_winansi(enc); return 1;
}
if (strcmp(name, "MacRomanEncoding") == 0) {
pdfmake_font_encoding_init_macroman(enc); return 1;
}
if (strcmp(name, "MacExpertEncoding") == 0) {
pdfmake_font_encoding_init_macexpert(enc); return 1;
}
if (strcmp(name, "SymbolEncoding") == 0) {
( run in 0.815 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )