* contrib/hbtip/encqp.prg
* QP decoder will now accept LF EOLs (to work well with
non-compliant mailers).
* external/libhpdf/hpdfpags.h
* external/libhpdf/hpdffdfb.c
* external/libhpdf/hpdfxref.c
* external/libhpdf/hpdfcons.h
* external/libhpdf/hpdfextg.c
* external/libhpdf/hpdfencc.c
* external/libhpdf/hpdffdfj.c
+ external/libhpdf/hpdfpdfa.c
* external/libhpdf/hpdfextg.h
* external/libhpdf/hpdfstre.c
* external/libhpdf/hpdffdfn.c
+ external/libhpdf/hpdfpdfa.h
* external/libhpdf/hpdffdf1.c
* external/libhpdf/hpdfenck.c
* external/libhpdf/hpdfstri.c
* external/libhpdf/hpdfstre.h
* external/libhpdf/hpdffdft.c
* external/libhpdf/hpdfoutl.c
* external/libhpdf/hpdfenco.c
* external/libhpdf/hpdfecyd.c
* external/libhpdf/hpdfimap.c
* external/libhpdf/hpdfoutl.h
* external/libhpdf/hpdfenco.h
* external/libhpdf/Makefile
* external/libhpdf/hpdffond.h
* external/libhpdf/hpdfency.h
* external/libhpdf/hpdffon1.c
* external/libhpdf/hpdffont.c
* external/libhpdf/hpdfcata.c
* external/libhpdf/hpdffont.h
* external/libhpdf/hpdfutil.c
* external/libhpdf/hpdfcata.h
* external/libhpdf/hpdfutil.h
* external/libhpdf/hpdfdict.c
* external/libhpdf/hpdfreal.c
* external/libhpdf/hpdfarra.c
* external/libhpdf/hpdfdocp.c
* external/libhpdf/libhpdf.dif
* external/libhpdf/hpdfconf.h
* external/libhpdf/hpdfinfo.c
* external/libhpdf/hpdfanno.c
* external/libhpdf/hpdfgsta.c
* external/libhpdf/hpdfdest.c
* external/libhpdf/hpdfinfo.h
* external/libhpdf/hpdfanno.h
* external/libhpdf/hpdfnumb.c
* external/libhpdf/hpdffdfc.c
* external/libhpdf/hpdfgsta.h
* external/libhpdf/hpdfdest.h
* external/libhpdf/hpdfdoc.c
* external/libhpdf/hpdferro.c
* external/libhpdf/hpdffdfi.c
* external/libhpdf/hpdfbina.c
* external/libhpdf/hpdfdoc.h
* external/libhpdf/hpdffdfk.c
* external/libhpdf/hpdflist.c
* external/libhpdf/hpdferro.h
* external/libhpdf/hpdfimag.c
* external/libhpdf/hpdfencj.c
* external/libhpdf/hpdflist.h
* external/libhpdf/hpdfecy.c
* external/libhpdf/hpdfimag.h
* external/libhpdf/hpdfencn.c
* external/libhpdf/hpdffonc.c
* external/libhpdf/hpdfu3d.c
* external/libhpdf/hpdfencr.h
* external/libhpdf/hpdffdf.c
* external/libhpdf/hpdfu3d.h
* external/libhpdf/hpdfmmgr.c
* external/libhpdf/hpdfmmgr.h
* external/libhpdf/hpdfnull.c
* external/libhpdf/README
* external/libhpdf/hpdffott.c
* external/libhpdf/hpdfpage.c
+ external/libhpdf/hpdfndic.c
* external/libhpdf/hpdfobje.c
* external/libhpdf/hpdfname.c
* external/libhpdf/hpdfpage.h
+ external/libhpdf/hpdfndic.h
* external/libhpdf/hpdf.h
* external/libhpdf/hpdfobje.h
* external/libhpdf/hpdfvers.h
* external/libhpdf/hpdfpago.c
* external/libhpdf/hpdftype.h
* external/libhpdf/hpdfpags.c
* external/libhpdf/hpdfbool.c
+ libharu updated to official 2.2.0 release (from 2.1.0).
Patch sent by Tamas Tevesz.
* Added new files to Makefile.
203 lines
5.3 KiB
C
203 lines
5.3 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-2009 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 <string.h>
|
|
#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;
|
|
}
|
|
|
|
|
|
HPDF_INT32
|
|
HPDF_String_Cmp (HPDF_String s1,
|
|
HPDF_String s2)
|
|
{
|
|
if (s1->len < s2->len) return -1;
|
|
if (s1->len > s2->len) return +1;
|
|
return memcmp(s1->value, s2->value, s1->len);
|
|
}
|