HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetOrthogonalProjection(HPDF_Dict view, HPDF_REAL mag) { HPDF_STATUS ret = HPDF_OK; HPDF_Dict projection; HPDF_PTRACE ((" HPDF_3DView_SetOrthogonalProjection\n")); if (view == NULL || mag <= 0) { 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", "O"); if (ret != HPDF_OK) { HPDF_Dict_Free (projection); return ret; } ret = HPDF_Dict_AddReal (projection, "OS", mag); 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; }
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetLighting(HPDF_Dict view, const char *scheme) { HPDF_STATUS ret = HPDF_OK; HPDF_Dict lighting; int i; static const char *schemes[] = { "Artwork", "None", "White", "Day", "Night", "Hard", "Primary", "Blue", "Red", "Cube", "CAD", "Headlamp" }; HPDF_PTRACE ((" HPDF_3DView_SetLighting\n")); if (view == NULL || scheme == NULL || scheme[0] == '\0') { return HPDF_INVALID_U3D_DATA; } for (i = 0; i < 12; i++) { if (!strcmp(scheme, schemes[i])) { break; } } if (i == 12) { return HPDF_INVALID_U3D_DATA; } lighting = HPDF_Dict_New (view->mmgr); if (!lighting) { return HPDF_Error_GetCode (view->error); } ret = HPDF_Dict_AddName (lighting, "Type", "3DLightingScheme"); if (ret != HPDF_OK) { HPDF_Dict_Free (lighting); return ret; } ret = HPDF_Dict_AddName (lighting, "Subtype", scheme); if (ret != HPDF_OK) { HPDF_Dict_Free (lighting); return ret; } ret = HPDF_Dict_Add (view, "LS", lighting); if (ret != HPDF_OK) { HPDF_Dict_Free (lighting); return ret; } return ret; }
void HPDF_Obj_ForceFree (HPDF_MMgr mmgr, void *obj) { HPDF_Obj_Header *header; HPDF_PTRACE((" HPDF_Obj_ForceFree\n")); if (!obj) return; header = (HPDF_Obj_Header *)obj; HPDF_PTRACE((" HPDF_Obj_ForceFree obj=0x%08X obj_id=0x%08X " "obj_class=0x%08X\n", (HPDF_UINT)obj, (HPDF_UINT)(header->obj_id), (HPDF_UINT)(header->obj_class))); switch (header->obj_class & HPDF_OCLASS_ANY) { case HPDF_OCLASS_STRING: HPDF_String_Free (obj); break; case HPDF_OCLASS_BINARY: HPDF_Binary_Free (obj); break; case HPDF_OCLASS_ARRAY: HPDF_Array_Free (obj); break; case HPDF_OCLASS_DICT: HPDF_Dict_Free (obj); break; default: HPDF_FreeMem (mmgr, obj); } }
void HPDF_Xref_Free (HPDF_Xref xref) { HPDF_UINT i; HPDF_XrefEntry entry; HPDF_Xref tmp_xref; HPDF_PTRACE((" HPDF_Xref_Free\n")); /* delete xref entries. where prev element is not NULL, * delete all xref entries recursively. */ while (xref) { /* delete all objects belong to the xref. */ if (xref->entries) { for (i = 0; i < xref->entries->count; i++) { entry = HPDF_Xref_GetEntry (xref, i); if (entry->obj) HPDF_Obj_ForceFree (xref->mmgr, entry->obj); HPDF_FreeMem (xref->mmgr, entry); } HPDF_List_Free(xref->entries); } if (xref->trailer) HPDF_Dict_Free (xref->trailer); tmp_xref = xref->prev; HPDF_FreeMem (xref->mmgr, xref); xref = tmp_xref; } }
HPDF_EncryptDict HPDF_EncryptDict_New (HPDF_MMgr mmgr, HPDF_Xref xref) { HPDF_Encrypt attr; HPDF_EncryptDict dict; HPDF_PTRACE((" HPDF_EncryptDict_New\n")); dict = HPDF_Dict_New (mmgr); if (!dict) return NULL; dict->header.obj_class |= HPDF_OSUBCLASS_ENCRYPT; dict->free_fn = HPDF_EncryptDict_OnFree; attr = HPDF_GetMem (dict->mmgr, sizeof(HPDF_Encrypt_Rec)); if (!attr) { HPDF_Dict_Free (dict); return NULL; } dict->attr = attr; HPDF_Encrypt_Init (attr); if (HPDF_Xref_Add (xref, dict) != HPDF_OK) return NULL; return dict; }
HPDF_Dict HPDF_3DView_New( HPDF_MMgr mmgr, HPDF_Xref xref, HPDF_U3D u3d, const char *name) { HPDF_STATUS ret = HPDF_OK; HPDF_Dict view; HPDF_PTRACE ((" HPDF_3DView_New\n")); if (name == NULL || name[0] == '\0') { return NULL; } view = HPDF_Dict_New (mmgr); if (!view) { return NULL; } if (HPDF_Xref_Add (xref, view) != HPDF_OK) return NULL; ret = HPDF_Dict_AddName (view, "TYPE", "3DView"); if (ret != HPDF_OK) { HPDF_Dict_Free (view); return NULL; } ret = HPDF_Dict_Add (view, "XN", HPDF_String_New (mmgr, name, NULL)); if (ret != HPDF_OK) { HPDF_Dict_Free (view); return NULL; } ret = HPDF_Dict_Add (view, "IN", HPDF_String_New (mmgr, name, NULL)); if (ret != HPDF_OK) { HPDF_Dict_Free (view); return NULL; } ret = HPDF_U3D_Add3DView( u3d, view); if (ret != HPDF_OK) { HPDF_Dict_Free (view); return NULL; } return view; }
HPDF_Page HPDF_Page_New (HPDF_MMgr mmgr, HPDF_Xref xref) { HPDF_STATUS ret; HPDF_PageAttr attr; HPDF_Page page; HPDF_PTRACE((" HPDF_Page_New\n")); page = HPDF_Dict_New (mmgr); if (!page) return NULL; page->header.obj_class |= HPDF_OSUBCLASS_PAGE; page->free_fn = Page_OnFree; page->before_write_fn = Page_BeforeWrite; attr = HPDF_GetMem (page->mmgr, sizeof(HPDF_PageAttr_Rec)); if (!attr) { HPDF_Dict_Free (page); return NULL; } page->attr = attr; HPDF_MemSet (attr, 0, sizeof(HPDF_PageAttr_Rec)); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; attr->cur_pos = HPDF_ToPoint (0, 0); attr->text_pos = HPDF_ToPoint (0, 0); ret = HPDF_Xref_Add (xref, page); if (ret != HPDF_OK) return NULL; attr->gstate = HPDF_GState_New (page->mmgr, NULL); attr->contents = HPDF_DictStream_New (page->mmgr, xref); if (!attr->gstate || !attr->contents) return NULL; attr->stream = attr->contents->stream; attr->xref = xref; /* add requiered elements */ ret += HPDF_Dict_AddName (page, "Type", "Page"); ret += HPDF_Dict_Add (page, "MediaBox", HPDF_Box_Array_New (page->mmgr, HPDF_ToBox (0, 0, (HPDF_INT16)(HPDF_DEF_PAGE_WIDTH), (HPDF_INT16)(HPDF_DEF_PAGE_HEIGHT)))); ret += HPDF_Dict_Add (page, "Contents", attr->contents); ret += AddResource (page); if (ret != HPDF_OK) return NULL; return page; }
HPDF_STATUS HPDF_PDFA_AppendOutputIntents(HPDF_Doc pdf, const char *iccname, HPDF_Dict iccdict) { HPDF_Array intents; HPDF_Dict intent; HPDF_STATUS ret; if (!HPDF_HasDoc (pdf)) return HPDF_INVALID_DOCUMENT; /* prepare intent */ intent = HPDF_Dict_New (pdf->mmgr); ret = HPDF_Xref_Add (pdf->xref, intent); if ( ret != HPDF_OK) { HPDF_Dict_Free(intent); return ret; } ret += HPDF_Dict_AddName (intent, "Type", "OutputIntent"); ret += HPDF_Dict_AddName (intent, "S", "GTS_PDFA1"); ret += HPDF_Dict_Add (intent, "OutputConditionIdentifier", HPDF_String_New (pdf->mmgr, iccname, NULL)); ret += HPDF_Dict_Add (intent, "OutputCondition", HPDF_String_New (pdf->mmgr, iccname,NULL)); ret += HPDF_Dict_Add (intent, "Info", HPDF_String_New (pdf->mmgr, iccname, NULL)); ret += HPDF_Dict_Add (intent, "DestOutputProfile ", iccdict); if ( ret != HPDF_OK) { HPDF_Dict_Free(intent); return ret; } /* Copied from HPDF_AddIntent - not public function */ intents = HPDF_Dict_GetItem (pdf->catalog, "OutputIntents", HPDF_OCLASS_ARRAY); if (intents == NULL) { intents = HPDF_Array_New (pdf->mmgr); if (intents) { HPDF_STATUS ret = HPDF_Dict_Add (pdf->catalog, "OutputIntents", intents); if (ret != HPDF_OK) { HPDF_CheckError (&pdf->error); return HPDF_Error_GetDetailCode (&pdf->error); } } } HPDF_Array_Add(intents,intent); return HPDF_Error_GetDetailCode (&pdf->error); }
HPDF_Dict HPDF_PageLabel_New (HPDF_Doc pdf, HPDF_PageNumStyle style, HPDF_INT first_page, const char *prefix) { HPDF_Dict obj = HPDF_Dict_New (pdf->mmgr); HPDF_PTRACE ((" HPDF_PageLabel_New\n")); if (!obj) return NULL; switch (style) { case HPDF_PAGE_NUM_STYLE_DECIMAL: if (HPDF_Dict_AddName (obj, "S", "D") != HPDF_OK) goto Fail; break; case HPDF_PAGE_NUM_STYLE_UPPER_ROMAN: if (HPDF_Dict_AddName (obj, "S", "R") != HPDF_OK) goto Fail; break; case HPDF_PAGE_NUM_STYLE_LOWER_ROMAN: if (HPDF_Dict_AddName (obj, "S", "r") != HPDF_OK) goto Fail; break; case HPDF_PAGE_NUM_STYLE_UPPER_LETTERS: if (HPDF_Dict_AddName (obj, "S", "A") != HPDF_OK) goto Fail; break; case HPDF_PAGE_NUM_STYLE_LOWER_LETTERS: if (HPDF_Dict_AddName (obj, "S", "a") != HPDF_OK) goto Fail; break; default: HPDF_SetError (&pdf->error, HPDF_PAGE_NUM_STYLE_OUT_OF_RANGE, (HPDF_STATUS)style); goto Fail; } if (prefix && prefix[0] != 0) if (HPDF_Dict_Add (obj, "P", HPDF_String_New (pdf->mmgr, prefix, pdf->def_encoder)) != HPDF_OK) goto Fail; if (first_page != 0) if (HPDF_Dict_AddNumber (obj, "St", first_page) != HPDF_OK) goto Fail; return obj; Fail: HPDF_Dict_Free (obj); return NULL; }
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; }
HPDF_U3D HPDF_U3D_LoadU3DFromMem ( HPDF_MMgr mmgr, const HPDF_BYTE *buf, HPDF_UINT size, HPDF_Xref xref ) { HPDF_Dict image; HPDF_STATUS ret = HPDF_OK; HPDF_PTRACE ((" HPDF_U3D_LoadU3DFromMem\n")); image = HPDF_DictStream_New (mmgr, xref); if (!image) { return NULL; } image->header.obj_class |= HPDF_OSUBCLASS_XOBJECT; ret = HPDF_Dict_AddName (image, "Type", "XObject"); if (ret != HPDF_OK) { HPDF_Dict_Free(image); return NULL; } ret = HPDF_Dict_AddName (image, "Subtype", "Image"); if (ret != HPDF_OK) { HPDF_Dict_Free(image); return NULL; } if (HPDF_Stream_Write (image->stream, buf, size) != HPDF_OK) { HPDF_Dict_Free(image); return NULL; } return image; }
HPDF_EXPORT(HPDF_Dict) HPDF_Create3DView(HPDF_MMgr mmgr, const char *name) { HPDF_STATUS ret = HPDF_OK; HPDF_Dict view; HPDF_PTRACE ((" HPDF_Create3DView\n")); if (name == NULL || name[0] == '\0') { return NULL; } view = HPDF_Dict_New (mmgr); if (!view) { return NULL; } ret = HPDF_Dict_AddName (view, "TYPE", "3DView"); if (ret != HPDF_OK) { HPDF_Dict_Free (view); return NULL; } ret = HPDF_Dict_Add (view, "XN", HPDF_String_New (mmgr, name, NULL)); if (ret != HPDF_OK) { HPDF_Dict_Free (view); return NULL; } ret = HPDF_Dict_Add (view, "IN", HPDF_String_New (mmgr, name, NULL)); if (ret != HPDF_OK) { HPDF_Dict_Free (view); return NULL; } return view; }
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_EXPORT(HPDF_Dict) HPDF_Create3DActivation(HPDF_Annotation u3dAnnotation) { HPDF_STATUS ret = HPDF_OK; HPDF_Dict activation; HPDF_PTRACE ((" HPDF_Create3DActivation\n")); activation = HPDF_Dict_New (u3dAnnotation->mmgr); if (!activation) { return NULL; } ret = HPDF_Dict_AddName (activation, "DIS", "U"); if (ret != HPDF_OK) { HPDF_Dict_Free (activation); return NULL; } return activation; }
HPDF_Font HPDF_Type0Font_New (HPDF_MMgr mmgr, HPDF_FontDef fontdef, HPDF_Encoder encoder, HPDF_Xref xref) { HPDF_Dict font; HPDF_FontAttr attr; HPDF_CMapEncoderAttr encoder_attr; HPDF_STATUS ret = 0; HPDF_Array descendant_fonts; HPDF_PTRACE ((" HPDF_Type0Font_New\n")); font = HPDF_Dict_New (mmgr); if (!font) return NULL; font->header.obj_class |= HPDF_OSUBCLASS_FONT; /* check whether the fontdef object and the encoder object is valid. */ if (encoder->type != HPDF_ENCODER_TYPE_DOUBLE_BYTE) { HPDF_SetError(font->error, HPDF_INVALID_ENCODER_TYPE, 0); return NULL; } if (fontdef->type != HPDF_FONTDEF_TYPE_CID && fontdef->type != HPDF_FONTDEF_TYPE_TRUETYPE) { HPDF_SetError(font->error, HPDF_INVALID_FONTDEF_TYPE, 0); return NULL; } attr = HPDF_GetMem (mmgr, sizeof(HPDF_FontAttr_Rec)); if (!attr) { HPDF_Dict_Free (font); return NULL; } font->header.obj_class |= HPDF_OSUBCLASS_FONT; font->write_fn = NULL; font->free_fn = OnFree_Func; font->attr = attr; encoder_attr = (HPDF_CMapEncoderAttr)encoder->attr; HPDF_MemSet (attr, 0, sizeof(HPDF_FontAttr_Rec)); attr->writing_mode = encoder_attr->writing_mode; attr->text_width_fn = TextWidth; attr->measure_text_fn = MeasureText; attr->fontdef = fontdef; attr->encoder = encoder; attr->xref = xref; if (HPDF_Xref_Add (xref, font) != HPDF_OK) return NULL; ret += HPDF_Dict_AddName (font, "Type", "Font"); ret += HPDF_Dict_AddName (font, "BaseFont", fontdef->base_font); ret += HPDF_Dict_AddName (font, "Subtype", "Type0"); if (fontdef->type == HPDF_FONTDEF_TYPE_CID) { ret += HPDF_Dict_AddName (font, "Encoding", encoder->name); } else { attr->cmap_stream = CreateCMap (encoder, xref); if (attr->cmap_stream) { ret += HPDF_Dict_Add (font, "Encoding", attr->cmap_stream); } else return NULL; } if (ret != HPDF_OK) return NULL; descendant_fonts = HPDF_Array_New (mmgr); if (!descendant_fonts) return NULL; if (HPDF_Dict_Add (font, "DescendantFonts", descendant_fonts) != HPDF_OK) return NULL; if (fontdef->type == HPDF_FONTDEF_TYPE_CID) { attr->descendant_font = CIDFontType0_New (font, xref); attr->type = HPDF_FONT_TYPE0_CID; } else { attr->descendant_font = CIDFontType2_New (font, xref); attr->type = HPDF_FONT_TYPE0_TT; } if (!attr->descendant_font) return NULL; else if (HPDF_Array_Add (descendant_fonts, attr->descendant_font) != HPDF_OK) return NULL; return font; }
HPDF_Font HPDF_Type3RasterFont_New(HPDF_MMgr mmgr, HPDF_FontDef fontdef, HPDF_Encoder encoder, HPDF_Xref xref) { HPDF_Dict font; HPDF_FontAttr attr; HPDF_Type3RasterFontDefAttr fontdef_attr; HPDF_BasicEncoderAttr encoder_attr; HPDF_STATUS ret = 0; HPDF_UINT i; HPDF_PTRACE((" HPDF_Type3RasterFont_New\n")); /* check whether the fontdef object and the encoder object is valid. */ if (encoder->type != HPDF_ENCODER_TYPE_SINGLE_BYTE) { HPDF_SetError(mmgr->error, HPDF_INVALID_ENCODER_TYPE, 0); return NULL; } if (fontdef->type != HPDF_FONTDEF_TYPE_TYPE3RASTER) { HPDF_SetError(mmgr->error, HPDF_INVALID_FONTDEF_TYPE, 0); return NULL; } font = HPDF_Dict_New(mmgr); if (!font) return NULL; font->header.obj_class |= HPDF_OSUBCLASS_FONT; attr = HPDF_GetMem(mmgr, sizeof(HPDF_FontAttr_Rec)); if (!attr) { HPDF_Dict_Free(font); return NULL; } font->header.obj_class |= HPDF_OSUBCLASS_FONT; font->write_fn = Type3RasterFont_OnWrite; font->free_fn = Type3RasterFont_OnFree; HPDF_MemSet(attr, 0, sizeof(HPDF_FontAttr_Rec)); font->attr = attr; attr->type = HPDF_FONT_TYPE3; attr->writing_mode = HPDF_WMODE_HORIZONTAL; attr->text_width_fn = Type3RasterFont_TextWidth; attr->measure_text_fn = Type3RasterFont_MeasureText; attr->fontdef = fontdef; attr->encoder = encoder; attr->xref = xref; /* singlebyte-font has a widths-array which is an array of 256 signed * short integer. */ attr->widths = HPDF_GetMem(mmgr, sizeof(HPDF_INT16) * 256); if (!attr->widths) { HPDF_Dict_Free(font); return NULL; } encoder_attr = (HPDF_BasicEncoderAttr)encoder->attr; HPDF_MemSet(attr->widths, 0, sizeof(HPDF_INT16) * 256); for (i = 0 /*encoder_attr->first_char*/; i <= 255 /*encoder_attr->last_char*/; i++) { HPDF_UINT16 w = HPDF_Type3RasterFontDef_GetWidth(fontdef, i); attr->widths[i] = w; } fontdef_attr = (HPDF_Type3RasterFontDefAttr)fontdef->attr; ret += HPDF_Dict_AddName(font, "Name", fontdef->base_font); ret += HPDF_Dict_AddName(font, "Type", "Font"); ret += HPDF_Dict_AddName(font, "Subtype", "Type3"); HPDF_REAL scale_x = 72.0f / (HPDF_REAL)fontdef_attr->dpi_x; HPDF_REAL scale_y = 72.0f / (HPDF_REAL)fontdef_attr->dpi_y; HPDF_TransMatrix font_matrix; font_matrix.a = scale_x; font_matrix.b = 0; font_matrix.c = 0; font_matrix.d = scale_y; font_matrix.x = 0; font_matrix.y = 0; HPDF_Array array = HPDF_Array_New(mmgr); ret += HPDF_Array_AddReal(array, font_matrix.a); ret += HPDF_Array_AddReal(array, font_matrix.b); ret += HPDF_Array_AddReal(array, font_matrix.c); ret += HPDF_Array_AddReal(array, font_matrix.d); ret += HPDF_Array_AddReal(array, font_matrix.x); ret += HPDF_Array_AddReal(array, font_matrix.y); ret += HPDF_Dict_Add(font, "FontMatrix", array); HPDF_Array diff_array = HPDF_Array_New(mmgr); ret += HPDF_Array_AddNumber(diff_array, 0); for (i = 0; i < 256; ++i) { char name[3]; sprintf(name, "%02X", i); ret += HPDF_Array_AddName(diff_array, name); } HPDF_Dict encoding = HPDF_Dict_New(mmgr); ret += HPDF_Dict_Add(encoding, "Differences", diff_array); ret += HPDF_Dict_Add(font, "Encoding", encoding); HPDF_Dict char_procs = HPDF_Dict_New(mmgr); for (i = 0; i < 256; ++i) { char name[3]; sprintf(name, "%02X", i); HPDF_Dict char_stream_dict = HPDF_DictStream_New(mmgr, xref); HPDF_Stream_WriteReal(char_stream_dict->stream, fontdef_attr->chars[i].width / scale_x); HPDF_Stream_WriteStr(char_stream_dict->stream, " 0 "); HPDF_Stream_WriteReal(char_stream_dict->stream, fontdef_attr->chars[i].left / scale_x); HPDF_Stream_WriteStr(char_stream_dict->stream, " "); HPDF_Stream_WriteReal(char_stream_dict->stream, fontdef_attr->chars[i].bottom / scale_y); HPDF_Stream_WriteStr(char_stream_dict->stream, " "); HPDF_Stream_WriteReal(char_stream_dict->stream, fontdef_attr->chars[i].right / scale_x); HPDF_Stream_WriteStr(char_stream_dict->stream, " "); HPDF_Stream_WriteReal(char_stream_dict->stream, fontdef_attr->chars[i].top / scale_y); HPDF_Stream_WriteStr(char_stream_dict->stream, " d1\012"); HPDF_Stream_WriteStr(char_stream_dict->stream, "q\012"); HPDF_Stream_WriteReal(char_stream_dict->stream, fontdef_attr->chars[i].pixels_x); HPDF_Stream_WriteStr(char_stream_dict->stream, " 0 0 "); HPDF_Stream_WriteReal(char_stream_dict->stream, fontdef_attr->chars[i].pixels_y); HPDF_Stream_WriteStr(char_stream_dict->stream, " "); HPDF_Stream_WriteReal(char_stream_dict->stream, fontdef_attr->chars[i].left / scale_x); HPDF_Stream_WriteStr(char_stream_dict->stream, " "); HPDF_Stream_WriteReal(char_stream_dict->stream, fontdef_attr->chars[i].bottom / scale_y); HPDF_Stream_WriteStr(char_stream_dict->stream, " cm\012"); HPDF_Stream_WriteStr(char_stream_dict->stream, "BI\012"); HPDF_Stream_WriteStr(char_stream_dict->stream, "/IM true\012"); HPDF_Stream_WriteStr(char_stream_dict->stream, "/W "); HPDF_Stream_WriteInt(char_stream_dict->stream, fontdef_attr->chars[i].pixels_x); HPDF_Stream_WriteStr(char_stream_dict->stream, " /H "); HPDF_Stream_WriteInt(char_stream_dict->stream, fontdef_attr->chars[i].pixels_y); HPDF_Stream_WriteStr(char_stream_dict->stream, "\012/BPC 1\012"); HPDF_Stream_WriteStr(char_stream_dict->stream, "/D [1 0]\012"); HPDF_Stream_WriteStr(char_stream_dict->stream, "ID\012"); if (fontdef_attr->chars[i].raster_data != NULL) HPDF_Stream_Write(char_stream_dict->stream, fontdef_attr->chars[i].raster_data, fontdef_attr->chars[i].raster_data_size); HPDF_Stream_WriteStr(char_stream_dict->stream, "\012EI\012"); HPDF_Stream_WriteStr(char_stream_dict->stream, "Q"); ret += HPDF_Dict_Add(char_procs, name, char_stream_dict); if (fontdef_attr->chars[i].left < fontdef->font_bbox.left) fontdef->font_bbox.left = fontdef_attr->chars[i].left; if (fontdef_attr->chars[i].bottom < fontdef->font_bbox.bottom) fontdef->font_bbox.bottom = fontdef_attr->chars[i].bottom; if (fontdef_attr->chars[i].right > fontdef->font_bbox.right) fontdef->font_bbox.right = fontdef_attr->chars[i].right; if (fontdef_attr->chars[i].top > fontdef->font_bbox.top) fontdef->font_bbox.top = fontdef_attr->chars[i].top; } fontdef->font_bbox.left /= scale_x; fontdef->font_bbox.bottom /= scale_y; fontdef->font_bbox.right /= scale_x; fontdef->font_bbox.top /= scale_y; ret += HPDF_Dict_Add(font, "CharProcs", char_procs); array = HPDF_Box_Array_New(mmgr, fontdef->font_bbox); ret += HPDF_Dict_Add(font, "FontBBox", array); if (ret != HPDF_OK) { HPDF_Dict_Free(font); return NULL; } if (HPDF_Xref_Add(xref, font) != HPDF_OK) return NULL; return font; }
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetBackgroundColor(HPDF_Dict view, HPDF_REAL r, HPDF_REAL g, HPDF_REAL b) { HPDF_Array color; HPDF_STATUS ret = HPDF_OK; HPDF_Dict background; HPDF_PTRACE ((" HPDF_3DView_SetBackgroundColor\n")); if (view == NULL || r < 0 || r > 1 || g < 0 || g > 1 || b < 0 || b > 1) { return HPDF_INVALID_U3D_DATA; } background = HPDF_Dict_New (view->mmgr); if (!background) { return HPDF_Error_GetCode (view->error); } color = HPDF_Array_New (view->mmgr); if (!color) { HPDF_Dict_Free (background); return HPDF_Error_GetCode (view->error); } ret = HPDF_Array_AddReal (color, r); if (ret != HPDF_OK) { HPDF_Array_Free (color); HPDF_Dict_Free (background); return ret; } ret = HPDF_Array_AddReal (color, g); if (ret != HPDF_OK) { HPDF_Array_Free (color); HPDF_Dict_Free (background); return ret; } ret = HPDF_Array_AddReal (color, b); if (ret != HPDF_OK) { HPDF_Array_Free (color); HPDF_Dict_Free (background); return ret; } ret = HPDF_Dict_AddName (background, "Type", "3DBG"); if (ret != HPDF_OK) { HPDF_Array_Free (color); HPDF_Dict_Free (background); return ret; } ret = HPDF_Dict_Add (background, "C", color); if (ret != HPDF_OK) { HPDF_Array_Free (color); HPDF_Dict_Free (background); return ret; } ret = HPDF_Dict_Add (view, "BG", background); if (ret != HPDF_OK) { HPDF_Array_Free (color); HPDF_Dict_Free (background); return ret; } return ret; }
static HPDF_STATUS LoadPngData (HPDF_Dict image, HPDF_Xref xref, HPDF_Stream png_data, HPDF_BOOL delayed_loading) { HPDF_STATUS ret = HPDF_OK; png_uint_32 width, height; int bit_depth, color_type; png_structp png_ptr = NULL; png_infop info_ptr = NULL; HPDF_PTRACE ((" HPDF_Image_LoadPngImage\n")); /* create read_struct. */ png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, image->error, PngErrorFunc, PngErrorFunc); if (png_ptr == NULL) { HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0); return HPDF_FAILD_TO_ALLOC_MEM; } /* create info-struct */ info_ptr = png_create_info_struct (png_ptr); if (info_ptr == NULL) { HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0); goto Exit; } png_set_sig_bytes (png_ptr, HPDF_PNG_BYTES_TO_CHECK); png_set_read_fn (png_ptr, (void *)png_data, (png_rw_ptr)&PngReadFunc); /* reading info structure. */ png_read_info(png_ptr, info_ptr); if (image->error->error_no != HPDF_OK) { goto Exit; } png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL); /* 16bit images are not supported. */ if (bit_depth == 16) { png_set_strip_16(png_ptr); } png_read_update_info(png_ptr, info_ptr); if (image->error->error_no != HPDF_OK) { goto Exit; } /* check palette-based images for transparent areas and load them immediately if found */ if (xref && PNG_COLOR_TYPE_PALETTE & color_type) { png_bytep trans; int num_trans; HPDF_Dict smask; png_bytep smask_data; if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) || !png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL)) { goto no_transparent_color_in_palette; } smask = HPDF_DictStream_New (image->mmgr, xref); if (!smask) { ret = HPDF_FAILD_TO_ALLOC_MEM; goto Exit; } smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT; ret = HPDF_Dict_AddName (smask, "Type", "XObject"); ret += HPDF_Dict_AddName (smask, "Subtype", "Image"); ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width); ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height); ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray"); ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth); if (ret != HPDF_OK) { HPDF_Dict_Free(smask); ret = HPDF_INVALID_PNG_IMAGE; goto Exit; } smask_data = HPDF_GetMem(image->mmgr, width * height); if (!smask_data) { HPDF_Dict_Free(smask); ret = HPDF_FAILD_TO_ALLOC_MEM; goto Exit; } if (ReadTransparentPaletteData(image, png_ptr, info_ptr, smask_data, trans, num_trans) != HPDF_OK) { HPDF_FreeMem(image->mmgr, smask_data); HPDF_Dict_Free(smask); ret = HPDF_INVALID_PNG_IMAGE; goto Exit; } if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) { HPDF_FreeMem(image->mmgr, smask_data); HPDF_Dict_Free(smask); ret = HPDF_FILE_IO_ERROR; goto Exit; } HPDF_FreeMem(image->mmgr, smask_data); ret += CreatePallet(image, png_ptr, info_ptr); ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width); ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height); ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth); ret += HPDF_Dict_Add (image, "SMask", smask); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return HPDF_OK; } no_transparent_color_in_palette: /* read images with alpha channel right away we have to do this because image transparent mask must be added to the Xref */ if (xref && PNG_COLOR_MASK_ALPHA & color_type) { HPDF_Dict smask; png_bytep smask_data; smask = HPDF_DictStream_New (image->mmgr, xref); if (!smask) { ret = HPDF_FAILD_TO_ALLOC_MEM; goto Exit; } smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT; ret = HPDF_Dict_AddName (smask, "Type", "XObject"); ret += HPDF_Dict_AddName (smask, "Subtype", "Image"); ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width); ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height); ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray"); ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth); if (ret != HPDF_OK) { HPDF_Dict_Free(smask); ret = HPDF_INVALID_PNG_IMAGE; goto Exit; } smask_data = HPDF_GetMem(image->mmgr, width * height); if (!smask_data) { HPDF_Dict_Free(smask); ret = HPDF_FAILD_TO_ALLOC_MEM; goto Exit; } if (ReadTransparentPngData(image, png_ptr, info_ptr, smask_data) != HPDF_OK) { HPDF_FreeMem(image->mmgr, smask_data); HPDF_Dict_Free(smask); ret = HPDF_INVALID_PNG_IMAGE; goto Exit; } if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) { HPDF_FreeMem(image->mmgr, smask_data); HPDF_Dict_Free(smask); ret = HPDF_FILE_IO_ERROR; goto Exit; } HPDF_FreeMem(image->mmgr, smask_data); if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray"); } else { ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB"); } ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width); ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height); ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth); ret += HPDF_Dict_Add (image, "SMask", smask); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return HPDF_OK; } /* if the image has color palette, copy the pallet of the image to * create color map. */ if (color_type == PNG_COLOR_TYPE_PALETTE) ret = CreatePallet(image, png_ptr, info_ptr); else if (color_type == PNG_COLOR_TYPE_GRAY) ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray"); else ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB"); if (ret != HPDF_OK) goto Exit; /* read image-data * if the image is interlaced, read whole image at once. * if delayed_loading is HPDF_TRUE, the data does not load this phase. */ if (delayed_loading) { image->before_write_fn = PngBeforeWrite; image->after_write_fn = PngAfterWrite; } else { if (png_get_interlace_type(png_ptr, info_ptr) != PNG_INTERLACE_NONE) ret = ReadPngData_Interlaced(image, png_ptr, info_ptr); else ret = ReadPngData(image, png_ptr, info_ptr); if (ret != HPDF_OK) goto Exit; } /* setting the info of the image. */ if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width) != HPDF_OK) goto Exit; if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height) != HPDF_OK) goto Exit; if (HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth) != HPDF_OK) goto Exit; /* clean up */ png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return HPDF_OK; Exit: png_destroy_read_struct(&png_ptr, &info_ptr, NULL); if (ret != HPDF_OK) { return ret; } return image->error->error_no; }
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_AddNode(HPDF_Dict view, const char *name, HPDF_REAL opacity, HPDF_BOOL visible) { HPDF_Array nodes = NULL; HPDF_Dict node; HPDF_STATUS ret = HPDF_OK; HPDF_PTRACE ((" HPDF_3DView_AddNode\n")); if (view == NULL || opacity < 0 || opacity > 1 || name == NULL || name[0] == '\0') { return HPDF_INVALID_U3D_DATA; } nodes = (HPDF_Array)HPDF_Dict_GetItem (view, "NA", HPDF_OCLASS_ARRAY); if (nodes == NULL) { nodes = HPDF_Array_New (view->mmgr); if (!nodes) { return HPDF_Error_GetCode (view->error); } ret = HPDF_Dict_Add (view, "NA", nodes); if (ret != HPDF_OK) { HPDF_Array_Free (nodes); return ret; } } node = HPDF_Dict_New (view->mmgr); if (!node) { HPDF_Array_Free (nodes); return HPDF_Error_GetCode (view->error); } ret = HPDF_Dict_AddName (node, "Type", "3DNode"); if (ret != HPDF_OK) { HPDF_Array_Free (nodes); HPDF_Dict_Free (node); return ret; } ret = HPDF_Dict_Add (node, "N", HPDF_String_New (view->mmgr, name, NULL)); if (ret != HPDF_OK) { HPDF_Array_Free (nodes); HPDF_Dict_Free (node); return ret; } ret = HPDF_Dict_AddReal (node, "O", opacity); if (ret != HPDF_OK) { HPDF_Array_Free (nodes); HPDF_Dict_Free (node); return ret; } ret = HPDF_Dict_AddBoolean (node, "V", visible); if (ret != HPDF_OK) { HPDF_Dict_Free (node); HPDF_Array_Free (nodes); return ret; } ret = HPDF_Array_Add(nodes, node); if (ret != HPDF_OK) { HPDF_Dict_Free (node); HPDF_Array_Free (nodes); return ret; } return ret; }
HPDF_Font HPDF_Type1Font_New (HPDF_MMgr mmgr, HPDF_FontDef fontdef, HPDF_Encoder encoder, HPDF_Xref xref) { HPDF_Dict font; HPDF_FontAttr attr; HPDF_Type1FontDefAttr fontdef_attr; HPDF_BasicEncoderAttr encoder_attr; HPDF_STATUS ret = 0; HPDF_UINT i; HPDF_PTRACE ((" HPDF_Type1Font_New\n")); /* check whether the fontdef object and the encoder object is valid. */ if (encoder->type != HPDF_ENCODER_TYPE_SINGLE_BYTE) { HPDF_SetError(mmgr->error, HPDF_INVALID_ENCODER_TYPE, 0); return NULL; } if (fontdef->type != HPDF_FONTDEF_TYPE_TYPE1) { HPDF_SetError(mmgr->error, HPDF_INVALID_FONTDEF_TYPE, 0); return NULL; } font = HPDF_Dict_New (mmgr); if (!font) return NULL; font->header.obj_class |= HPDF_OSUBCLASS_FONT; attr = HPDF_GetMem (mmgr, sizeof(HPDF_FontAttr_Rec)); if (!attr) { HPDF_Dict_Free (font); return NULL; } font->header.obj_class |= HPDF_OSUBCLASS_FONT; font->write_fn = Type1Font_OnWrite; font->free_fn = Type1Font_OnFree; HPDF_MemSet (attr, 0, sizeof(HPDF_FontAttr_Rec)); font->attr = attr; attr->type = HPDF_FONT_TYPE1; attr->writing_mode = HPDF_WMODE_HORIZONTAL; attr->text_width_fn = Type1Font_TextWidth; attr->measure_text_fn = Type1Font_MeasureText; attr->fontdef = fontdef; attr->encoder = encoder; attr->xref = xref; /* singlebyte-font has a widths-array which is an array of 256 signed * short integer. */ attr->widths = HPDF_GetMem (mmgr, sizeof(HPDF_INT16) * 256); if (!attr->widths) { HPDF_Dict_Free (font); return NULL; } encoder_attr = (HPDF_BasicEncoderAttr)encoder->attr; HPDF_MemSet (attr->widths, 0, sizeof(HPDF_INT16) * 256); for (i = encoder_attr->first_char; i <= encoder_attr->last_char; i++) { HPDF_UNICODE u = encoder_attr->unicode_map[i]; HPDF_UINT16 w = HPDF_Type1FontDef_GetWidth (fontdef, u); attr->widths[i] = w; } fontdef_attr = (HPDF_Type1FontDefAttr)fontdef->attr; if(strncmp (fontdef->base_font, "HPDF_", 5) == 0 && fontdef->is_form_font == HPDF_TRUE) { ret += HPDF_Dict_AddName (font, "Type", "Font"); ret += HPDF_Dict_AddName (font, "BaseFont", fontdef->base_font + 5); ret += HPDF_Dict_AddName (font, "Subtype", "TrueType"); } else{ ret += HPDF_Dict_AddName (font, "Type", "Font"); ret += HPDF_Dict_AddName (font, "BaseFont", fontdef->base_font); ret += HPDF_Dict_AddName (font, "Subtype", "Type1"); } if (!fontdef_attr->is_base14font) { if (fontdef->missing_width != 0) ret += HPDF_Dict_AddNumber (font, "MissingWidth", fontdef->missing_width); ret += Type1Font_CreateDescriptor (mmgr, font, xref); } if (ret != HPDF_OK) { HPDF_Dict_Free (font); return NULL; } if (HPDF_Xref_Add (xref, font) != HPDF_OK) return NULL; return font; }
HPDF_Font HPDF_TTFont_New (HPDF_MMgr mmgr, HPDF_FontDef fontdef, HPDF_Encoder encoder, HPDF_Xref xref) { HPDF_Dict font; HPDF_FontAttr attr; HPDF_TTFontDefAttr fontdef_attr; HPDF_BasicEncoderAttr encoder_attr; HPDF_STATUS ret = 0; HPDF_PTRACE ((" HPDF_TTFont_New\n")); font = HPDF_Dict_New (mmgr); if (!font) return NULL; font->header.obj_class |= HPDF_OSUBCLASS_FONT; /* check whether the fontdef object and the encoder object is valid. */ if (encoder->type != HPDF_ENCODER_TYPE_SINGLE_BYTE) { HPDF_SetError(font->error, HPDF_INVALID_ENCODER_TYPE, 0); return NULL; } if (fontdef->type != HPDF_FONTDEF_TYPE_TRUETYPE) { HPDF_SetError(font->error, HPDF_INVALID_FONTDEF_TYPE, 0); return NULL; } attr = (HPDF_FontAttr)HPDF_GetMem (mmgr, sizeof(HPDF_FontAttr_Rec)); if (!attr) { HPDF_Dict_Free (font); return NULL; } HPDF_MemSet (attr, 0, sizeof(HPDF_FontAttr_Rec)); font->header.obj_class |= HPDF_OSUBCLASS_FONT; font->write_fn = OnWrite; font->before_write_fn = BeforeWrite; font->free_fn = OnFree; font->attr = attr; attr->type = HPDF_FONT_TRUETYPE; attr->writing_mode = HPDF_WMODE_HORIZONTAL; attr->text_width_fn = TextWidth; attr->measure_text_fn = MeasureText; attr->fontdef = fontdef; attr->encoder = encoder; attr->xref = xref; /* singlebyte-font has a widths-array which is an array of 256 signed * short integer. * in the case of type1-font, widths-array for all letters is made in * constructer. but in the case of true-type-font, the array is * initialized at 0, and set when the corresponding character was used * for the first time. */ attr->widths = (HPDF_INT16*)HPDF_GetMem (mmgr, sizeof(HPDF_INT16) * 256); if (!attr->widths) { HPDF_Dict_Free (font); return NULL; } HPDF_MemSet (attr->widths, 0, sizeof(HPDF_INT16) * 256); attr->used = (HPDF_BYTE*)HPDF_GetMem (mmgr, sizeof(HPDF_BYTE) * 256); if (!attr->used) { HPDF_Dict_Free (font); return NULL; } HPDF_MemSet (attr->used, 0, sizeof(HPDF_BYTE) * 256); fontdef_attr = (HPDF_TTFontDefAttr)fontdef->attr; ret += HPDF_Dict_AddName (font, "Type", "Font"); ret += HPDF_Dict_AddName (font, "BaseFont", fontdef_attr->base_font); ret += HPDF_Dict_AddName (font, "Subtype", "TrueType"); encoder_attr = (HPDF_BasicEncoderAttr)encoder->attr; ret += HPDF_Dict_AddNumber (font, "FirstChar", encoder_attr->first_char); ret += HPDF_Dict_AddNumber (font, "LastChar", encoder_attr->last_char); if (fontdef->missing_width != 0) ret += HPDF_Dict_AddNumber (font, "MissingWidth", fontdef->missing_width); if (ret != HPDF_OK) { HPDF_Dict_Free (font); return NULL; } if (HPDF_Xref_Add (xref, font) != HPDF_OK) return NULL; return font; }
HPDF_Font HPDF_Type0Font_New (HPDF_MMgr mmgr, HPDF_FontDef fontdef, HPDF_Encoder encoder, HPDF_Xref xref) { HPDF_Dict font; HPDF_FontAttr attr; HPDF_CMapEncoderAttr encoder_attr; HPDF_STATUS ret = 0; HPDF_Array descendant_fonts; HPDF_PTRACE ((" HPDF_Type0Font_New\n")); font = HPDF_Dict_New (mmgr); if (!font) return NULL; font->header.obj_class |= HPDF_OSUBCLASS_FONT; /* check whether the fontdef object and the encoder object is valid. */ if (encoder->type != HPDF_ENCODER_TYPE_DOUBLE_BYTE) { HPDF_SetError(font->error, HPDF_INVALID_ENCODER_TYPE, 0); return NULL; } if (fontdef->type != HPDF_FONTDEF_TYPE_CID && fontdef->type != HPDF_FONTDEF_TYPE_TRUETYPE) { HPDF_SetError(font->error, HPDF_INVALID_FONTDEF_TYPE, 0); return NULL; } attr = HPDF_GetMem (mmgr, sizeof(HPDF_FontAttr_Rec)); if (!attr) { HPDF_Dict_Free (font); return NULL; } font->header.obj_class |= HPDF_OSUBCLASS_FONT; font->write_fn = NULL; font->free_fn = OnFree_Func; font->attr = attr; encoder_attr = (HPDF_CMapEncoderAttr)encoder->attr; HPDF_MemSet (attr, 0, sizeof(HPDF_FontAttr_Rec)); attr->writing_mode = encoder_attr->writing_mode; attr->text_width_fn = TextWidth; attr->measure_text_fn = MeasureText; attr->fontdef = fontdef; attr->encoder = encoder; attr->xref = xref; if (HPDF_Xref_Add (xref, font) != HPDF_OK) return NULL; ret += HPDF_Dict_AddName (font, "Type", "Font"); ret += HPDF_Dict_AddName (font, "BaseFont", fontdef->base_font); ret += HPDF_Dict_AddName (font, "Subtype", "Type0"); if (fontdef->type == HPDF_FONTDEF_TYPE_CID) { ret += HPDF_Dict_AddName (font, "Encoding", encoder->name); } else { /* * Handle the Unicode encoding, see hpdf_encoding_utf.c For some * reason, xpdf-based readers cannot deal with our cmap but work * fine when using the predefined "Identity-H" * encoding. However, text selection does not work, unless we * add a ToUnicode cmap. This CMap should also be "Identity", * but that does not work -- specifying our cmap as a stream however * does work. Who can understand that ? */ if (HPDF_StrCmp(encoder_attr->ordering, "Identity-H") == 0) { ret += HPDF_Dict_AddName (font, "Encoding", "Identity-H"); attr->cmap_stream = CreateCMap (encoder, xref); if (attr->cmap_stream) { ret += HPDF_Dict_Add (font, "ToUnicode", attr->cmap_stream); } else return NULL; } else { attr->cmap_stream = CreateCMap (encoder, xref); if (attr->cmap_stream) { ret += HPDF_Dict_Add (font, "Encoding", attr->cmap_stream); } else return NULL; } } if (ret != HPDF_OK) return NULL; descendant_fonts = HPDF_Array_New (mmgr); if (!descendant_fonts) return NULL; if (HPDF_Dict_Add (font, "DescendantFonts", descendant_fonts) != HPDF_OK) return NULL; if (fontdef->type == HPDF_FONTDEF_TYPE_CID) { attr->descendant_font = CIDFontType0_New (font, xref); attr->type = HPDF_FONT_TYPE0_CID; } else { attr->descendant_font = CIDFontType2_New (font, xref); attr->type = HPDF_FONT_TYPE0_TT; } if (!attr->descendant_font) return NULL; else if (HPDF_Array_Add (descendant_fonts, attr->descendant_font) != HPDF_OK) return NULL; return font; }
HPDF_U3D HPDF_U3D_LoadU3D (HPDF_MMgr mmgr, HPDF_Stream u3d_data, HPDF_Xref xref) { HPDF_Dict u3d; const char *type; HPDF_PTRACE ((" HPDF_U3D_LoadU3D\n")); u3d = HPDF_DictStream_New (mmgr, xref); if (!u3d) { return NULL; } u3d->header.obj_class |= HPDF_OSUBCLASS_XOBJECT; /* add required elements */ u3d->filter = HPDF_STREAM_FILTER_NONE; if (HPDF_Dict_AddName (u3d, "Type", "3D") != HPDF_OK) { HPDF_Dict_Free(u3d); return NULL; } if (Get3DStreamType (u3d_data, &type) != HPDF_OK) { HPDF_Dict_Free(u3d); return NULL; } if (HPDF_Dict_AddName (u3d, "Subtype", type) != HPDF_OK) { HPDF_Dict_Free(u3d); return NULL; } for (;;) { HPDF_BYTE buf[HPDF_STREAM_BUF_SIZ]; HPDF_UINT len = HPDF_STREAM_BUF_SIZ; HPDF_STATUS ret = HPDF_Stream_Read (u3d_data, buf, &len); if (ret != HPDF_OK) { if (ret == HPDF_STREAM_EOF) { if (len > 0) { ret = HPDF_Stream_Write (u3d->stream, buf, len); if (ret != HPDF_OK) { HPDF_Dict_Free(u3d); return NULL; } } break; } else { HPDF_Dict_Free(u3d); return NULL; } } if (HPDF_Stream_Write (u3d->stream, buf, len) != HPDF_OK) { HPDF_Dict_Free(u3d); return NULL; } } return u3d; }