HPDF_SetCompressionMode (HPDF_Doc pdf, HPDF_UINT mode) { if (!HPDF_Doc_Validate (pdf)) return HPDF_INVALID_DOCUMENT; if (mode != (mode & HPDF_COMP_MASK)) return HPDF_RaiseError (&pdf->error, HPDF_INVALID_COMPRESSION_MODE, 0); #ifndef HPDF_NOZLIB pdf->compression_mode = mode; return HPDF_OK; #else /* HPDF_NOZLIB */ return HPDF_INVALID_COMPRESSION_MODE; #endif /* HPDF_NOZLIB */ }
HPDF_SetEncryptionMode (HPDF_Doc pdf, HPDF_EncryptMode mode, HPDF_UINT key_len) { HPDF_Encrypt e; HPDF_PTRACE ((" HPDF_SetEncryptionMode\n")); if (!HPDF_Doc_Validate (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 { if (mode == HPDF_ENCRYPT_R2) e->key_len = 5; else { /* if encryption mode is specified revision-3, the version of * pdf file is set to 1.4 */ pdf->pdf_version = HPDF_VER_14; if (key_len >= 5 && key_len <= 16) e->key_len = key_len; else if (key_len == 0) e->key_len = 16; else return HPDF_RaiseError (&pdf->error, HPDF_INVALID_ENCRYPT_KEY_LEN, 0); } e->mode = mode; } return HPDF_OK; }
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; }
HPDF_UseJPFonts (HPDF_Doc pdf) { HPDF_FontDef fontdef; HPDF_STATUS ret; if (!HPDF_Doc_Validate (pdf)) return HPDF_INVALID_DOCUMENT; /* MS-Gothic */ fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Gothic", MS_Gothic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Gothic,Bold", MS_Gothic_Bold_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Gothic,Italic", MS_Gothic_Italic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Gothic,BoldItalic", MS_Gothic_BoldItalic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; /* MS-PGothic */ fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PGothic", MS_PGothic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PGothic,Bold", MS_PGothic_Bold_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PGothic,Italic", MS_PGothic_Italic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PGothic,BoldItalic", MS_PGothic_BoldItalic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; /* MS-Mincho */ fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho", MS_Mincho_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho,Bold", MS_Mincho_Bold_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho,Italic", MS_Mincho_Italic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho,BoldItalic", MS_Mincho_BoldItalic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; /* MS-PMincho */ fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho", MS_PMincho_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho,Bold", MS_PMincho_Bold_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho,Italic", MS_PMincho_Italic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho,BoldItalic", MS_PMincho_BoldItalic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; return HPDF_OK; }