Răsfoiți Sursa

Updated libharu to v2.4.4 (#25)

Carl Husberg 1 an în urmă
părinte
comite
8c4cd2811d

+ 1 - 0
pdf.mod/libharu/CMakeLists.txt

@@ -121,6 +121,7 @@ set(
     include/hpdf_info.h
     include/hpdf_list.h
     include/hpdf_mmgr.h
+    include/hpdf_namedict.h
     include/hpdf_objects.h
     include/hpdf_outline.h
     include/hpdf_pages.h

BIN
pdf.mod/libharu/demo/text_annotation.pdf


+ 13 - 0
pdf.mod/libharu/include/.gitignore

@@ -0,0 +1,13 @@
+hpdf_config.h.in*
+hpdf_config.h
+config.h.in*
+config.h
+Makefile.in
+stamp-h1
+Makefile
+*.lo
+*.la
+.deps
+.libs
+*.o
+*.a

+ 1 - 1
pdf.mod/libharu/include/hpdf_version.h

@@ -1,6 +1,6 @@
 #define HPDF_MAJOR_VERSION 2
 #define HPDF_MINOR_VERSION 4
-#define HPDF_BUGFIX_VERSION 3
+#define HPDF_BUGFIX_VERSION 4
 #define HPDF_EXTRA_VERSION ""
 
 #define hpdf_vquote(x) #x

+ 65 - 60
pdf.mod/libharu/src/CMakeLists.txt

@@ -7,72 +7,77 @@
 # libhpdf source files
 # =======================================================================
 set(
-  LIBHPDF_SRCS
-  	hpdf_annotation.c
-  	hpdf_array.c
-  	hpdf_binary.c
-  	hpdf_boolean.c
-  	hpdf_catalog.c
-  	hpdf_destination.c
-  	hpdf_dict.c
-  	hpdf_direct.c
-  	hpdf_doc_png.c
-  	hpdf_doc.c
-  	hpdf_encoder_cns.c
-  	hpdf_encoder_cnt.c
-  	hpdf_encoder_jp.c
-  	hpdf_encoder_kr.c
-  	hpdf_encoder.c
-  	hpdf_encrypt.c
-  	hpdf_encryptdict.c
-  	hpdf_error.c
-  	hpdf_ext_gstate.c
-  	hpdf_font_cid.c
-  	hpdf_font_tt.c
-  	hpdf_font_type1.c
-  	hpdf_font.c
-  	hpdf_fontdef_base14.c
-  	hpdf_fontdef_cid.c
-  	hpdf_fontdef_cns.c
-  	hpdf_fontdef_cnt.c
-  	hpdf_fontdef_jp.c
-  	hpdf_fontdef_kr.c
-  	hpdf_fontdef_tt.c
-  	hpdf_fontdef_type1.c
-  	hpdf_fontdef.c
-  	hpdf_gstate.c
-	hpdf_image_ccitt.c
-  	hpdf_image_png.c
-  	hpdf_image.c
-  	hpdf_info.c
-  	hpdf_list.c
-  	hpdf_mmgr.c
-  	hpdf_name.c
-  	hpdf_namedict.c
-  	hpdf_null.c
-  	hpdf_number.c
-  	hpdf_objects.c
-  	hpdf_outline.c
-  	hpdf_page_label.c
-  	hpdf_page_operator.c
-  	hpdf_pages.c
-  	hpdf_real.c
-  	hpdf_shading.c
-  	hpdf_streams.c
-  	hpdf_string.c
-  	hpdf_u3d.c
-  	hpdf_utils.c
-  	hpdf_xref.c
-  	hpdf_pdfa.c
-	hpdf_3dmeasure.c
-	hpdf_exdata.c
-	hpdf_encoder_utf.c
+    LIBHPDF_SRCS
+    hpdf_annotation.c
+    hpdf_array.c
+    hpdf_binary.c
+    hpdf_boolean.c
+    hpdf_catalog.c
+    hpdf_destination.c
+    hpdf_dict.c
+    hpdf_direct.c
+    hpdf_doc_png.c
+    hpdf_doc.c
+    hpdf_encoder_cns.c
+    hpdf_encoder_cnt.c
+    hpdf_encoder_jp.c
+    hpdf_encoder_kr.c
+    hpdf_encoder_utf.c
+    hpdf_encoder.c
+    hpdf_encrypt.c
+    hpdf_encryptdict.c
+    hpdf_error.c
+    hpdf_ext_gstate.c
+    hpdf_font_cid.c
+    hpdf_font_tt.c
+    hpdf_font_type1.c
+    hpdf_font.c
+    hpdf_fontdef_base14.c
+    hpdf_fontdef_cid.c
+    hpdf_fontdef_cns.c
+    hpdf_fontdef_cnt.c
+    hpdf_fontdef_jp.c
+    hpdf_fontdef_kr.c
+    hpdf_fontdef_tt.c
+    hpdf_fontdef_type1.c
+    hpdf_fontdef.c
+    hpdf_gstate.c
+    hpdf_image_ccitt.c
+    hpdf_image_png.c
+    hpdf_image.c
+    hpdf_info.c
+    hpdf_list.c
+    hpdf_mmgr.c
+    hpdf_name.c
+    hpdf_namedict.c
+    hpdf_null.c
+    hpdf_number.c
+    hpdf_objects.c
+    hpdf_outline.c
+    hpdf_page_label.c
+    hpdf_page_operator.c
+    hpdf_pages.c
+    hpdf_real.c
+    hpdf_shading.c
+    hpdf_streams.c
+    hpdf_string.c
+    hpdf_u3d.c
+    hpdf_utils.c
+    hpdf_xref.c
+    hpdf_pdfa.c
+    hpdf_3dmeasure.c
+    hpdf_exdata.c
+    hpdf_encoder_utf.c
 )
 
 # =======================================================================
 # create hpdf library
 # =======================================================================
 add_library(hpdf ${LIBHPDF_SRCS})
+set_target_properties(hpdf PROPERTIES
+    SOVERSION ${HPDF_MAJOR_VERSION}.${HPDF_MINOR_VERSION}
+    VERSION ${HPDF_MAJOR_VERSION}.${HPDF_MINOR_VERSION}.${HPDF_BUGFIX_VERSION}
+)
 if (PNG_FOUND)
     include_directories (${PNG_INCLUDE_DIRS})
     target_link_libraries (hpdf ${PNG_LIBRARIES})

+ 2 - 2
pdf.mod/libharu/src/hpdf_3dmeasure.c

@@ -125,7 +125,7 @@ HPDF_3DMeasure_SetName(HPDF_3DMeasure measure,
 
 	s = HPDF_String_New (measure->mmgr, name, 0);
 	if (!s)
-		return HPDF_Error_GetCode ( s->error);
+		return HPDF_Error_GetCode ( measure->error);
 
 	ret = HPDF_Dict_Add(measure, "TRL", s);
 
@@ -164,7 +164,7 @@ HPDF_3DC3DMeasure_SetText(HPDF_3DMeasure measure,
 
 	s = HPDF_String_New (measure->mmgr, text, encoder);
 	if (!s)
-		return HPDF_Error_GetCode ( s->error);
+		return HPDF_Error_GetCode ( measure->error);
 
 	ret = HPDF_Dict_Add(measure, "UT", s);
 

+ 3 - 1
pdf.mod/libharu/src/hpdf_dict.c

@@ -347,8 +347,10 @@ HPDF_Dict_Add  (HPDF_Dict        dict,
     if (header->obj_id & HPDF_OTYPE_INDIRECT) {
         HPDF_Proxy proxy = HPDF_Proxy_New (dict->mmgr, obj);
 
-        if (!proxy)
+        if (!proxy) {
+            HPDF_Obj_Free(dict->mmgr, obj);
             return HPDF_Error_GetCode (dict->error);
+        }
 
         element->value = proxy;
         proxy->header.obj_id |= HPDF_OTYPE_DIRECT;

+ 2 - 2
pdf.mod/libharu/src/hpdf_fontdef_jp.c

@@ -1685,7 +1685,7 @@ MS_Mincho_Init  (HPDF_FontDef   fontdef)
                 HPDF_FONT_SERIF;
     fontdef->italic_angle = 0;
     fontdef->stemv = 78;
-    if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, MS_Gothic_W_ARRAY)) !=
+    if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, MS_Mincho_W_ARRAY)) !=
                 HPDF_OK) {
         return ret;
     }
@@ -1746,7 +1746,7 @@ MS_PMincho_Init  (HPDF_FontDef   fontdef)
     fontdef->flags = HPDF_FONT_SYMBOLIC + HPDF_FONT_SERIF;
     fontdef->italic_angle = 0;
     fontdef->stemv = 78;
-    if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, MS_PGothic_W_ARRAY)) !=
+    if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, MS_PMincho_W_ARRAY)) !=
                 HPDF_OK) {
         return ret;
     }

+ 2 - 2
pdf.mod/libharu/src/hpdf_fontdef_kr.c

@@ -1353,7 +1353,7 @@ BatangChe_Init  (HPDF_FontDef   fontdef)
                 HPDF_FONT_SERIF;
     fontdef->italic_angle = 0;
     fontdef->stemv = 78;
-    if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, DotumChe_W_ARRAY)) !=
+    if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, BatangChe_W_ARRAY)) !=
                 HPDF_OK) {
         return ret;
     }
@@ -1414,7 +1414,7 @@ Batang_Init  (HPDF_FontDef   fontdef)
     fontdef->flags = HPDF_FONT_SYMBOLIC + HPDF_FONT_SERIF;
     fontdef->italic_angle = 0;
     fontdef->stemv = 78;
-    if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, Dotum_W_ARRAY)) !=
+    if ((ret = HPDF_CIDFontDef_AddWidth (fontdef, Batang_W_ARRAY)) !=
                 HPDF_OK) {
         return ret;
     }

+ 3 - 3
pdf.mod/libharu/src/hpdf_fontdef_tt.c

@@ -1241,7 +1241,7 @@ CheckCompositGryph  (HPDF_FontDef   fontdef,
     } else {
         HPDF_INT16 num_of_contours;
         HPDF_INT16 flags;
-        HPDF_INT16 glyph_index;
+        HPDF_UINT16 glyph_index;
         const HPDF_UINT16 ARG_1_AND_2_ARE_WORDS = 1;
         const HPDF_UINT16 WE_HAVE_A_SCALE  = 8;
         const HPDF_UINT16 MORE_COMPONENTS = 32;
@@ -1264,7 +1264,7 @@ CheckCompositGryph  (HPDF_FontDef   fontdef,
             if ((ret = GetINT16 (attr->stream, &flags)) != HPDF_OK)
                 return ret;
 
-            if ((ret = GetINT16 (attr->stream, &glyph_index)) != HPDF_OK)
+            if ((ret = GetUINT16 (attr->stream, &glyph_index)) != HPDF_OK)
                 return ret;
 
             if (flags & ARG_1_AND_2_ARE_WORDS) {
@@ -1291,7 +1291,7 @@ CheckCompositGryph  (HPDF_FontDef   fontdef,
                     return ret;
             }
 
-            if (glyph_index > 0 && glyph_index < attr->num_glyphs &&
+            if (glyph_index < attr->num_glyphs &&
                     !attr->glyph_tbl.flgs[glyph_index]) {
                 HPDF_INT32 next_glyph;
 

+ 15 - 17
pdf.mod/libharu/src/hpdf_fontdef_type1.c

@@ -181,30 +181,30 @@ LoadAfm (HPDF_FontDef  fontdef,
         } else
 
         if (HPDF_StrCmp (keyword, "CharacterSet") == 0) {
-            HPDF_UINT len = HPDF_StrLen (s, HPDF_LIMIT_MAX_STRING_LEN);
+            HPDF_UINT len1 = HPDF_StrLen (s, HPDF_LIMIT_MAX_STRING_LEN);
 
-            if (len > 0) {
-                attr->char_set = HPDF_GetMem (fontdef->mmgr, len + 1);
+            if (len1 > 0) {
+                attr->char_set = HPDF_GetMem (fontdef->mmgr, len1 + 1);
                 if (!attr->char_set)
                     return HPDF_Error_GetCode (fontdef->error);
 
-                HPDF_StrCpy (attr->char_set, s, attr->char_set + len);
+                HPDF_StrCpy (attr->char_set, s, attr->char_set + len1);
             }
         } else
         if (HPDF_StrCmp (keyword, "FontBBox") == 0) {
-            char buf[HPDF_INT_LEN + 1];
+            char buf1[HPDF_INT_LEN + 1];
 
-            s = GetKeyword (s, buf, HPDF_INT_LEN + 1);
-            fontdef->font_bbox.left = (HPDF_REAL)HPDF_AToI (buf);
+            s = GetKeyword (s, buf1, HPDF_INT_LEN + 1);
+            fontdef->font_bbox.left = (HPDF_REAL)HPDF_AToI (buf1);
 
-            s = GetKeyword (s, buf, HPDF_INT_LEN + 1);
-            fontdef->font_bbox.bottom = (HPDF_REAL)HPDF_AToI (buf);
+            s = GetKeyword (s, buf1, HPDF_INT_LEN + 1);
+            fontdef->font_bbox.bottom = (HPDF_REAL)HPDF_AToI (buf1);
 
-            s = GetKeyword (s, buf, HPDF_INT_LEN + 1);
-            fontdef->font_bbox.right = (HPDF_REAL)HPDF_AToI (buf);
+            s = GetKeyword (s, buf1, HPDF_INT_LEN + 1);
+            fontdef->font_bbox.right = (HPDF_REAL)HPDF_AToI (buf1);
 
-            GetKeyword (s, buf, HPDF_INT_LEN + 1);
-            fontdef->font_bbox.top = (HPDF_REAL)HPDF_AToI (buf);
+            GetKeyword (s, buf1, HPDF_INT_LEN + 1);
+            fontdef->font_bbox.top = (HPDF_REAL)HPDF_AToI (buf1);
         } else
         if (HPDF_StrCmp (keyword, "EncodingScheme") == 0) {
             HPDF_StrCpy (attr->encoding_scheme, s,
@@ -242,7 +242,7 @@ LoadAfm (HPDF_FontDef  fontdef,
     /* load CharMetrics */
     for (i = 0; i < attr->widths_count; i++, cdata++) {
         const char *s;
-        char buf2[HPDF_LIMIT_MAX_NAME_LEN + 1];
+        char buf2[HPDF_LIMIT_MAX_NAME_LEN + 1] = { 0 };
 
         len = HPDF_TMP_BUF_SIZ;
         if ((ret = HPDF_Stream_ReadLn (stream, buf, &len)) != HPDF_OK)
@@ -259,8 +259,6 @@ LoadAfm (HPDF_FontDef  fontdef,
             s += 2;
 
             s = GetKeyword (s, buf2, HPDF_LIMIT_MAX_NAME_LEN + 1);
-              HPDF_AToI (buf2);
-
             cdata->char_cd = (HPDF_INT16)HPDF_AToI (buf2);
 
         } else
@@ -343,7 +341,7 @@ LoadFontData (HPDF_FontDef  fontdef,
                         len + 11);
 
                 if (s2)
-                    attr->length2 = attr->font_data->size + - 520 -
+                    attr->length2 = attr->font_data->size - 520 -
                         attr->length1 + (s2 - buf);
                 /*  length1 indicate the size of binary-data.
                  *  in most fonts, it is all right at 520 bytes . but it need

+ 7 - 3
pdf.mod/libharu/src/hpdf_page_operator.c

@@ -441,13 +441,17 @@ HPDF_Page_Concat  (HPDF_Page         page,
         return HPDF_CheckError (page->error);
 
     tm = attr->gstate->trans_matrix;
-
+    /*
+    | ta tb 0 |   | a b |   | ta*a+tb*c   ta*b+tb*d   |
+    | tc td 0 | x | c d | = | tc*a+td*c   tc*b+td*d   |
+    | tx ty 1 |   | x y |   | tx*a+ty*c+x tx*b+ty*d+y |
+    */
     attr->gstate->trans_matrix.a = tm.a * a + tm.b * c;
     attr->gstate->trans_matrix.b = tm.a * b + tm.b * d;
     attr->gstate->trans_matrix.c = tm.c * a + tm.d * c;
     attr->gstate->trans_matrix.d = tm.c * b + tm.d * d;
-    attr->gstate->trans_matrix.x = tm.x + x * tm.a + y * tm.c;
-    attr->gstate->trans_matrix.y = tm.y + x * tm.b + y * tm.d;
+    attr->gstate->trans_matrix.x = tm.x * a + tm.y * c + x;
+    attr->gstate->trans_matrix.y = tm.x * b + tm.y * d + y;
 
     return ret;
 }

+ 1 - 1
pdf.mod/libharu/src/hpdf_pdfa.c

@@ -181,7 +181,7 @@ HPDF_PDFA_SetPDFAConformance (HPDF_Doc pdf,HPDF_PDFAType pdfatype)
         pdf->pdf_version = HPDF_VER_14;
 
         HPDF_Dict_AddName(xmp,"Type","Metadata");
-        HPDF_Dict_AddName(xmp,"SubType","XML");
+        HPDF_Dict_AddName(xmp,"Subtype","XML");
 
         ret = HPDF_OK;
         ret += HPDF_Stream_WriteStr(xmp->stream, HEADER);

+ 28 - 37
pdf.mod/libharu/src/hpdf_utils.c

@@ -183,16 +183,14 @@ HPDF_FToA  (char       *s,
             HPDF_REAL   val,
             char       *eptr)
 {
-    HPDF_INT32 int_val;
-    HPDF_INT32 fpart_val;
+    HPDF_REAL int_val;
+    HPDF_REAL fpart_val;
+    HPDF_REAL dig;
     char buf[HPDF_REAL_LEN + 1];
     char* sptr = s;
     char* t;
-    HPDF_UINT32 i;
-    HPDF_UINT32 prec;
     HPDF_INT32 logVal;
-    HPDF_REAL roundInc;
-    HPDF_INT64 fShift;
+    HPDF_UINT32 prec;
 
     if (val > HPDF_LIMIT_MAX_REAL)
         val = HPDF_LIMIT_MAX_REAL;
@@ -200,15 +198,15 @@ HPDF_FToA  (char       *s,
     if (val < HPDF_LIMIT_MIN_REAL)
         val = HPDF_LIMIT_MIN_REAL;
 
-    t = buf + HPDF_REAL_LEN;
-    *t-- = 0;
+    t = buf;
+    *t++ = 0;
 
     if (val < 0) {
         *s++ = '-';
         val = -val;
     }
 
-    /* Compute the decimal precision to write at least 5 significant figures */
+    /* compute the decimal precision to write at least 5 significant figures */
     logVal = (HPDF_INT32)(val > 1e-20 ? log10(val) : 0.);
     if (logVal >= 0) {
         prec = 5;
@@ -217,38 +215,31 @@ HPDF_FToA  (char       *s,
         prec = -logVal + 5;
     }
 
-    roundInc = 0.5 * (1. / pow((HPDF_REAL)10, (HPDF_REAL)prec));
-    fShift = (HPDF_INT64)pow((HPDF_REAL)10, (HPDF_REAL)prec);
-
-    /* separate an integer part and a decimal part. */
-    int_val = (HPDF_INT64)(val + roundInc);
-    fpart_val = (HPDF_INT64)((HPDF_REAL)(val - int_val + roundInc) * fShift);
-
-    /* process decimal part */
-    for (i = 0; i < prec; i++) {
-        *t = (char)((char)(fpart_val % 10) + '0');
-        fpart_val /= 10;
-        t--;
-    }
+    /* separate an integer part and a fractional part. */
+    fpart_val = modff(val, &int_val);
 
     /* process integer part */
-    *t-- = '.';
-    *t = '0';
-    if (int_val == 0)
-        t--;
-
-    while (int_val > 0) {
-        *t = (char)((char)(int_val % 10) + '0');
-        int_val /= 10;
-        t--;
-    }
+    do {
+        dig = modff(int_val/10.0, &int_val);
+        *t++ = (char)(dig*10.0 + 0.5) + '0';
+    } while (int_val > 0);
 
-    t++;
+    /* copy to destination buffer */
+    t--;
     while (s <= eptr && *t != 0)
-        *s++ = *t++;
-    s--;
-
-    /* delete an excessive decimal portion. */
+        *s++ = *t--;
+
+   /* process fractional part */
+   *s++ = '.';
+   if(fpart_val != 0.0) {
+       for (HPDF_UINT32 i = 0; i < prec; i++) {
+          fpart_val = modff(fpart_val*10.0, &int_val);
+          *s++ = (char)(int_val + 0.5) + '0';
+       }
+   }
+
+   /* delete an excessive decimal portion. */
+   s--;
     while (s > sptr) {
         if (*s == '0')
             *s = 0;

+ 6 - 1
pdf.mod/libharu/src/hpdf_xref.c

@@ -317,9 +317,14 @@ static HPDF_STATUS
 WriteTrailer  (HPDF_Xref     xref,
                HPDF_Stream   stream)
 {
-    HPDF_UINT max_obj_id = xref->entries->count + xref->start_offset;
+    HPDF_UINT max_obj_id;
     HPDF_STATUS ret;
 
+    if (!xref)
+        return HPDF_INVALID_OBJECT;
+
+    max_obj_id = xref->entries->count + xref->start_offset;
+
     HPDF_PTRACE ((" WriteTrailer\n"));
 
     if ((ret = HPDF_Dict_AddNumber (xref->trailer, "Size", max_obj_id))