HPDF_STATUS HPDF_Info_SetInfoAttr (HPDF_Dict info, HPDF_InfoType type, const char *value, HPDF_Encoder encoder) { const char* name = InfoTypeToName (type); HPDF_PTRACE((" HPDF_Info_SetInfoAttr\n")); if (type <= HPDF_INFO_MOD_DATE) return HPDF_SetError (info->error, HPDF_INVALID_PARAMETER, 0); if (type == HPDF_INFO_TRAPPED) return HPDF_Dict_AddName(info, name, value); return HPDF_Dict_Add (info, name, HPDF_String_New (info->mmgr, value, encoder)); }
HPDF_InsertPage (HPDF_Doc pdf, HPDF_Page target) { HPDF_Page page; HPDF_STATUS ret; HPDF_PTRACE ((" HPDF_InsertPage\n")); if (!HPDF_HasDoc (pdf)) return NULL; if (!HPDF_Page_Validate (target)) { HPDF_RaiseError (&pdf->error, HPDF_INVALID_PAGE, 0); return NULL; } /* check whether the page belong to the pdf */ if (pdf->mmgr != target->mmgr) { HPDF_RaiseError (&pdf->error, HPDF_INVALID_PAGE, 0); return NULL; } page = HPDF_Page_New (pdf->mmgr, pdf->xref); if (!page) { HPDF_CheckError (&pdf->error); return NULL; } if ((ret = HPDF_Page_InsertBefore (page, target)) != HPDF_OK) { HPDF_RaiseError (&pdf->error, ret, 0); return NULL; } if ((ret = HPDF_List_Insert (pdf->page_list, target, page)) != HPDF_OK) { HPDF_RaiseError (&pdf->error, ret, 0); return NULL; } if (pdf->compression_mode & HPDF_COMP_TEXT) HPDF_Page_SetFilter (page, HPDF_STREAM_FILTER_FLATE_DECODE); return page; }
HPDF_SetOpenAction (HPDF_Doc pdf, HPDF_Destination open_action) { HPDF_STATUS ret; HPDF_PTRACE ((" HPDF_SetOpenAction\n")); if (!HPDF_HasDoc (pdf)) return HPDF_INVALID_DOCUMENT; if (open_action && !HPDF_Destination_Validate (open_action)) return HPDF_RaiseError (&pdf->error, HPDF_INVALID_DESTINATION, 0); ret = HPDF_Catalog_SetOpenAction (pdf->catalog, open_action); if (ret != HPDF_OK) return HPDF_CheckError (&pdf->error); return HPDF_OK; }
const char* HPDF_Info_GetInfoAttr (HPDF_Dict info, HPDF_InfoType type) { const char* name = InfoTypeToName (type); HPDF_String s; HPDF_PTRACE((" HPDF_Info_GetInfoAttr\n")); if (!info) return NULL; s = (HPDF_String)HPDF_Dict_GetItem (info, name, HPDF_OCLASS_STRING); if (!s) return NULL; else return (const char *)(s->value); }
static void OnFree (HPDF_Dict obj) { HPDF_FontAttr attr = (HPDF_FontAttr)obj->attr; HPDF_PTRACE ((" HPDF_TTFont_OnFree\n")); if (attr) { if (attr->widths) { HPDF_FreeMem (obj->mmgr, attr->widths); } if (attr->used) { HPDF_FreeMem (obj->mmgr, attr->used); } HPDF_FreeMem (obj->mmgr, attr); } }
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); }
HPDF_STATUS HPDF_Type1FontDef_SetWidths (HPDF_FontDef fontdef, const HPDF_CharData* widths) { const HPDF_CharData* src = widths; HPDF_Type1FontDefAttr attr = (HPDF_Type1FontDefAttr)fontdef->attr; HPDF_CharData* dst; HPDF_UINT i = 0; HPDF_PTRACE (" HPDF_Type1FontDef_SetWidths\n"); FreeWidth (fontdef); while (src->unicode != 0xFFFF) { src++; i++; } attr->widths_count = i; dst = (HPDF_CharData*)HPDF_GetMem (fontdef->mmgr, sizeof(HPDF_CharData) * attr->widths_count); if (dst == NULL) return HPDF_Error_GetCode (fontdef->error); HPDF_MemSet (dst, 0, sizeof(HPDF_CharData) * attr->widths_count); attr->widths = dst; src = widths; for (i = 0; i < attr->widths_count; i++) { dst->char_cd = src->char_cd; dst->unicode = src->unicode; dst->width = src->width; if (dst->unicode == 0x0020) { fontdef->missing_width = src->width; } src++; dst++; } return HPDF_OK; }
HPDF_Annot_SetGrayColor (HPDF_Annotation annot, HPDF_REAL color) { HPDF_Array cArray; HPDF_STATUS ret = HPDF_OK; HPDF_PTRACE (" HPDF_Annot_SetGrayColor\n"); cArray = HPDF_Array_New (annot->mmgr); if (!cArray) return HPDF_Error_GetCode ( annot->error); ret += HPDF_Dict_Add (annot, "C", cArray); ret += HPDF_Array_AddReal ( cArray, color); if (ret != HPDF_OK) return HPDF_Error_GetCode ( annot->error); return HPDF_OK; }
HPDF_Page_GetCurrentTextPos2 (HPDF_Page page, HPDF_Point *pos) { HPDF_PageAttr attr; HPDF_PTRACE((" HPDF_Page_GetCurrentTextPos2\n")); pos->x = 0; pos->y = 0; if (!HPDF_Page_Validate (page)) return HPDF_INVALID_PAGE; attr = (HPDF_PageAttr)page->attr; if (attr->gmode & HPDF_GMODE_TEXT_OBJECT) *pos = attr->text_pos; return HPDF_OK; }
HPDF_STATUS HPDF_List_Remove (HPDF_List list, void *item) { HPDF_UINT i; void **obj = list->obj; HPDF_PTRACE((" HPDF_List_Remove\n")); for (i = 0; i < list->count; i++) { if (*obj == item) { HPDF_List_RemoveByIndex(list, i); return HPDF_OK; } else obj++; } return HPDF_ITEM_NOT_FOUND; }
HPDF_Annotation HPDF_LinkAnnot_New (HPDF_MMgr mmgr, HPDF_Xref xref, HPDF_Rect rect, HPDF_Destination dst) { HPDF_Annotation annot; HPDF_PTRACE((" HPDF_LinkAnnot_New\n")); annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_LINK, rect); if (!annot) return NULL; if (HPDF_Dict_Add (annot, "Dest", dst) != HPDF_OK) return NULL; return annot; }
HPDF_MarkupAnnot_SetInteriorGrayColor (HPDF_Annotation annot, HPDF_REAL color)/* IC with Gray entry */ { HPDF_Array cArray; HPDF_STATUS ret = HPDF_OK; HPDF_PTRACE (" HPDF_MarkupAnnot_SetInteriorGrayColor\n"); cArray = HPDF_Array_New ( annot->mmgr); if (!cArray) return HPDF_Error_GetCode ( annot->error); ret += HPDF_Dict_Add (annot, "IC", cArray); ret += HPDF_Array_AddReal (cArray, color); if (ret != HPDF_OK) return HPDF_Error_GetCode ( annot->error); return HPDF_OK; }
HPDF_Annotation HPDF_PopupAnnot_New (HPDF_MMgr mmgr, HPDF_Xref xref, HPDF_Rect rect, HPDF_Annotation parent) { HPDF_Annotation annot; HPDF_PTRACE (" HPDF_PopupAnnot_New\n"); annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_POPUP, rect); if (!annot) return NULL; if (HPDF_Dict_Add (annot, "Parent", parent) != HPDF_OK) return NULL; return annot; }
HPDF_NameDict HPDF_NameDict_New (HPDF_MMgr mmgr, HPDF_Xref xref) { HPDF_NameDict ndict; HPDF_PTRACE((" HPDF_NameDict_New\n")); ndict = HPDF_Dict_New (mmgr); if (!ndict) return NULL; if (HPDF_Xref_Add (xref, ndict) != HPDF_OK) return NULL; ndict->header.obj_class |= HPDF_OSUBCLASS_NAMEDICT; return ndict; }
HPDF_STATUS HPDF_Doc_SetEncryptOff (HPDF_Doc pdf) { HPDF_PTRACE ((" HPDF_Doc_SetEncryptOff\n")); if (!pdf->encrypt_on) return HPDF_OK; /* if encrypy-dict object is registered to cross-reference-table, * replace it to null-object. * additionally remove encrypt-dict object from trailer-object. */ if (pdf->encrypt_dict) { HPDF_UINT obj_id = pdf->encrypt_dict->header.obj_id; if (obj_id & HPDF_OTYPE_INDIRECT) { HPDF_XrefEntry entry; HPDF_Null null_obj; HPDF_Dict_RemoveElement (pdf->trailer, "Encrypt"); entry = HPDF_Xref_GetEntryByObjectId (pdf->xref, obj_id & 0x00FFFFFF); if (!entry) { return HPDF_SetError (&pdf->error, HPDF_DOC_ENCRYPTDICT_NOT_FOUND, 0); } null_obj = HPDF_Null_New (pdf->mmgr); if (!null_obj) return pdf->error.error_no; entry->obj = null_obj; null_obj->header.obj_id = obj_id | HPDF_OTYPE_INDIRECT; pdf->encrypt_dict->header.obj_id = HPDF_OTYPE_NONE; } } pdf->encrypt_on = HPDF_FALSE; return HPDF_OK; }
HPDF_LoadRawImageFromFile (HPDF_Doc pdf, const char *filename, HPDF_UINT width, HPDF_UINT height, HPDF_ColorSpace color_space) { HPDF_Stream imagedata; HPDF_Image image; HPDF_PTRACE ((" HPDF_LoadRawImageFromFile\n")); if (!HPDF_HasDoc (pdf)) return NULL; /* create file stream */ imagedata = HPDF_FileReader_New (pdf->mmgr, filename); if (HPDF_Stream_Validate (imagedata)) image = HPDF_Image_LoadRawImage (pdf->mmgr, imagedata, pdf->xref, width, height, color_space); else image = NULL; /* destroy file stream */ HPDF_Stream_Free (imagedata); if (!image) HPDF_CheckError (&pdf->error); if (pdf->compression_mode & HPDF_COMP_IMAGE) { if (image != NULL) image->filter = HPDF_STREAM_FILTER_FLATE_DECODE; else { printf("Error. image is NULL.\n"); assert (0); } } return image; }
HPDF_MarkupAnnot_SetCloudEffect (HPDF_Annotation annot, HPDF_INT cloudIntensity) /* BE entry */ { HPDF_Dict borderEffect; HPDF_STATUS ret = HPDF_OK; HPDF_PTRACE((" HPDF_MarkupAnnot_SetCloudEffect\n")); borderEffect = HPDF_Dict_New ( annot->mmgr); if (!borderEffect) return HPDF_Error_GetCode ( annot->error); ret += HPDF_Dict_Add ( annot, "BE", borderEffect); ret += HPDF_Dict_AddName ( borderEffect, "S", "C"); ret += HPDF_Dict_AddNumber ( borderEffect, "I", cloudIntensity); if (ret != HPDF_OK) return HPDF_Error_GetCode (annot->error); return HPDF_OK; }
void HPDF_Array_Clear (HPDF_Array array) { HPDF_UINT i; HPDF_PTRACE((" HPDF_Array_Clear\n")); if (!array) return; for (i = 0; i < array->list->count; i++) { void * obj = HPDF_List_ItemAt (array->list, i); if (obj) { HPDF_Obj_Free (array->mmgr, obj); } } HPDF_List_Clear (array->list); }
void HPDF_CIDFontDef_FreeWidth (HPDF_FontDef fontdef) { HPDF_CIDFontDefAttr attr = (HPDF_CIDFontDefAttr)fontdef->attr; HPDF_UINT i; HPDF_PTRACE (" HPDF_FontDef_Validate\n"); for (i = 0; i < attr->widths->count; i++) { HPDF_CID_Width *w = (HPDF_CID_Width *)HPDF_List_ItemAt (attr->widths, i); HPDF_FreeMem (fontdef->mmgr, w); } HPDF_List_Free (attr->widths); attr->widths = NULL; fontdef->valid = HPDF_FALSE; }
HPDF_INT16 HPDF_CIDFontDef_GetCIDWidth (HPDF_FontDef fontdef, HPDF_UINT16 cid) { HPDF_CIDFontDefAttr attr = (HPDF_CIDFontDefAttr)fontdef->attr; HPDF_UINT i; HPDF_PTRACE (" HPDF_CIDFontDef_GetCIDWidth\n"); for (i = 0; i < attr->widths->count; i++) { HPDF_CID_Width *w = (HPDF_CID_Width *)HPDF_List_ItemAt (attr->widths, i); if (w->cid == cid) return w->width; } /* Not found in pdf_cid_width array. */ return attr->DW; }
HPDF_SetPageLayout (HPDF_Doc pdf, HPDF_PageLayout layout) { HPDF_STATUS ret; HPDF_PTRACE ((" HPDF_GetPageLayout\n")); if (!HPDF_HasDoc (pdf)) return HPDF_INVALID_DOCUMENT; if (layout < 0 || layout >= HPDF_PAGE_LAYOUT_EOF) return HPDF_RaiseError (&pdf->error, HPDF_PAGE_LAYOUT_OUT_OF_RANGE, (HPDF_STATUS)layout); ret = HPDF_Catalog_SetPageLayout (pdf->catalog, layout); if (ret != HPDF_OK) HPDF_CheckError (&pdf->error); return HPDF_OK; }
HPDF_LoadJpegImageFromMem (HPDF_Doc pdf, const HPDF_BYTE *buffer, HPDF_UINT size) { HPDF_Image image; HPDF_PTRACE ((" HPDF_LoadJpegImageFromMem\n")); if (!HPDF_HasDoc (pdf)) { return NULL; } image = HPDF_Image_LoadJpegImageFromMem (pdf->mmgr, buffer, size , pdf->xref); if (!image) { HPDF_CheckError (&pdf->error); } return image; }
HPDF_SetPageMode (HPDF_Doc pdf, HPDF_PageMode mode) { HPDF_STATUS ret; HPDF_PTRACE ((" HPDF_GetPageMode\n")); if (!HPDF_HasDoc (pdf)) return HPDF_INVALID_DOCUMENT; if (mode < 0 || mode >= HPDF_PAGE_MODE_EOF) return HPDF_RaiseError (&pdf->error, HPDF_PAGE_MODE_OUT_OF_RANGE, (HPDF_STATUS)mode); ret = HPDF_Catalog_SetPageMode (pdf->catalog, mode); if (ret != HPDF_OK) return HPDF_CheckError (&pdf->error); return HPDF_OK; }
HPDF_SetPermission (HPDF_Doc pdf, HPDF_UINT permission) { HPDF_Encrypt e; HPDF_PTRACE ((" HPDF_SetPermission\n")); if (!HPDF_HasDoc (pdf)) return HPDF_DOC_INVALID_OBJECT; e = HPDF_EncryptDict_GetAttr (pdf->encrypt_dict); if (!e) return HPDF_RaiseError (&pdf->error, HPDF_DOC_ENCRYPTDICT_NOT_FOUND, 0); else e->permission = permission; return HPDF_OK; }
HPDF_Page_Create3DC3DMeasure(HPDF_Page page, HPDF_Point3D firstanchorpoint, HPDF_Point3D textanchorpoint) { HPDF_PageAttr attr; HPDF_Annotation measure; HPDF_PTRACE((" HPDF_Page_Create3DC3DMeasure\n")); if (!HPDF_Page_Validate (page)) return NULL; attr = (HPDF_PageAttr)page->attr; measure = HPDF_3DC3DMeasure_New(page->mmgr, attr->xref, firstanchorpoint, textanchorpoint); if ( !measure) HPDF_CheckError (page->error); return measure; }
HPDF_SaveToStream (HPDF_Doc pdf) { HPDF_PTRACE ((" HPDF_SaveToStream\n")); if (!HPDF_HasDoc (pdf)) return HPDF_INVALID_DOCUMENT; if (!pdf->stream) pdf->stream = HPDF_MemStream_New (pdf->mmgr, HPDF_STREAM_BUF_SIZ); if (!HPDF_Stream_Validate (pdf->stream)) return HPDF_RaiseError (&pdf->error, HPDF_INVALID_STREAM, 0); HPDF_MemStream_FreeData (pdf->stream); if (InternalSaveToStream (pdf, pdf->stream) != HPDF_OK) return HPDF_CheckError (&pdf->error); return HPDF_OK; }
HPDF_STATUS HPDF_Doc_SetCurrentPage (HPDF_Doc pdf, HPDF_Page page) { HPDF_PTRACE ((" HPDF_Doc_SetCurrentPage\n")); if (!HPDF_HasDoc (pdf)) return HPDF_INVALID_DOCUMENT; if (!HPDF_Page_Validate (page)) return HPDF_SetError (&pdf->error, HPDF_INVALID_PAGE, 0); /* check whether the page belong to the pdf */ if (pdf->mmgr != page->mmgr) return HPDF_SetError (&pdf->error, HPDF_INVALID_PAGE, 0); pdf->cur_page = page; return HPDF_OK; }
HPDF_EXPORT(HPDF_JavaScript) HPDF_CreateJavaScript( HPDF_Doc pdf, const char *code ) { HPDF_JavaScript javaScript; int len ; HPDF_PTRACE ((" HPDF_CreateJavaScript\n")); javaScript = (HPDF_JavaScript) HPDF_DictStream_New(pdf->mmgr, pdf->xref); if (!javaScript) { return NULL; } len = (HPDF_UINT)strlen(code); if (HPDF_Stream_Write (javaScript->stream, (HPDF_BYTE *)code, len) != HPDF_OK) { HPDF_Dict_Free(javaScript); return NULL; } return javaScript; }
HPDF_SaveToFile (HPDF_Doc pdf, const char *file_name) { HPDF_Stream stream; HPDF_PTRACE ((" HPDF_SaveToFile\n")); if (!HPDF_HasDoc (pdf)) return HPDF_INVALID_DOCUMENT; stream = HPDF_FileWriter_New (pdf->mmgr, file_name); if (!stream) return HPDF_CheckError (&pdf->error); InternalSaveToStream (pdf, stream); HPDF_Stream_Free (stream); return HPDF_CheckError (&pdf->error); }
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetPerspectiveProjection(HPDF_Dict view, HPDF_REAL fov) { HPDF_STATUS ret = HPDF_OK; HPDF_Dict projection; HPDF_PTRACE ((" HPDF_3DView_SetPerspectiveProjection\n")); if (view == NULL || fov < 0 || fov > 180) { return HPDF_INVALID_U3D_DATA; } projection = HPDF_Dict_New (view->mmgr); if (!projection) { return HPDF_Error_GetCode (view->error); } ret = HPDF_Dict_AddName (projection, "Subtype", "P"); if (ret != HPDF_OK) { HPDF_Dict_Free (projection); return ret; } ret = HPDF_Dict_AddName (projection, "PS", "Min"); if (ret != HPDF_OK) { HPDF_Dict_Free (projection); return ret; } ret = HPDF_Dict_AddReal (projection, "FOV", fov); if (ret != HPDF_OK) { HPDF_Dict_Free (projection); return ret; } ret = HPDF_Dict_Add (view, "P", projection); if (ret != HPDF_OK) { HPDF_Dict_Free (projection); return ret; } return ret; }