upgrade libHaru to 2.3.0; make UTF-8 encoding default; some internal modifications and fixes

This commit is contained in:
Alex Fabijanic
2017-11-21 20:42:14 -06:00
parent 1724e8ba53
commit e067b19903
100 changed files with 8241 additions and 1179 deletions

View File

@@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_string.h
* << 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,
@@ -12,6 +15,7 @@
*
*/
#include <string.h>
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf_objects.h"
@@ -70,11 +74,11 @@ HPDF_String_SetValue (HPDF_String obj,
if (len > HPDF_LIMIT_MAX_STRING_LEN)
return HPDF_SetError (obj->error, HPDF_STRING_OUT_OF_RANGE, 0);
obj->value = (char *)HPDF_GetMem (obj->mmgr, len + 1);
obj->value = HPDF_GetMem (obj->mmgr, len + 1);
if (!obj->value)
return HPDF_Error_GetCode (obj->error);
HPDF_StrCpy (obj->value, value, obj->value + len);
HPDF_StrCpy ((char *)obj->value, value, (char *)obj->value + len);
obj->len = len;
return ret;
@@ -116,12 +120,12 @@ HPDF_String_Write (HPDF_String obj,
return ret;
if ((ret = HPDF_Stream_WriteBinary (stream, obj->value,
HPDF_StrLen (obj->value, -1), e)) != HPDF_OK)
HPDF_StrLen ((char *)obj->value, -1), e)) != HPDF_OK)
return ret;
return HPDF_Stream_WriteChar (stream, '>');
} else {
return HPDF_Stream_WriteEscapeText (stream, obj->value);
return HPDF_Stream_WriteEscapeText (stream, (char *)obj->value);
}
} else {
HPDF_BYTE* src = obj->value;
@@ -141,7 +145,7 @@ HPDF_String_Write (HPDF_String obj,
HPDF_Encoder_SetParseText (obj->encoder, &parse_state, src, len);
for (i = 0; i < len; i++) {
for (i = 0; (HPDF_INT32)i < len; i++) {
HPDF_BYTE b = src[i];
HPDF_UNICODE tmp_unicode;
HPDF_ByteType btype = HPDF_Encoder_ByteType (obj->encoder,
@@ -159,7 +163,7 @@ HPDF_String_Write (HPDF_String obj,
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;
HPDF_UINT16 char_code = (HPDF_UINT16)((HPDF_UINT) b * 256 + b2);
tmp_unicode = HPDF_Encoder_ToUnicode (obj->encoder,
char_code);
@@ -187,3 +191,12 @@ HPDF_String_Write (HPDF_String obj,
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);
}