* external/libhpdf/Makefile
+ Enabled for all dos platforms (dos/watcom currently and
probably all dos builds done on MS-DOS hosts).
+ external/libhpdf/ori_dst
+ external/libhpdf/ori_src
+ external/libhpdf/cnv_hb2o.bat
+ external/libhpdf/cnv_o2hb.bat
- external/libhpdf/hpdf_annotation.c
- external/libhpdf/hpdf_annotation.h
- external/libhpdf/hpdf_array.c
- external/libhpdf/hpdf_binary.c
- external/libhpdf/hpdf_boolean.c
- external/libhpdf/hpdf_catalog.c
- external/libhpdf/hpdf_catalog.h
- external/libhpdf/hpdf_conf.h
- external/libhpdf/hpdf_config.h
- external/libhpdf/hpdf_consts.h
- external/libhpdf/hpdf_destination.c
- external/libhpdf/hpdf_destination.h
- external/libhpdf/hpdf_dict.c
- external/libhpdf/hpdf_doc.c
- external/libhpdf/hpdf_doc.h
- external/libhpdf/hpdf_doc_png.c
- external/libhpdf/hpdf_encoder.c
- external/libhpdf/hpdf_encoder.h
- external/libhpdf/hpdf_encoder_cns.c
- external/libhpdf/hpdf_encoder_cnt.c
- external/libhpdf/hpdf_encoder_jp.c
- external/libhpdf/hpdf_encoder_kr.c
- external/libhpdf/hpdf_encrypt.c
- external/libhpdf/hpdf_encrypt.h
- external/libhpdf/hpdf_encryptdict.c
- external/libhpdf/hpdf_encryptdict.h
- external/libhpdf/hpdf_error.c
- external/libhpdf/hpdf_error.h
- external/libhpdf/hpdf_ext_gstate.c
- external/libhpdf/hpdf_ext_gstate.h
- external/libhpdf/hpdf_font.c
- external/libhpdf/hpdf_font.h
- external/libhpdf/hpdf_font_cid.c
- external/libhpdf/hpdf_font_tt.c
- external/libhpdf/hpdf_font_type1.c
- external/libhpdf/hpdf_fontdef.c
- external/libhpdf/hpdf_fontdef.h
- external/libhpdf/hpdf_fontdef_base14.c
- external/libhpdf/hpdf_fontdef_cid.c
- external/libhpdf/hpdf_fontdef_cns.c
- external/libhpdf/hpdf_fontdef_cnt.c
- external/libhpdf/hpdf_fontdef_jp.c
- external/libhpdf/hpdf_fontdef_kr.c
- external/libhpdf/hpdf_fontdef_tt.c
- external/libhpdf/hpdf_fontdef_type1.c
- external/libhpdf/hpdf_gstate.c
- external/libhpdf/hpdf_gstate.h
- external/libhpdf/hpdf_image.c
- external/libhpdf/hpdf_image.h
- external/libhpdf/hpdf_image_png.c
- external/libhpdf/hpdf_info.c
- external/libhpdf/hpdf_info.h
- external/libhpdf/hpdf_list.c
- external/libhpdf/hpdf_list.h
- external/libhpdf/hpdf_mmgr.c
- external/libhpdf/hpdf_mmgr.h
- external/libhpdf/hpdf_name.c
- external/libhpdf/hpdf_null.c
- external/libhpdf/hpdf_number.c
- external/libhpdf/hpdf_objects.c
- external/libhpdf/hpdf_objects.h
- external/libhpdf/hpdf_outline.c
- external/libhpdf/hpdf_outline.h
- external/libhpdf/hpdf_page_label.c
- external/libhpdf/hpdf_page_label.h
- external/libhpdf/hpdf_page_operator.c
- external/libhpdf/hpdf_pages.c
- external/libhpdf/hpdf_pages.h
- external/libhpdf/hpdf_real.c
- external/libhpdf/hpdf_streams.c
- external/libhpdf/hpdf_streams.h
- external/libhpdf/hpdf_string.c
- external/libhpdf/hpdf_types.h
- external/libhpdf/hpdf_u3d.c
- external/libhpdf/hpdf_u3d.h
- external/libhpdf/hpdf_utils.c
- external/libhpdf/hpdf_utils.h
- external/libhpdf/hpdf_version.h
- external/libhpdf/hpdf_xref.c
+ external/libhpdf/hpdfanno.c
+ external/libhpdf/hpdfanno.h
+ external/libhpdf/hpdfarra.c
+ external/libhpdf/hpdfbina.c
+ external/libhpdf/hpdfbool.c
+ external/libhpdf/hpdfcata.c
+ external/libhpdf/hpdfcata.h
+ external/libhpdf/hpdfcfg.h
+ external/libhpdf/hpdfconf.h
+ external/libhpdf/hpdfcons.h
+ external/libhpdf/hpdfdest.c
+ external/libhpdf/hpdfdest.h
+ external/libhpdf/hpdfdict.c
+ external/libhpdf/hpdfdoc.c
+ external/libhpdf/hpdfdoc.h
+ external/libhpdf/hpdfdocp.c
+ external/libhpdf/hpdfecy.c
+ external/libhpdf/hpdfecyd.c
+ external/libhpdf/hpdfencc.c
+ external/libhpdf/hpdfencj.c
+ external/libhpdf/hpdfenck.c
+ external/libhpdf/hpdfencn.c
+ external/libhpdf/hpdfenco.c
+ external/libhpdf/hpdfenco.h
+ external/libhpdf/hpdfencr.h
+ external/libhpdf/hpdfency.h
+ external/libhpdf/hpdferro.c
+ external/libhpdf/hpdferro.h
+ external/libhpdf/hpdfextg.c
+ external/libhpdf/hpdfextg.h
+ external/libhpdf/hpdffdf.c
+ external/libhpdf/hpdffdf1.c
+ external/libhpdf/hpdffdfb.c
+ external/libhpdf/hpdffdfc.c
+ external/libhpdf/hpdffdfi.c
+ external/libhpdf/hpdffdfj.c
+ external/libhpdf/hpdffdfk.c
+ external/libhpdf/hpdffdfn.c
+ external/libhpdf/hpdffdft.c
+ external/libhpdf/hpdffon1.c
+ external/libhpdf/hpdffonc.c
+ external/libhpdf/hpdffond.h
+ external/libhpdf/hpdffont.c
+ external/libhpdf/hpdffont.h
+ external/libhpdf/hpdffott.c
+ external/libhpdf/hpdfgsta.c
+ external/libhpdf/hpdfgsta.h
+ external/libhpdf/hpdfimag.c
+ external/libhpdf/hpdfimag.h
+ external/libhpdf/hpdfimap.c
+ external/libhpdf/hpdfinfo.c
+ external/libhpdf/hpdfinfo.h
+ external/libhpdf/hpdflist.c
+ external/libhpdf/hpdflist.h
+ external/libhpdf/hpdfmmgr.c
+ external/libhpdf/hpdfmmgr.h
+ external/libhpdf/hpdfname.c
+ external/libhpdf/hpdfnull.c
+ external/libhpdf/hpdfnumb.c
+ external/libhpdf/hpdfobje.c
+ external/libhpdf/hpdfobje.h
+ external/libhpdf/hpdfoutl.c
+ external/libhpdf/hpdfoutl.h
+ external/libhpdf/hpdfpage.c
+ external/libhpdf/hpdfpage.h
+ external/libhpdf/hpdfpago.c
+ external/libhpdf/hpdfpags.c
+ external/libhpdf/hpdfpags.h
+ external/libhpdf/hpdfreal.c
+ external/libhpdf/hpdfstre.c
+ external/libhpdf/hpdfstre.h
+ external/libhpdf/hpdfstri.c
+ external/libhpdf/hpdftype.h
+ external/libhpdf/hpdfu3d.c
+ external/libhpdf/hpdfu3d.h
+ external/libhpdf/hpdfutil.c
+ external/libhpdf/hpdfutil.h
+ external/libhpdf/hpdfvers.h
+ external/libhpdf/hpdfxref.c
* external/libhpdf/hpdf.h
* external/libhpdf/Makefile
* Converted to short filenames. Added converted scripts.
* source/hbpcre/cnv_hb2o.bat
* source/hbpcre/cnv_o2hb.bat
! Fixed typo in prev.
* Removed PCRE references from comment texts.
193 lines
5.1 KiB
C
193 lines
5.1 KiB
C
/*
|
|
* << Haru Free PDF Library >> -- hpdf_string.c
|
|
*
|
|
* URL: http://libharu.org
|
|
*
|
|
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
|
|
* Copyright (c) 2007-2008 Antony Dovgal <tony@daylessday.org>
|
|
*
|
|
* Permission to use, copy, modify, distribute and sell this software
|
|
* and its documentation for any purpose is hereby granted without fee,
|
|
* provided that the above copyright notice appear in all copies and
|
|
* that both that copyright notice and this permission notice appear
|
|
* in supporting documentation.
|
|
* It is provided "as is" without express or implied warranty.
|
|
*
|
|
*/
|
|
|
|
#include "hpdfconf.h"
|
|
#include "hpdfutil.h"
|
|
#include "hpdfobje.h"
|
|
|
|
static const HPDF_BYTE UNICODE_HEADER[] = {
|
|
0xFE, 0xFF
|
|
};
|
|
|
|
|
|
HPDF_String
|
|
HPDF_String_New (HPDF_MMgr mmgr,
|
|
const char *value,
|
|
HPDF_Encoder encoder)
|
|
{
|
|
HPDF_String obj;
|
|
|
|
HPDF_PTRACE((" HPDF_String_New\n"));
|
|
|
|
obj = (HPDF_String)HPDF_GetMem (mmgr, sizeof(HPDF_String_Rec));
|
|
if (obj) {
|
|
HPDF_MemSet (&obj->header, 0, sizeof(HPDF_Obj_Header));
|
|
obj->header.obj_class = HPDF_OCLASS_STRING;
|
|
|
|
obj->mmgr = mmgr;
|
|
obj->error = mmgr->error;
|
|
obj->encoder = encoder;
|
|
obj->value = NULL;
|
|
obj->len = 0;
|
|
|
|
if (HPDF_String_SetValue (obj, value) != HPDF_OK) {
|
|
HPDF_FreeMem (obj->mmgr, obj);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
|
|
HPDF_STATUS
|
|
HPDF_String_SetValue (HPDF_String obj,
|
|
const char *value)
|
|
{
|
|
HPDF_UINT len;
|
|
HPDF_STATUS ret = HPDF_OK;
|
|
|
|
HPDF_PTRACE((" HPDF_String_SetValue\n"));
|
|
|
|
if (obj->value) {
|
|
HPDF_FreeMem (obj->mmgr, obj->value);
|
|
obj->len = 0;
|
|
}
|
|
|
|
len = HPDF_StrLen(value, HPDF_LIMIT_MAX_STRING_LEN + 1);
|
|
|
|
if (len > HPDF_LIMIT_MAX_STRING_LEN)
|
|
return HPDF_SetError (obj->error, HPDF_STRING_OUT_OF_RANGE, 0);
|
|
|
|
obj->value = HPDF_GetMem (obj->mmgr, len + 1);
|
|
if (!obj->value)
|
|
return HPDF_Error_GetCode (obj->error);
|
|
|
|
HPDF_StrCpy ((char *)obj->value, value, (char *)obj->value + len);
|
|
obj->len = len;
|
|
|
|
return ret;
|
|
}
|
|
|
|
void
|
|
HPDF_String_Free (HPDF_String obj)
|
|
{
|
|
if (!obj)
|
|
return;
|
|
|
|
HPDF_PTRACE((" HPDF_String_Free\n"));
|
|
|
|
HPDF_FreeMem (obj->mmgr, obj->value);
|
|
HPDF_FreeMem (obj->mmgr, obj);
|
|
}
|
|
|
|
|
|
HPDF_STATUS
|
|
HPDF_String_Write (HPDF_String obj,
|
|
HPDF_Stream stream,
|
|
HPDF_Encrypt e)
|
|
{
|
|
HPDF_STATUS ret;
|
|
|
|
/*
|
|
* When encoder is not NULL, text is changed to unicode using encoder,
|
|
* and it outputs by HPDF_write_binary method.
|
|
*/
|
|
|
|
HPDF_PTRACE((" HPDF_String_Write\n"));
|
|
|
|
if (e)
|
|
HPDF_Encrypt_Reset (e);
|
|
|
|
if (obj->encoder == NULL) {
|
|
if (e) {
|
|
if ((ret = HPDF_Stream_WriteChar (stream, '<')) != HPDF_OK)
|
|
return ret;
|
|
|
|
if ((ret = HPDF_Stream_WriteBinary (stream, obj->value,
|
|
HPDF_StrLen ((char *)obj->value, -1), e)) != HPDF_OK)
|
|
return ret;
|
|
|
|
return HPDF_Stream_WriteChar (stream, '>');
|
|
} else {
|
|
return HPDF_Stream_WriteEscapeText (stream, (char *)obj->value);
|
|
}
|
|
} else {
|
|
HPDF_BYTE* src = obj->value;
|
|
HPDF_BYTE buf[HPDF_TEXT_DEFAULT_LEN * 2];
|
|
HPDF_UINT tmp_len = 0;
|
|
HPDF_BYTE* pbuf = buf;
|
|
HPDF_INT32 len = obj->len;
|
|
HPDF_ParseText_Rec parse_state;
|
|
HPDF_UINT i;
|
|
|
|
if ((ret = HPDF_Stream_WriteChar (stream, '<')) != HPDF_OK)
|
|
return ret;
|
|
|
|
if ((ret = HPDF_Stream_WriteBinary (stream, UNICODE_HEADER, 2, e))
|
|
!= HPDF_OK)
|
|
return ret;
|
|
|
|
HPDF_Encoder_SetParseText (obj->encoder, &parse_state, src, len);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
HPDF_BYTE b = src[i];
|
|
HPDF_UNICODE tmp_unicode;
|
|
HPDF_ByteType btype = HPDF_Encoder_ByteType (obj->encoder,
|
|
&parse_state);
|
|
|
|
if (tmp_len >= HPDF_TEXT_DEFAULT_LEN - 1) {
|
|
if ((ret = HPDF_Stream_WriteBinary (stream, buf,
|
|
tmp_len * 2, e)) != HPDF_OK)
|
|
return ret;
|
|
|
|
tmp_len = 0;
|
|
pbuf = buf;
|
|
}
|
|
|
|
if (btype != HPDF_BYTE_TYPE_TRIAL) {
|
|
if (btype == HPDF_BYTE_TYPE_LEAD) {
|
|
HPDF_BYTE b2 = src[i + 1];
|
|
HPDF_UINT16 char_code = (HPDF_UINT) b * 256 + b2;
|
|
|
|
tmp_unicode = HPDF_Encoder_ToUnicode (obj->encoder,
|
|
char_code);
|
|
} else {
|
|
tmp_unicode = HPDF_Encoder_ToUnicode (obj->encoder, b);
|
|
}
|
|
|
|
HPDF_UInt16Swap (&tmp_unicode);
|
|
HPDF_MemCpy (pbuf, (HPDF_BYTE*)&tmp_unicode, 2);
|
|
pbuf += 2;
|
|
tmp_len++;
|
|
}
|
|
}
|
|
|
|
if (tmp_len > 0) {
|
|
if ((ret = HPDF_Stream_WriteBinary (stream, buf, tmp_len * 2, e))
|
|
!= HPDF_OK)
|
|
return ret;
|
|
}
|
|
|
|
if ((ret = HPDF_Stream_WriteChar (stream, '>')) != HPDF_OK)
|
|
return ret;
|
|
}
|
|
|
|
return HPDF_OK;
|
|
}
|
|
|