HPDF_STATUS HPDF_String_SetValue (HPDF_String obj, const char *value) { HPDF_UINT len; HPDF_STATUS ret = HPDF_OK; HPDF_PTRACE((" HPDF_String_SetValue\n")); if (obj->value) { HPDF_FreeMem (obj->mmgr, obj->value); obj->len = 0; } len = HPDF_StrLen(value, HPDF_LIMIT_MAX_STRING_LEN + 1); if (len > HPDF_LIMIT_MAX_STRING_LEN) return HPDF_SetError (obj->error, HPDF_STRING_OUT_OF_RANGE, 0); obj->value = HPDF_GetMem (obj->mmgr, len + 1); if (!obj->value) return HPDF_Error_GetCode (obj->error); HPDF_StrCpy ((char *)obj->value, value, (char *)obj->value + len); obj->len = len; return ret; }
HPDF_STATUS HPDF_Obj_Write (void *obj, HPDF_Stream stream, HPDF_Encrypt e) { HPDF_Obj_Header *header = (HPDF_Obj_Header *)obj; HPDF_PTRACE((" HPDF_Obj_Write\n")); if (header->obj_id & HPDF_OTYPE_HIDDEN) { HPDF_PTRACE(("#HPDF_Obj_Write obj=0x%08X skipped\n", (HPDF_UINT)obj)); return HPDF_OK; } if (header->obj_class == HPDF_OCLASS_PROXY) { char buf[HPDF_SHORT_BUF_SIZ]; char *pbuf = buf; char *eptr = buf + HPDF_SHORT_BUF_SIZ - 1; HPDF_Proxy p = obj; header = (HPDF_Obj_Header*)p->obj; pbuf = HPDF_IToA (pbuf, header->obj_id & 0x00FFFFFF, eptr); *pbuf++ = ' '; pbuf = HPDF_IToA (pbuf, header->gen_no, eptr); HPDF_StrCpy(pbuf, " R", eptr); return HPDF_Stream_WriteStr(stream, buf); } return HPDF_Obj_WriteValue(obj, stream, e); }
static HPDF_STATUS UTF8_Init (HPDF_Encoder encoder) { HPDF_CMapEncoderAttr attr; HPDF_STATUS ret; if ((ret = HPDF_CMapEncoder_InitAttr (encoder)) != HPDF_OK) return ret; attr = (HPDF_CMapEncoderAttr)encoder->attr; if (HPDF_CMapEncoder_AddCMap (encoder, CMAP_ARRAY_UTF8) != HPDF_OK) return encoder->error->error_no; if ((ret = UTF8_AddCodeSpaceRange (encoder)) != HPDF_OK) return ret; if (HPDF_CMapEncoder_AddNotDefRange (encoder, UTF8_NOTDEF_RANGE) != HPDF_OK) return encoder->error->error_no; HPDF_CMapEncoder_SetUnicodeArray (encoder, UTF8_UNICODE_ARRAY); attr->is_lead_byte_fn = UTF8_IsLeadByte; attr->is_trial_byte_fn = UTF8_IsTrialByte; HPDF_StrCpy (attr->registry, "Adobe", attr->registry + HPDF_LIMIT_MAX_NAME_LEN); HPDF_StrCpy (attr->ordering, "UTF-8", attr->ordering + HPDF_LIMIT_MAX_NAME_LEN); attr->suppliment = 0; attr->writing_mode = HPDF_WMODE_HORIZONTAL; /* Not sure about this attr->uid_offset = 0; attr->xuid[0] = 0; attr->xuid[1] = 0; attr->xuid[2] = 0; */ encoder->type = HPDF_ENCODER_TYPE_DOUBLE_BYTE; return HPDF_OK; }
static HPDF_STATUS OnWrite (HPDF_Dict obj, HPDF_Stream stream) { HPDF_FontAttr attr = (HPDF_FontAttr)obj->attr; HPDF_BasicEncoderAttr encoder_attr = (HPDF_BasicEncoderAttr)attr->encoder->attr; HPDF_UINT i; HPDF_STATUS ret; char buf[128]; char *pbuf = buf; char *eptr = buf + 127; HPDF_PTRACE ((" HPDF_Font_OnWrite\n")); /* Widths entry */ if ((ret = HPDF_Stream_WriteEscapeName (stream, "Widths")) != HPDF_OK) return ret; if ((ret = HPDF_Stream_WriteStr (stream, " [\012")) != HPDF_OK) return ret; for (i = encoder_attr->first_char; i <= encoder_attr->last_char; i++) { pbuf = HPDF_IToA (pbuf, attr->widths[i], eptr); *pbuf++ = ' '; if ((i + 1) % 16 == 0) { HPDF_StrCpy(pbuf, "\012", eptr); if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK) return ret; pbuf = buf; } } HPDF_StrCpy (pbuf, "]\012", eptr); if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK) return ret; return attr->encoder->write_fn (attr->encoder, stream); }
const char* HPDF_Page_GetLocalFontName (HPDF_Page page, HPDF_Font font) { HPDF_PageAttr attr = (HPDF_PageAttr )page->attr; const char *key; HPDF_PTRACE((" HPDF_Page_GetLocalFontName\n")); /* whether check font-resource exists. when it does not exists, * create font-resource * 2006.07.21 Fixed a problem which may cause a memory leak. */ if (!attr->fonts) { HPDF_Dict resources; HPDF_Dict fonts; resources = HPDF_Page_GetInheritableItem (page, "Resources", HPDF_OCLASS_DICT); if (!resources) return NULL; fonts = HPDF_Dict_New (page->mmgr); if (!fonts) return NULL; if (HPDF_Dict_Add (resources, "Font", fonts) != HPDF_OK) return NULL; attr->fonts = fonts; } /* search font-object from font-resource */ key = HPDF_Dict_GetKeyByObj (attr->fonts, font); if (!key) { /* if the font is not resisterd in font-resource, register font to * font-resource. */ char fontName[HPDF_LIMIT_MAX_NAME_LEN + 1]; char *ptr; char *end_ptr = fontName + HPDF_LIMIT_MAX_NAME_LEN; ptr = (char *)HPDF_StrCpy (fontName, "F", end_ptr); HPDF_IToA (ptr, attr->fonts->list->count + 1, end_ptr); if (HPDF_Dict_Add (attr->fonts, fontName, font) != HPDF_OK) return NULL; key = HPDF_Dict_GetKeyByObj (attr->fonts, font); } return key; }
HPDF_FontDef HPDF_CIDFontDef_New (HPDF_MMgr mmgr, char *name, HPDF_FontDef_InitFunc init_fn) { HPDF_FontDef fontdef; HPDF_CIDFontDefAttr fontdef_attr; HPDF_PTRACE (" HPDF_CIDFontDef_New\n"); if (!mmgr) return NULL; fontdef = HPDF_GetMem (mmgr, sizeof(HPDF_FontDef_Rec)); if (!fontdef) return NULL; HPDF_MemSet (fontdef, 0, sizeof(HPDF_FontDef_Rec)); fontdef->sig_bytes = HPDF_FONTDEF_SIG_BYTES; HPDF_StrCpy (fontdef->base_font, name, fontdef->base_font + HPDF_LIMIT_MAX_NAME_LEN); fontdef->mmgr = mmgr; fontdef->error = mmgr->error; fontdef->type = HPDF_FONTDEF_TYPE_UNINITIALIZED; fontdef->free_fn = HPDF_CIDFontDef_FreeFunc; fontdef->init_fn = init_fn; fontdef->valid = HPDF_FALSE; fontdef_attr = HPDF_GetMem (mmgr, sizeof(HPDF_CIDFontDefAttr_Rec)); if (!fontdef_attr) { HPDF_FreeMem (fontdef->mmgr, fontdef); return NULL; } fontdef->attr = fontdef_attr; HPDF_MemSet ((HPDF_BYTE *)fontdef_attr, 0, sizeof(HPDF_CIDFontDefAttr_Rec)); fontdef_attr->widths = HPDF_List_New (mmgr, HPDF_DEF_CHAR_WIDTHS_NUM); if (!fontdef_attr->widths) { HPDF_FreeMem (fontdef->mmgr, fontdef); HPDF_FreeMem (fontdef->mmgr, fontdef_attr); return NULL; } fontdef->missing_width = 500; fontdef_attr->DW = 1000; fontdef_attr->DW2[0] = 880; fontdef_attr->DW2[1] = -1000; return fontdef; }
const char* HPDF_Page_GetExtGStateName (HPDF_Page page, HPDF_ExtGState state) { HPDF_PageAttr attr = (HPDF_PageAttr )page->attr; const char *key; HPDF_PTRACE((" HPDF_Page_GetExtGStateName\n")); if (!attr->ext_gstates) { HPDF_Dict resources; HPDF_Dict ext_gstates; resources = HPDF_Page_GetInheritableItem (page, "Resources", HPDF_OCLASS_DICT); if (!resources) return NULL; ext_gstates = HPDF_Dict_New (page->mmgr); if (!ext_gstates) return NULL; if (HPDF_Dict_Add (resources, "ExtGState", ext_gstates) != HPDF_OK) return NULL; attr->ext_gstates = ext_gstates; } /* search ext_gstate-object from ext_gstate-resource */ key = HPDF_Dict_GetKeyByObj (attr->ext_gstates, state); if (!key) { /* if the ext-gstate is not resisterd in ext-gstate resource, register * to ext-gstate resource. */ char ext_gstate_name[HPDF_LIMIT_MAX_NAME_LEN + 1]; char *ptr; char *end_ptr = ext_gstate_name + HPDF_LIMIT_MAX_NAME_LEN; ptr = (char *)HPDF_StrCpy (ext_gstate_name, "E", end_ptr); HPDF_IToA (ptr, attr->ext_gstates->list->count + 1, end_ptr); if (HPDF_Dict_Add (attr->ext_gstates, ext_gstate_name, state) != HPDF_OK) return NULL; key = HPDF_Dict_GetKeyByObj (attr->ext_gstates, state); } return key; }
const char* HPDF_Page_GetXObjectName (HPDF_Page page, HPDF_XObject xobj) { HPDF_PageAttr attr = (HPDF_PageAttr )page->attr; const char *key; HPDF_PTRACE((" HPDF_Page_GetXObjectName\n")); if (!attr->xobjects) { HPDF_Dict resources; HPDF_Dict xobjects; resources = HPDF_Page_GetInheritableItem (page, "Resources", HPDF_OCLASS_DICT); if (!resources) return NULL; xobjects = HPDF_Dict_New (page->mmgr); if (!xobjects) return NULL; if (HPDF_Dict_Add (resources, "XObject", xobjects) != HPDF_OK) return NULL; attr->xobjects = xobjects; } /* search xobject-object from xobject-resource */ key = HPDF_Dict_GetKeyByObj (attr->xobjects, xobj); if (!key) { /* if the xobject is not resisterd in xobject-resource, register * xobject to xobject-resource. */ char xobj_name[HPDF_LIMIT_MAX_NAME_LEN + 1]; char *ptr; char *end_ptr = xobj_name + HPDF_LIMIT_MAX_NAME_LEN; ptr = (char *)HPDF_StrCpy (xobj_name, "X", end_ptr); HPDF_IToA (ptr, attr->xobjects->list->count + 1, end_ptr); if (HPDF_Dict_Add (attr->xobjects, xobj_name, xobj) != HPDF_OK) return NULL; key = HPDF_Dict_GetKeyByObj (attr->xobjects, xobj); } return key; }
static HPDF_STATUS Type1Font_OnWrite (HPDF_Dict obj, HPDF_Stream stream) { HPDF_FontAttr attr = (HPDF_FontAttr)obj->attr; HPDF_Type1FontDefAttr fontdef_attr = (HPDF_Type1FontDefAttr)attr->fontdef->attr; HPDF_BasicEncoderAttr encoder_attr = (HPDF_BasicEncoderAttr)attr->encoder->attr; HPDF_UINT i; HPDF_STATUS ret; char buf[HPDF_TMP_BUF_SIZ]; char *eptr = buf + HPDF_TMP_BUF_SIZ - 1; HPDF_PTRACE ((" HPDF_Font_Type1Font_OnWrite\n")); /* if font is base14-font these entries is not required */ if ( ( fontdef_attr->write_widths || fontdef_attr->font_data ) && ( !fontdef_attr->is_base14font || encoder_attr->has_differences ) ) { char *pbuf; pbuf = (char *)HPDF_StrCpy (buf, "/FirstChar ", eptr); pbuf = HPDF_IToA (pbuf, encoder_attr->first_char, eptr); HPDF_StrCpy (pbuf, "\012", eptr); if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK) return ret; pbuf = (char *)HPDF_StrCpy (buf, "/LastChar ", eptr); pbuf = HPDF_IToA (pbuf, encoder_attr->last_char, eptr); HPDF_StrCpy (pbuf, "\012", eptr); if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK) return ret; /* Widths entry */ if ((ret = HPDF_Stream_WriteEscapeName (stream, "Widths")) != HPDF_OK) return ret; if ((ret = HPDF_Stream_WriteStr (stream, " [\012")) != HPDF_OK) return ret; pbuf = buf; for (i = encoder_attr->first_char; i <= encoder_attr->last_char; i++) { pbuf = HPDF_IToA (pbuf, attr->widths[i], eptr); *pbuf++ = ' '; if ((i + 1) % 16 == 0) { HPDF_StrCpy(pbuf, "\012", eptr); if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK) return ret; pbuf = buf; } } HPDF_StrCpy (pbuf, "]\012", eptr); if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK) return ret; } return attr->encoder->write_fn (attr->encoder, stream); }
HPDF_STATUS HPDF_Xref_WriteToStream (HPDF_Xref xref, HPDF_Stream stream, HPDF_Encrypt e) { HPDF_STATUS ret; HPDF_UINT i; char buf[HPDF_SHORT_BUF_SIZ]; char* pbuf; char* eptr = buf + HPDF_SHORT_BUF_SIZ - 1; HPDF_UINT str_idx; HPDF_Xref tmp_xref = xref; /* write each objects of xref to the specified stream */ HPDF_PTRACE((" HPDF_Xref_WriteToStream\n")); while (tmp_xref) { if (tmp_xref->start_offset == 0) str_idx = 1; else str_idx = 0; for (i = str_idx; i < tmp_xref->entries->count; i++) { HPDF_XrefEntry entry = (HPDF_XrefEntry)HPDF_List_ItemAt (tmp_xref->entries, i); HPDF_UINT obj_id = tmp_xref->start_offset + i; HPDF_UINT16 gen_no = entry->gen_no; entry->byte_offset = stream->size; pbuf = buf; pbuf = HPDF_IToA (pbuf, obj_id, eptr); *pbuf++ = ' '; pbuf = HPDF_IToA (pbuf, gen_no, eptr); HPDF_StrCpy(pbuf, " obj\012", eptr); if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK) return ret; if (e) HPDF_Encrypt_InitKey (e, obj_id, gen_no); if ((ret = HPDF_Obj_WriteValue (entry->obj, stream, e)) != HPDF_OK) return ret; if ((ret = HPDF_Stream_WriteStr (stream, "\012endobj\012")) != HPDF_OK) return ret; } tmp_xref = tmp_xref->prev; } /* start to write cross-reference table */ tmp_xref = xref; while (tmp_xref) { tmp_xref->addr = stream->size; pbuf = buf; pbuf = (char *)HPDF_StrCpy (pbuf, "xref\012", eptr); pbuf = HPDF_IToA (pbuf, tmp_xref->start_offset, eptr); *pbuf++ = ' '; pbuf = HPDF_IToA (pbuf, tmp_xref->entries->count, eptr); HPDF_StrCpy (pbuf, "\012", eptr); ret = HPDF_Stream_WriteStr (stream, buf); if (ret != HPDF_OK) return ret; for (i = 0; i < tmp_xref->entries->count; i++) { HPDF_XrefEntry entry = HPDF_Xref_GetEntry(tmp_xref, i); pbuf = buf; pbuf = HPDF_IToA2 (pbuf, entry->byte_offset, HPDF_BYTE_OFFSET_LEN + 1); *pbuf++ = ' '; pbuf = HPDF_IToA2 (pbuf, entry->gen_no, HPDF_GEN_NO_LEN + 1); *pbuf++ = ' '; *pbuf++ = entry->entry_typ; HPDF_StrCpy (pbuf, "\015\012", eptr); ret = HPDF_Stream_WriteStr (stream, buf); if (ret != HPDF_OK) return ret; } tmp_xref = tmp_xref->prev; } /* write trailer dictionary */ ret = WriteTrailer (xref, stream); return ret; }
HPDF_NewDoc (HPDF_Doc pdf) { char buf[HPDF_TMP_BUF_SIZ]; char *ptr = buf; char *eptr = buf + HPDF_TMP_BUF_SIZ - 1; const char *version; HPDF_PTRACE ((" HPDF_NewDoc\n")); if (!HPDF_Doc_Validate (pdf)) return HPDF_DOC_INVALID_OBJECT; HPDF_FreeDoc (pdf); pdf->xref = HPDF_Xref_New (pdf->mmgr, 0); if (!pdf->xref) return HPDF_CheckError (&pdf->error); pdf->trailer = pdf->xref->trailer; pdf->font_mgr = HPDF_List_New (pdf->mmgr, HPDF_DEF_ITEMS_PER_BLOCK); if (!pdf->font_mgr) return HPDF_CheckError (&pdf->error); if (!pdf->fontdef_list) { pdf->fontdef_list = HPDF_List_New (pdf->mmgr, HPDF_DEF_ITEMS_PER_BLOCK); if (!pdf->fontdef_list) return HPDF_CheckError (&pdf->error); } if (!pdf->encoder_list) { pdf->encoder_list = HPDF_List_New (pdf->mmgr, HPDF_DEF_ITEMS_PER_BLOCK); if (!pdf->encoder_list) return HPDF_CheckError (&pdf->error); } pdf->catalog = HPDF_Catalog_New (pdf->mmgr, pdf->xref); if (!pdf->catalog) return HPDF_CheckError (&pdf->error); pdf->root_pages = HPDF_Catalog_GetRoot (pdf->catalog); if (!pdf->root_pages) return HPDF_CheckError (&pdf->error); pdf->page_list = HPDF_List_New (pdf->mmgr, HPDF_DEF_PAGE_LIST_NUM); if (!pdf->page_list) return HPDF_CheckError (&pdf->error); pdf->cur_pages = pdf->root_pages; ptr = (char *)HPDF_StrCpy (ptr, (const char *)"Haru Free PDF Library ", eptr); version = HPDF_GetVersion (); HPDF_StrCpy (ptr, version, eptr); if (HPDF_SetInfoAttr (pdf, HPDF_INFO_PRODUCER, buf) != HPDF_OK) return HPDF_CheckError (&pdf->error); return HPDF_OK; }
static HPDF_STATUS LoadAfm (HPDF_FontDef fontdef, HPDF_Stream stream) { HPDF_Type1FontDefAttr attr = (HPDF_Type1FontDefAttr)fontdef->attr; char buf[HPDF_TMP_BUF_SIZ]; HPDF_CharData* cdata; HPDF_STATUS ret; HPDF_UINT len; char keyword[HPDF_LIMIT_MAX_NAME_LEN + 1]; HPDF_UINT i; HPDF_PTRACE (" LoadAfm\n"); len = HPDF_TMP_BUF_SIZ; /* chaeck AFM header */ if ((ret = HPDF_Stream_ReadLn (stream, buf, &len)) != HPDF_OK) return ret; GetKeyword (buf, keyword, HPDF_LIMIT_MAX_NAME_LEN + 1); if (HPDF_StrCmp (keyword, "StartFontMetrics") != 0) return HPDF_INVALID_AFM_HEADER; /* Global Font Information */ for (;;) { const char *s; len = HPDF_TMP_BUF_SIZ; if ((ret = HPDF_Stream_ReadLn (stream, buf, &len)) != HPDF_OK) return ret; s = GetKeyword (buf, keyword, HPDF_LIMIT_MAX_NAME_LEN + 1); if (HPDF_StrCmp (keyword, "FontName") == 0) { HPDF_StrCpy (fontdef->base_font, s, fontdef->base_font + HPDF_LIMIT_MAX_NAME_LEN); } else if (HPDF_StrCmp (keyword, "Weight") == 0) { if (HPDF_StrCmp (s, "Bold") == 0) fontdef->flags |= HPDF_FONT_FOURCE_BOLD; } else if (HPDF_StrCmp (keyword, "IsFixedPitch") == 0) { if (HPDF_StrCmp (s, "true") == 0) fontdef->flags |= HPDF_FONT_FIXED_WIDTH; } else if (HPDF_StrCmp (keyword, "ItalicAngle") == 0) { fontdef->italic_angle = (HPDF_INT16)HPDF_AToI (s); if (fontdef->italic_angle != 0) fontdef->flags |= HPDF_FONT_ITALIC; } else if (HPDF_StrCmp (keyword, "CharacterSet") == 0) { HPDF_UINT len = HPDF_StrLen (s, HPDF_LIMIT_MAX_STRING_LEN); if (len > 0) { attr->char_set = HPDF_GetMem (fontdef->mmgr, len + 1); if (!attr->char_set) return HPDF_Error_GetCode (fontdef->error); HPDF_StrCpy (attr->char_set, s, attr->char_set + len); } } else if (HPDF_StrCmp (keyword, "FontBBox") == 0) { char buf[HPDF_INT_LEN + 1]; s = GetKeyword (s, buf, HPDF_INT_LEN + 1); fontdef->font_bbox.left = (HPDF_REAL)HPDF_AToI (buf); s = GetKeyword (s, buf, HPDF_INT_LEN + 1); fontdef->font_bbox.bottom = (HPDF_REAL)HPDF_AToI (buf); s = GetKeyword (s, buf, HPDF_INT_LEN + 1); fontdef->font_bbox.right = (HPDF_REAL)HPDF_AToI (buf); GetKeyword (s, buf, HPDF_INT_LEN + 1); fontdef->font_bbox.top = (HPDF_REAL)HPDF_AToI (buf); } else if (HPDF_StrCmp (keyword, "EncodingScheme") == 0) { HPDF_StrCpy (attr->encoding_scheme, s, attr->encoding_scheme + HPDF_LIMIT_MAX_NAME_LEN); } else if (HPDF_StrCmp (keyword, "CapHeight") == 0) { fontdef->cap_height = (HPDF_UINT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "Ascender") == 0) { fontdef->ascent = (HPDF_INT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "Descender") == 0) { fontdef->descent = (HPDF_INT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "STDHW") == 0) { fontdef->stemh = (HPDF_UINT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "STDHV") == 0) { fontdef->stemv = (HPDF_UINT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "StartCharMetrics") == 0) { attr->widths_count = HPDF_AToI (s); break; } } cdata = (HPDF_CharData*)HPDF_GetMem (fontdef->mmgr, sizeof(HPDF_CharData) * attr->widths_count); if (cdata == NULL) return HPDF_Error_GetCode (fontdef->error); HPDF_MemSet (cdata, 0, sizeof(HPDF_CharData) * attr->widths_count); attr->widths = cdata; /* load CharMetrics */ for (i = 0; i < attr->widths_count; i++, cdata++) { const char *s; char buf2[HPDF_LIMIT_MAX_NAME_LEN + 1]; len = HPDF_TMP_BUF_SIZ; if ((ret = HPDF_Stream_ReadLn (stream, buf, &len)) != HPDF_OK) return ret; /* C default character code. */ s = GetKeyword (buf, buf2, HPDF_LIMIT_MAX_NAME_LEN + 1); if (HPDF_StrCmp (buf2, "CX") == 0) { /* not suppoted yet. */ return HPDF_SetError (fontdef->error, HPDF_INVALID_CHAR_MATRICS_DATA, 0); } else if (HPDF_StrCmp (buf2, "C") == 0) { s += 2; s = GetKeyword (s, buf2, HPDF_LIMIT_MAX_NAME_LEN + 1); HPDF_AToI (buf2); cdata->char_cd = (HPDF_INT16)HPDF_AToI (buf2); } else return HPDF_SetError (fontdef->error, HPDF_INVALID_CHAR_MATRICS_DATA, 0); /* WX Character width */ s = HPDF_StrStr (s, "WX ", 0); if (!s) return HPDF_SetError (fontdef->error, HPDF_INVALID_WX_DATA, 0); s += 3; s = GetKeyword (s, buf2, HPDF_LIMIT_MAX_NAME_LEN + 1); if (buf2[0] == 0) return HPDF_SetError (fontdef->error, HPDF_INVALID_WX_DATA, 0); cdata->width = (HPDF_INT16)HPDF_AToI (buf2); /* N PostScript language character name */ s = HPDF_StrStr (s, "N ", 0); if (!s) return HPDF_SetError (fontdef->error, HPDF_INVALID_N_DATA, 0); s += 2; GetKeyword (s, buf2, HPDF_LIMIT_MAX_NAME_LEN + 1); cdata->unicode = HPDF_GryphNameToUnicode (buf2); } return HPDF_OK; }
static HPDF_STATUS Type3RasterFont_OnWrite(HPDF_Dict obj, HPDF_Stream stream) { HPDF_FontAttr attr = (HPDF_FontAttr)obj->attr; HPDF_Type3RasterFontDefAttr fontdef_attr = (HPDF_Type3RasterFontDefAttr)attr->fontdef->attr; HPDF_BasicEncoderAttr encoder_attr = (HPDF_BasicEncoderAttr)attr->encoder->attr; HPDF_UINT i; HPDF_STATUS ret; char buf[HPDF_TMP_BUF_SIZ]; char *eptr = buf + HPDF_TMP_BUF_SIZ - 1; HPDF_PTRACE((" HPDF_Font_Type3RasterFont_OnWrite\n")); /* if font is base14-font these entries is not required */ if (1) { char *pbuf; pbuf = (char *)HPDF_StrCpy(buf, "/FirstChar ", eptr); pbuf = HPDF_IToA(pbuf, /*encoder_attr->first_char*/0, eptr); HPDF_StrCpy(pbuf, "\012", eptr); if ((ret = HPDF_Stream_WriteStr(stream, buf)) != HPDF_OK) return ret; pbuf = (char *)HPDF_StrCpy(buf, "/LastChar ", eptr); pbuf = HPDF_IToA(pbuf, /*encoder_attr->last_char*/255, eptr); HPDF_StrCpy(pbuf, "\012", eptr); if ((ret = HPDF_Stream_WriteStr(stream, buf)) != HPDF_OK) return ret; /* Widths entry */ if ((ret = HPDF_Stream_WriteEscapeName(stream, "Widths")) != HPDF_OK) return ret; if ((ret = HPDF_Stream_WriteStr(stream, " [\012")) != HPDF_OK) return ret; pbuf = buf; for (i = 0 /*encoder_attr->first_char*/; i <= 255/*encoder_attr->last_char*/; i++) { pbuf = HPDF_FToA(pbuf, fontdef_attr->chars[i].width / (72.0f / (HPDF_REAL)fontdef_attr->dpi_x), eptr); *pbuf++ = ' '; if ((i + 1) % 16 == 0) { HPDF_StrCpy(pbuf, "\012", eptr); if ((ret = HPDF_Stream_WriteStr(stream, buf)) != HPDF_OK) return ret; pbuf = buf; } } HPDF_StrCpy(pbuf, "]\012", eptr); if ((ret = HPDF_Stream_WriteStr(stream, buf)) != HPDF_OK) return ret; } return ret; }