Well,
1) In hpdf_doc.c a stream is created:
HPDF_EXPORT(const char*)
HPDF_LoadTTFontFromFile (HPDF_Doc pdf,
const char *file_name,
HPDF_BOOL embedding)
{
HPDF_Stream font_data;
const char *ret;
HPDF_PTRACE ((" HPDF_LoadTTFontFromFile\n"));
if (!HPDF_HasDoc (pdf))
return NULL;
/* create file stream */
font_data = HPDF_FileReader_New (pdf->mmgr, file_name);
if (HPDF_Stream_Validate (font_data)) {
ret = LoadTTFontFromStream (pdf, font_data, embedding,
file_name);
} else
ret = NULL;
if (!ret)
HPDF_CheckError (&pdf->error);
return ret;
}
2) In hpdf_doc.c the stream is used:
static const char*
LoadTTFontFromStream (HPDF_Doc pdf,
HPDF_Stream font_data,
HPDF_BOOL embedding,
const char *file_name)
{
HPDF_FontDef def;
HPDF_PTRACE ((" HPDF_LoadTTFontFromStream\n"));
def = HPDF_TTFontDef_Load (pdf->mmgr, font_data,
embedding); //ON ERROR or not EMBEDDING the
stream is auto closed, not logical
if (def) {
HPDF_FontDef tmpdef = HPDF_Doc_FindFontDef (pdf, def-
>base_font);
if (tmpdef) {
HPDF_FontDef_Free (def);
HPDF_SetError (&pdf->error, HPDF_FONT_EXISTS, 0);
return NULL;
}
if (HPDF_List_Add (pdf->fontdef_list, def) != HPDF_OK) {
HPDF_FontDef_Free (def);
return NULL;
}
} else
return NULL;
if (embedding) { //
EMBEDDING: open stream is registered.
if (pdf->ttfont_tag[0] == 0) {
HPDF_MemCpy (pdf->ttfont_tag, (HPDF_BYTE *)"HPDFAA", 6);
} else {
HPDF_INT i;
for (i = 5; i >= 0; i--) {
pdf->ttfont_tag[i] += 1;
if (pdf->ttfont_tag[i] > 'Z')
pdf->ttfont_tag[i] = 'A';
else
break;
}
}
HPDF_TTFontDef_SetTagName (def, (char *)pdf->ttfont_tag);
}
return def-
>base_font; //NOT
EMBEDDING: open stream has been automatically closed
}
3) In hpdf_fontdef_tt.c the stream is closed:
HPDF_FontDef
HPDF_TTFontDef_Load (HPDF_MMgr mmgr,
HPDF_Stream stream,
HPDF_BOOL embedding)
{
HPDF_STATUS ret;
HPDF_FontDef fontdef;
HPDF_PTRACE ((" HPDF_TTFontDef_Load\n"));
fontdef = HPDF_TTFontDef_New (mmgr);
if (!fontdef) {
HPDF_Stream_Free (stream); //On error,
STREAM IS CLOSED HERE, this confused me, it is not logical
return NULL;
}
ret = LoadFontData (fontdef, stream, embedding, 0);
if (ret != HPDF_OK) {
HPDF_FontDef_Free (fontdef);
return NULL;
}
return fontdef;
}
4) In hpdf_fontdef_tt.c the stream is closed:
static HPDF_STATUS
LoadFontData (HPDF_FontDef fontdef,
HPDF_Stream stream,
HPDF_BOOL embedding,
HPDF_UINT offset)
{
HPDF_TTFontDefAttr attr = (HPDF_TTFontDefAttr)fontdef->attr;
HPDF_STATUS ret;
HPDF_TTFTable *tbl;
HPDF_PTRACE ((" HPDF_TTFontDef_LoadFontData\n"));
attr->stream = stream;
attr->embedding = embedding;
if ((ret = HPDF_Stream_Seek (stream, offset, HPDF_SEEK_SET)) !=
HPDF_OK)
return ret;
if ((ret = LoadTTFTable (fontdef)) != HPDF_OK)
return ret;
#ifdef HPDF_DUMP_FONTDATA
DumpTable (fontdef);
#endif /* HPDF_DUMP_FONTDATA */
if ((ret = ParseHead (fontdef)) != HPDF_OK)
return ret;
if ((ret = ParseMaxp (fontdef)) != HPDF_OK)
return ret;
if ((ret = ParseHhea (fontdef)) != HPDF_OK)
return ret;
if ((ret = ParseCMap (fontdef)) != HPDF_OK)
return ret;
if ((ret = ParseHmtx (fontdef)) != HPDF_OK)
return ret;
if ((ret = ParseLoca (fontdef)) != HPDF_OK)
return ret;
if ((ret = ParseName (fontdef)) != HPDF_OK)
return ret;
if ((ret = ParseOS2 (fontdef)) != HPDF_OK)
return ret;
tbl = FindTable (fontdef, "glyf");
if (!tbl)
return HPDF_SetError (fontdef->error, HPDF_TTF_MISSING_TABLE,
4);
attr->glyph_tbl.base_offset = tbl->offset;
fontdef->cap_height =
HPDF_TTFontDef_GetCharBBox (fontdef,
(HPDF_UINT16)'H').top;
fontdef->x_height =
HPDF_TTFontDef_GetCharBBox (fontdef,
(HPDF_UINT16)'x').top;
fontdef->missing_width = (HPDF_UINT32)attr->h_metric
[0].advance_width * 1000 /
attr->header.units_per_em;
HPDF_PTRACE ((" fontdef->cap_height=%d\n", fontdef->cap_height));
HPDF_PTRACE ((" fontdef->x_height=%d\n", fontdef->x_height));
HPDF_PTRACE ((" fontdef->missing_width=%d\n", fontdef-
>missing_width));
if (!embedding) {
HPDF_Stream_Free (attr->stream); //Not embedding, THE
STREAM IS CLOSED, this is not logical.
attr->stream = NULL;
}
return HPDF_OK;
}
I expected that the stream is the responsibility of the opener. I
expected that in 1) the stream is closed if needed. This is not the
case. To me this is not logical, opening a stream in source hpdf_doc.c
and closing the stream in hpdf_typedef_tt.c
In my case, I opened the stream in acp_getfontfileinfo.c and then I
found out that MY stream was automatically closed in hpdf_typedef_tt.c
Regards,
Mirco