Пример #1
0
static HPDF_STATUS
WriteTrailer  (HPDF_Xref     xref,
               HPDF_Stream   stream)
{
    HPDF_UINT max_obj_id = xref->entries->count + xref->start_offset;
    HPDF_STATUS ret;

    HPDF_PTRACE ((" WriteTrailer\n"));

    if ((ret = HPDF_Dict_AddNumber (xref->trailer, "Size", max_obj_id))
            != HPDF_OK)
        return ret;

    if (xref->prev)
        if ((ret = HPDF_Dict_AddNumber (xref->trailer, "Prev",
                xref->prev->addr)) != HPDF_OK)
            return ret;

    if ((ret = HPDF_Stream_WriteStr (stream, "trailer\012")) != HPDF_OK)
        return ret;

    if ((ret = HPDF_Dict_Write (xref->trailer, stream, NULL)) != HPDF_OK)
        return ret;

    if ((ret = HPDF_Stream_WriteStr (stream, "\012startxref\012")) != HPDF_OK)
        return ret;

    if ((ret = HPDF_Stream_WriteUInt (stream, xref->addr)) != HPDF_OK)
        return ret;

    if ((ret = HPDF_Stream_WriteStr (stream, "\012%%EOF\012")) != HPDF_OK)
        return ret;

    return HPDF_OK;
}
Пример #2
0
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);
}
Пример #3
0
HPDF_STATUS
HPDF_Array_Write  (HPDF_Array    array,
                   HPDF_Stream   stream,
                   HPDF_Encrypt  e)
{
    HPDF_UINT i;
    HPDF_STATUS ret;

    HPDF_PTRACE((" HPDF_Array_Write\n"));

    ret = HPDF_Stream_WriteStr (stream, "[ ");
    if (ret != HPDF_OK)
        return ret;

    for (i = 0; i < array->list->count; i++) {
        void * element = HPDF_List_ItemAt (array->list, i);

        ret = HPDF_Obj_Write (element, stream, e);
        if (ret != HPDF_OK)
            return ret;

        ret = HPDF_Stream_WriteChar (stream, ' ');
        if (ret != HPDF_OK)
            return ret;
    }

    ret = HPDF_Stream_WriteChar (stream, ']');

    return ret;
}
Пример #4
0
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);
}
Пример #5
0
HPDF_STATUS
HPDF_Obj_WriteValue  (void          *obj,
                      HPDF_Stream   stream,
                      HPDF_Encrypt  e)
{
    HPDF_Obj_Header *header;
    HPDF_STATUS ret;

    HPDF_PTRACE((" HPDF_Obj_WriteValue\n"));

    header = (HPDF_Obj_Header *)obj;

    HPDF_PTRACE((" HPDF_Obj_WriteValue obj=0x%08X obj_class=0x%04X\n",
            (HPDF_UINT)obj, (HPDF_UINT)header->obj_class));

    switch (header->obj_class & HPDF_OCLASS_ANY) {
        case HPDF_OCLASS_NAME:
            ret = HPDF_Name_Write (obj, stream);
            break;
        case HPDF_OCLASS_NUMBER:
            ret = HPDF_Number_Write (obj, stream);
            break;
        case HPDF_OCLASS_REAL:
            ret = HPDF_Real_Write (obj, stream);
            break;
        case HPDF_OCLASS_STRING:
            ret = HPDF_String_Write (obj, stream, e);
            break;
        case HPDF_OCLASS_BINARY:
            ret = HPDF_Binary_Write (obj, stream, e);
            break;
        case HPDF_OCLASS_ARRAY:
            ret = HPDF_Array_Write (obj, stream, e);
            break;
        case HPDF_OCLASS_DICT:
            ret = HPDF_Dict_Write (obj, stream, e);
            break;
        case HPDF_OCLASS_BOOLEAN:
            ret = HPDF_Boolean_Write (obj, stream);
            break;
        case HPDF_OCLASS_DIRECT:
            ret = HPDF_Direct_Write (obj, stream);
            break;
        case HPDF_OCLASS_NULL:
            ret = HPDF_Stream_WriteStr (stream, "null");
            break;
        default:
            ret = HPDF_ERR_UNKNOWN_CLASS;
    }

    return ret;
}
Пример #6
0
static HPDF_STATUS
WriteHeader  (HPDF_Doc      pdf,
              HPDF_Stream   stream)
{
    HPDF_UINT idx = (HPDF_INT)pdf->pdf_version;

    HPDF_PTRACE ((" WriteHeader\n"));

    if (HPDF_Stream_WriteStr (stream, HPDF_VERSION_STR[idx]) != HPDF_OK)
        return pdf->error.error_no;

    return HPDF_OK;
}
Пример #7
0
HPDF_STATUS
HPDF_Binary_Write  (HPDF_Binary   obj,
                    HPDF_Stream   stream,
                    HPDF_Encrypt  e)
{
    HPDF_STATUS ret;

    if (obj->len == 0)
        return HPDF_Stream_WriteStr (stream, "<>");

    if ((ret = HPDF_Stream_WriteChar (stream, '<')) != HPDF_OK)
        return ret;

    if (e)
        HPDF_Encrypt_Reset (e);

    if ((ret = HPDF_Stream_WriteBinary (stream, obj->value, obj->len, e)) !=
                    HPDF_OK)
        return ret;

    return HPDF_Stream_WriteChar (stream, '>');
}
Пример #8
0
HPDF_STATUS
HPDF_PDFA_SetPDFAConformance (HPDF_Doc pdf,HPDF_PDFAType pdfatype)
{
    HPDF_OutputIntent xmp;
    HPDF_STATUS ret;
    const char *info = NULL;

    if (!HPDF_HasDoc(pdf)) {
        return HPDF_INVALID_DOCUMENT;
    }

    xmp = HPDF_DictStream_New(pdf->mmgr,pdf->xref);
    if (!xmp) {
        return HPDF_INVALID_STREAM;
    }

    HPDF_Dict_AddName(xmp,"Type","Metadata");
    HPDF_Dict_AddName(xmp,"SubType","XML");

    ret = HPDF_OK;
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_HEADER);

    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_PRODUCER_STARTTAG);

    info = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_PRODUCER);
    ret += HPDF_Stream_WriteStr(xmp->stream, info);
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_PRODUCER_ENDTAG);

    /* Add CreateDate, ModifyDate, and CreatorTool */
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_INFODATA_STARTTAG);
    info = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_CREATION_DATE);
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATE_DATE_STARTTAG);
    /* Convert date to XMP compatible format */
    ret += ConvertDateToXMDate(xmp->stream, info);
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATE_DATE_ENDTAG);

    info = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_MOD_DATE);
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_MOD_DATE_STARTTAG);
    ret += ConvertDateToXMDate(xmp->stream, info);
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_MOD_DATE_ENDTAG);

    info = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_CREATOR);
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATORTOOL_STARTTAG);
    ret += HPDF_Stream_WriteStr(xmp->stream, info);
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATORTOOL_ENDTAG);

    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_INFODATA_ENDTAG);

    switch(pdfatype) {
    case HPDF_PDFA_1A:
        ret += HPDF_Stream_WriteStr(xmp->stream, XMP_PDFA1A);
        break;
    case HPDF_PDFA_1B:
        ret += HPDF_Stream_WriteStr(xmp->stream, XMP_PDFA1B);
        break;
    }
    ret += HPDF_Stream_WriteStr(xmp->stream, XMP_FOOTER);

    if (ret != HPDF_OK) {
        return HPDF_INVALID_STREAM;
    }

    if ((ret = HPDF_Dict_Add(pdf->catalog, "Metadata", xmp)) != HPDF_OK) {
        return ret;
    }

    return HPDF_PDFA_GenerateID(pdf);
}
Пример #9
0
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);
}
Пример #10
0
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;
}
Пример #11
0
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;
}
Пример #12
0
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;
}