diff --git a/PDF/CMakeLists.txt b/PDF/CMakeLists.txt index 876dd0986..3ecb9574a 100644 --- a/PDF/CMakeLists.txt +++ b/PDF/CMakeLists.txt @@ -136,9 +136,7 @@ POCO_INSTALL("${LIBNAME}") POCO_GENERATE_PACKAGE("${LIBNAME}") if (ENABLE_TESTS) + add_subdirectory(samples) add_subdirectory(testsuite) endif () -if (ENABLE_SAMPLES) - add_subdirectory(samples) -endif () diff --git a/PDF/Makefile b/PDF/Makefile index 24f5796be..250d01310 100644 --- a/PDF/Makefile +++ b/PDF/Makefile @@ -10,17 +10,17 @@ INCLUDE += -I $(POCO_BASE)/PDF/include/Poco/PDF objects = Destination Document Encoder Font Image Outline \ LinkAnnotation Page PDFException TextAnnotation \ - hpdf_annotation hpdf_array hpdf_binary hpdf_boolean \ + hpdf_3dmeasure hpdf_annotation hpdf_array hpdf_binary hpdf_boolean \ hpdf_catalog hpdf_destination hpdf_dict hpdf_doc hpdf_doc_png \ hpdf_encoder hpdf_encoder_cns hpdf_encoder_cnt hpdf_encoder_jp \ - hpdf_encoder_kr hpdf_encrypt hpdf_encryptdict hpdf_error \ - hpdf_ext_gstate hpdf_font hpdf_font_cid hpdf_font_tt \ + hpdf_encoder_kr hpdf_encoder_utf hpdf_encrypt hpdf_encryptdict hpdf_error \ + hpdf_exdata hpdf_ext_gstate hpdf_font hpdf_font_cid hpdf_font_tt \ hpdf_font_type1 hpdf_fontdef hpdf_fontdef_base14 hpdf_fontdef_cid \ hpdf_fontdef_cns hpdf_fontdef_cnt hpdf_fontdef_jp hpdf_fontdef_kr \ - hpdf_fontdef_tt hpdf_fontdef_type1 hpdf_gstate hpdf_image \ - hpdf_image_png hpdf_info hpdf_list hpdf_mmgr hpdf_name hpdf_null \ + hpdf_fontdef_tt hpdf_fontdef_type1 hpdf_gstate hpdf_image hpdf_image_ccitt \ + hpdf_image_png hpdf_info hpdf_list hpdf_mmgr hpdf_name hpdf_namedict hpdf_null \ hpdf_number hpdf_objects hpdf_outline hpdf_page_label hpdf_page_operator \ - hpdf_pages hpdf_real hpdf_streams hpdf_string hpdf_utils hpdf_xref \ + hpdf_pages hpdf_pdfa hpdf_real hpdf_streams hpdf_string hpdf_u3d hpdf_utils hpdf_xref \ adler32 compress crc32 deflate gzio \ infback inffast inflate inftrees trees zutil \ png pngerror pnggccrd pngget pngmem pngpread \ diff --git a/PDF/PDF.progen b/PDF/PDF.progen deleted file mode 100644 index 6c71e3a49..000000000 --- a/PDF/PDF.progen +++ /dev/null @@ -1,16 +0,0 @@ -vc.project.guid = E12E5C71-79A4-495A-848F-F1710111E610 -vc.project.name = PDF -vc.project.target = Poco${vc.project.name} -vc.project.type = library -vc.project.pocobase = .. -vc.project.outdir = ${vc.project.pocobase} -vc.project.platforms = Win32, x64 -vc.project.configurations = debug_shared, release_shared, debug_static_mt, release_static_mt, debug_static_md, release_static_md -vc.project.prototype = ${vc.project.name}_vs90.vcproj -vc.project.compiler.include = .\\include\\Poco\\PDF;..\\Foundation\\include -vc.project.compiler.defines = -vc.project.compiler.defines.shared = _CRT_SECURE_NO_WARNINGS;${vc.project.name}_EXPORTS -vc.project.compiler.defines.debug_shared = ${vc.project.compiler.defines.shared} -vc.project.compiler.defines.release_shared = ${vc.project.compiler.defines.shared} -vc.solution.create = true -vc.solution.include = testsuite\\TestSuite diff --git a/PDF/PDF_vs140.vcxproj b/PDF/PDF_vs140.vcxproj index c2b2e7ed6..dc4cdbc8a 100644 --- a/PDF/PDF_vs140.vcxproj +++ b/PDF/PDF_vs140.vcxproj @@ -85,7 +85,7 @@ - <_ProjectFileVersion>14.0.23107.0 + <_ProjectFileVersion>14.0.25123.0 PocoPDFd PocoPDFmdd PocoPDFmtd @@ -285,6 +285,7 @@ + @@ -299,9 +300,11 @@ + + @@ -318,11 +321,13 @@ + + @@ -330,9 +335,11 @@ + + @@ -374,6 +381,7 @@ + @@ -384,6 +392,7 @@ + @@ -392,13 +401,17 @@ + + + + diff --git a/PDF/PDF_vs140.vcxproj.filters b/PDF/PDF_vs140.vcxproj.filters index 4d4223fb9..a06348825 100644 --- a/PDF/PDF_vs140.vcxproj.filters +++ b/PDF/PDF_vs140.vcxproj.filters @@ -2,40 +2,40 @@ - {552b2e5f-04fb-49a7-9baa-fc20dec46757} + {a0634ffa-18a6-4b8a-8d5e-5cd8ce33b3b9} - {fbdf7c26-cd16-4fb5-8263-3c8c8937cb6e} + {dae3dec4-c110-4a31-abfe-7b05f6994293} - {a1e7aa4e-57ce-46a0-a4ee-9347a029644e} + {fc45a0d4-71df-43a3-ae23-fc8b286967d1} - {c8a86f54-496a-4723-9752-b3e396279c25} + {a2b94263-66a3-49b7-a2fe-628dcb08086f} - {2178eb18-6fec-48fd-be75-fb129252b779} + {1cf26a6b-6de8-4233-ba72-b8e675ef99ff} - {680b8a32-17ff-4995-8249-29b8ce94495c} + {9af04267-b18c-467d-94a7-62e8304a81d5} - {167c8e35-db84-4fa9-b4d5-c86c44e73328} + {5b4bc72c-9f7c-4eb9-bdda-158488b0cb55} - {9223eee0-9b19-4491-a792-8eec0aa1e3f8} + {feeea5e8-7e0c-4c7c-a79d-2cf804cc1378} - {25c72362-48e2-42c2-ad81-a40c21d29019} + {43e6cf89-8985-4fb4-82c7-43631868160c} - {18792256-b2da-4e92-af96-372efd5b5af0} + {88ecf0b8-8a16-42c6-ae45-9360156c820f} - {df66f277-6850-453f-833a-c70d9d8163b2} + {8aa5e5a1-2d95-4cf3-af8e-05c1f7186560} - {834e052d-ee19-4d73-a11d-9a895a46e672} + {eb00e13a-2cc3-48f1-8c6f-9aef394cea8e} @@ -156,6 +156,9 @@ 3rd Party\zlib\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -198,6 +201,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -207,6 +213,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -255,6 +264,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -270,6 +282,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -291,6 +306,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -300,6 +318,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -383,6 +404,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -413,6 +437,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -437,6 +464,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -449,14 +479,23 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + \ No newline at end of file diff --git a/PDF/PDF_vs150.vcxproj b/PDF/PDF_vs150.vcxproj index 0af3b2ccc..5f26e8f40 100644 --- a/PDF/PDF_vs150.vcxproj +++ b/PDF/PDF_vs150.vcxproj @@ -85,7 +85,7 @@ - <_ProjectFileVersion>14.0.23107.0 + <_ProjectFileVersion>15.0.26919.1 PocoPDFd PocoPDFmdd PocoPDFmtd @@ -285,6 +285,7 @@ + @@ -299,9 +300,11 @@ + + @@ -318,11 +321,13 @@ + + @@ -330,9 +335,11 @@ + + @@ -374,6 +381,7 @@ + @@ -384,6 +392,7 @@ + @@ -392,13 +401,17 @@ + + + + diff --git a/PDF/PDF_vs150.vcxproj.filters b/PDF/PDF_vs150.vcxproj.filters index 4d4223fb9..e4349e1d6 100644 --- a/PDF/PDF_vs150.vcxproj.filters +++ b/PDF/PDF_vs150.vcxproj.filters @@ -2,40 +2,40 @@ - {552b2e5f-04fb-49a7-9baa-fc20dec46757} + {b68a3217-8ff9-46ca-a852-8b1e07294baa} - {fbdf7c26-cd16-4fb5-8263-3c8c8937cb6e} + {e6d1bded-3e36-4697-9415-08ab4087e8d1} - {a1e7aa4e-57ce-46a0-a4ee-9347a029644e} + {7e9ec59d-5949-40da-a626-eb61afb42605} - {c8a86f54-496a-4723-9752-b3e396279c25} + {c182269e-b546-45bc-b7bb-9d0b14ce8e9c} - {2178eb18-6fec-48fd-be75-fb129252b779} + {42b61af5-6dee-4824-969f-27d4e331fe01} - {680b8a32-17ff-4995-8249-29b8ce94495c} + {b1d7126a-3efe-49b7-8651-b7c4d821982d} - {167c8e35-db84-4fa9-b4d5-c86c44e73328} + {64d9fbb5-225f-4ce4-b74e-9893ad90a3e8} - {9223eee0-9b19-4491-a792-8eec0aa1e3f8} + {6bdc4af3-ac04-48be-8376-190eaeb3a58a} - {25c72362-48e2-42c2-ad81-a40c21d29019} + {fa7dd6a4-5f9f-4ddf-99a7-66e71be030a3} - {18792256-b2da-4e92-af96-372efd5b5af0} + {83f468fb-aaff-4e4c-bbe7-29a342e3d43c} - {df66f277-6850-453f-833a-c70d9d8163b2} + {72418292-af6e-457e-9554-e51c88511e83} - {834e052d-ee19-4d73-a11d-9a895a46e672} + {2d406545-c655-475f-9063-512d54f2ebf9} @@ -156,6 +156,9 @@ 3rd Party\zlib\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -198,6 +201,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -207,6 +213,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -255,6 +264,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -270,6 +282,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -291,6 +306,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -300,6 +318,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -383,6 +404,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -413,6 +437,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -437,6 +464,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -449,14 +479,23 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + \ No newline at end of file diff --git a/PDF/PDF_x64_vs140.vcxproj b/PDF/PDF_x64_vs140.vcxproj index b228be9ab..7673c258c 100644 --- a/PDF/PDF_x64_vs140.vcxproj +++ b/PDF/PDF_x64_vs140.vcxproj @@ -85,7 +85,7 @@ - <_ProjectFileVersion>14.0.23107.0 + <_ProjectFileVersion>14.0.25123.0 PocoPDF64d PocoPDFmdd PocoPDFmtd @@ -284,6 +284,7 @@ + @@ -298,9 +299,11 @@ + + @@ -317,11 +320,13 @@ + + @@ -329,9 +334,11 @@ + + @@ -373,6 +380,7 @@ + @@ -383,6 +391,7 @@ + @@ -391,13 +400,17 @@ + + + + diff --git a/PDF/PDF_x64_vs140.vcxproj.filters b/PDF/PDF_x64_vs140.vcxproj.filters index debbb97d4..e9154cad6 100644 --- a/PDF/PDF_x64_vs140.vcxproj.filters +++ b/PDF/PDF_x64_vs140.vcxproj.filters @@ -2,40 +2,40 @@ - {9b9727fd-a481-4c26-b106-71b32d6581c9} + {663ad107-137d-4e9a-93c4-ed94a22a8f17} - {8e4910d6-6b5e-467d-a958-facb4307f176} + {d4c6356e-4a4c-4c45-a6bc-7ccd406ae1ec} - {773a9037-c0f0-4c82-878e-7b917ccd4702} + {e4d66d23-45e3-427d-9c70-8282ba04665b} - {14ba9203-6ef5-4b1e-ba46-fd3c2d0774f9} + {60a90041-e161-42f0-9a77-e9d89c12433e} - {508fe1e7-e52c-4c17-aec8-47be2e5ee440} + {6c42c33a-60f7-4c5c-b2af-55b120a6f4b0} - {ed67d70f-0df4-4ae3-bf37-22427e92610d} + {0cfb430f-7053-4c6e-84fe-d0aed378c2c6} - {b3b98a78-bd86-43aa-a584-40985c225bef} + {b740ca59-9742-4a13-9f02-d4e547c2a358} - {3937fed9-a1bf-490f-8431-c874e977d843} + {9c88a241-c59c-4b5d-bc0a-b808fa732c60} - {b1a48f23-1603-4c99-8f0c-dd02ca41808c} + {419ca7b8-c305-4951-a78d-cbceed8a9d4d} - {da93ca46-eede-4412-94e0-55406bd16454} + {473ad912-8d9d-482d-bd17-f5323b1211b4} - {cb425dfd-52a1-4a94-90b2-f4eb26046d27} + {d6a021c3-53f4-4e0d-a471-9724e44eacef} - {25dc74ff-9a19-46ba-931f-8e700ef382ca} + {a085d8cd-ef46-4637-9250-40524294edb9} @@ -156,6 +156,9 @@ 3rd Party\zlib\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -198,6 +201,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -207,6 +213,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -255,6 +264,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -270,6 +282,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -291,6 +306,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -300,6 +318,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -383,6 +404,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -413,6 +437,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -437,6 +464,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -449,14 +479,23 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + \ No newline at end of file diff --git a/PDF/PDF_x64_vs150.vcxproj b/PDF/PDF_x64_vs150.vcxproj index 7d03f7cac..621be2459 100644 --- a/PDF/PDF_x64_vs150.vcxproj +++ b/PDF/PDF_x64_vs150.vcxproj @@ -85,7 +85,7 @@ - <_ProjectFileVersion>14.0.23107.0 + <_ProjectFileVersion>15.0.26919.1 PocoPDF64d PocoPDFmdd PocoPDFmtd @@ -284,6 +284,7 @@ + @@ -298,9 +299,11 @@ + + @@ -317,11 +320,13 @@ + + @@ -329,9 +334,11 @@ + + @@ -373,6 +380,7 @@ + @@ -383,6 +391,7 @@ + @@ -391,13 +400,17 @@ + + + + diff --git a/PDF/PDF_x64_vs150.vcxproj.filters b/PDF/PDF_x64_vs150.vcxproj.filters index debbb97d4..b97ecd8ce 100644 --- a/PDF/PDF_x64_vs150.vcxproj.filters +++ b/PDF/PDF_x64_vs150.vcxproj.filters @@ -2,40 +2,40 @@ - {9b9727fd-a481-4c26-b106-71b32d6581c9} + {158681b8-3d0f-48d4-9e20-022f918cb49f} - {8e4910d6-6b5e-467d-a958-facb4307f176} + {788a6650-ce51-4888-8a04-d4109b42f1ef} - {773a9037-c0f0-4c82-878e-7b917ccd4702} + {0b0476a8-8ff4-4cba-9507-f488c8b436e0} - {14ba9203-6ef5-4b1e-ba46-fd3c2d0774f9} + {bab965de-6f10-457a-b9ec-1f2384a49c01} - {508fe1e7-e52c-4c17-aec8-47be2e5ee440} + {7507cc7b-ab50-4e91-bb88-99ae6c8cf6f9} - {ed67d70f-0df4-4ae3-bf37-22427e92610d} + {47d12286-96c7-4925-8629-07ba46a79210} - {b3b98a78-bd86-43aa-a584-40985c225bef} + {f5f3d108-67e3-4327-b79c-3ccc2eb32c41} - {3937fed9-a1bf-490f-8431-c874e977d843} + {b0f93f9e-d388-4405-b70b-8ad39e0e2e53} - {b1a48f23-1603-4c99-8f0c-dd02ca41808c} + {e31c78a9-a0d0-4e51-877c-851f1ecca957} - {da93ca46-eede-4412-94e0-55406bd16454} + {c154e88e-4512-49c2-81e7-fc920914df61} - {cb425dfd-52a1-4a94-90b2-f4eb26046d27} + {8f761097-8d0a-4f44-a339-0e2db5234cbf} - {25dc74ff-9a19-46ba-931f-8e700ef382ca} + {81381f47-d176-4840-8203-a5275893306a} @@ -156,6 +156,9 @@ 3rd Party\zlib\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -198,6 +201,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -207,6 +213,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -255,6 +264,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -270,6 +282,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -291,6 +306,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -300,6 +318,9 @@ 3rd Party\HARU\Source Files + + 3rd Party\HARU\Source Files + 3rd Party\HARU\Source Files @@ -383,6 +404,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -413,6 +437,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -437,6 +464,9 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files @@ -449,14 +479,23 @@ 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + 3rd Party\HARU\Header Files + + 3rd Party\HARU\Header Files + \ No newline at end of file diff --git a/PDF/build.gradle b/PDF/build.gradle new file mode 100644 index 000000000..3fecdb3b5 --- /dev/null +++ b/PDF/build.gradle @@ -0,0 +1,39 @@ +project(":PDF") { + model { + components { + PDF(NativeLibrarySpec) { + sources { + c { + source { + srcDir 'src' + include '**/*.c' + } + exportedHeaders { + srcDirs 'include', 'include/Poco/PDF' + } + } + cpp { + source { + srcDir 'src' + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'include', 'include/Poco/PDF' + } + lib project: ':Util', library: 'Util' + lib project: ':Foundation', library: 'Foundation' + } + } + } + } + binaries { + withType(SharedLibraryBinarySpec) { + if (toolChain in VisualCpp) { + cppCompiler.define "PDF_EXPORTS" + } + } + } + } +} +task poco { dependsOn "assemble" } + diff --git a/PDF/include/Poco/PDF/Destination.h b/PDF/include/Poco/PDF/Destination.h index 4a1665ea2..bc37b5a0c 100644 --- a/PDF/include/Poco/PDF/Destination.h +++ b/PDF/include/Poco/PDF/Destination.h @@ -40,7 +40,7 @@ public: /// Sets the position and zoom for destination. void fit(); - /// Sets the appearance of the page to displaying entire page within the window. + /// Sets the appearance of the page to displaying entire page within the window. void fitHorizontal(float top); /// Defines the appearance of a page to magnifying to fit the height of the @@ -58,7 +58,7 @@ public: void fitWindow(); /// Sets the appearance of the page to magnifying to fit the bounding box of - /// the page within the window. + /// the page within the window. void fitWindowHorizontal(float top); /// Defines the appearance of a page to magnifying to fit the width of the diff --git a/PDF/include/Poco/PDF/Document.h b/PDF/include/Poco/PDF/Document.h index a6c8389dd..c9ea94668 100644 --- a/PDF/include/Poco/PDF/Document.h +++ b/PDF/include/Poco/PDF/Document.h @@ -74,26 +74,26 @@ public: enum PageLayout { - PAGE_LAYOUT_SINGLE = HPDF_PAGE_LAYOUT_SINGLE, + PAGE_LAYOUT_SINGLE = HPDF_PAGE_LAYOUT_SINGLE, /// Only one page is displayed. PAGE_LAYOUT_ONE_COLUMN = HPDF_PAGE_LAYOUT_ONE_COLUMN, /// Display the pages in one column. PAGE_LAYOUT_TWO_COLUMN_LEFT = HPDF_PAGE_LAYOUT_TWO_COLUMN_LEFT, - /// Display the pages in two column. The page of the odd number is displayed left. + /// Display the pages in two column. The page of the odd number is displayed left. PAGE_LAYOUT_TWO_COLUMN_RIGHT = HPDF_PAGE_LAYOUT_TWO_COLUMN_RIGHT - /// Display the pages in two column. The page of the odd number is displayed right. + /// Display the pages in two column. The page of the odd number is displayed right. }; enum PageMode { - PAGE_MODE_USE_NONE = HPDF_PAGE_MODE_USE_NONE, - /// Display the document with neither outline nor thumbnail. + PAGE_MODE_USE_NONE = HPDF_PAGE_MODE_USE_NONE, + /// Display the document with neither outline nor thumbnail. PAGE_MODE_USE_OUTLINE = HPDF_PAGE_MODE_USE_OUTLINE, /// Display the document with outline pain. PAGE_MODE_USE_THUMBS = HPDF_PAGE_MODE_USE_THUMBS, ///Display the document with thumbnail pain. PAGE_MODE_FULL_SCREEN = HPDF_PAGE_MODE_FULL_SCREEN - /// Display the document with full screen mode. + /// Display the document with full screen mode. }; enum Compression @@ -101,13 +101,13 @@ public: COMPRESSION_NONE = HPDF_COMP_NONE, /// All contents are not compressed. COMPRESSION_TEXT = HPDF_COMP_TEXT, - /// Compress the contents stream of the page. + /// Compress the contents stream of the page. COMPRESSION_IMAGE = HPDF_COMP_IMAGE, - /// Compress the streams of the image objects. + /// Compress the streams of the image objects. COMPRESSION_METADATA = HPDF_COMP_METADATA, /// Other stream datas (fonts, cmaps and so on) are compressed. COMPRESSION_ALL = HPDF_COMP_ALL - /// All stream datas are compressed. + /// All stream datas are compressed. /// (Same as HPDF_COMP_TEXT | HPDF_COMP_IMAGE | HPDF_COMP_METADATA) }; @@ -118,7 +118,7 @@ public: /// The length of key is automatically set to 5(40bit). ENCRYPT_R3 = HPDF_ENCRYPT_R3 /// Use "Revision 3" algorithm. - /// Between 5(40bit) and 16(128bit) can be specified for length of the key. + /// Between 5(40bit) and 16(128bit) can be specified for length of the key. }; enum PageNumberStyle @@ -167,11 +167,11 @@ public: /// the sz argument. SizeType size(); - /// Resets the document stream, reads the document into the stream and + /// Resets the document stream, reads the document into the stream and /// returns the document data size. void setPages(std::size_t pagePerPages); - /// Sets the number of pages per page. + /// Sets the number of pages per page. /// See HARU library HPDF_SetPagesConfiguration API call /// documentation for detailed explanation. @@ -218,9 +218,9 @@ public: std::string loadType1Font(const std::string& afmFileName, const std::string& pfmFileName); /// Loads type 1 font from file. Returns font name. - std::string loadTTFont(const std::string& fileName, bool embedding, int index = -1); - /// Loads type 1 font from file. Returns font name. - /// If the embedding parameter is true, the glyph data of the font is embedded, + std::string loadTTFont(const std::string& fileName, bool embed, int index = -1); + /// Loads true type font from file. Returns font name. + /// If the embed parameter is true, the glyph data of the font is embedded, /// otherwise only the matrix data is included in PDF file. const Image& loadPNGImage(const std::string& fileName); @@ -228,9 +228,9 @@ public: const Image& loadPNGImageInfo(const std::string& fileName); /// Loads the specified PNG image information from the file and returns reference to it. - /// Unlike loadPNGImage, this function does not load the whole data immediately. - /// Only size and color properties are loaded. The image data is loaded just before the - /// image object is written to PDF, and the loaded data is deleted immediately. + /// Unlike loadPNGImage, this function does not load the whole data immediately. + /// Only size and color properties are loaded. The image data is loaded just before the + /// image object is written to PDF, and the loaded data is deleted immediately. const Image& loadJPEGImage(const std::string& fileName); /// Loads the specified PNG image from the file and returns reference to it. @@ -253,6 +253,9 @@ public: void addPageLabel(int pageNum, PageNumberStyle style, int firstPage, const std::string& prefix = ""); /// adds page labeling range for the document. + void useUTF8Encoding(); + /// Enables use of UTF-8 encoding (default enabled). + void useJapaneseFonts(); /// Enables use of Japanese fonts. @@ -281,7 +284,7 @@ public: /// Creates extended graphic state object. /// Bumps up the version of PDF to 1.4. /// NOTE: - /// In Acrobat Reader 5.0, when ExtGState object is used combined with HPDF_Page_Concat(), + /// In Acrobat Reader 5.0, when ExtGState object is used combined with HPDF_Page_Concat(), /// there is a case that cannot be correctly displayed. const Outline& createOutline(const std::string& title, const Outline& outline, const Encoder& encoder); @@ -289,9 +292,9 @@ public: void setInfo(Info info, const std::string& value); /// Sets the document info. - + void setInfo(Info info, const LocalDateTime& dt); - /// Sets the document creation or modification date. + /// Sets the document creation or moidification date. std::string getInfo(Info info); /// Returns the document info. @@ -304,7 +307,13 @@ public: std::size_t pageCount() const; /// Returns number of pages in the document. + private: + HPDF_Doc& handle(); + + void init(Poco::UInt32 pageCount, + Page::Size pageSize, Page::Orientation orientation); + void reset(bool all = false); /// Resets the current document. If all is true, the loaded /// resources (e.g. fonts, encodings ...)are unloaded. Otherwise @@ -321,6 +330,8 @@ private: EncoderContainer _encoders; OutlineContainer _outlines; ImageContainer _images; + + friend class Page; }; @@ -360,8 +371,7 @@ inline Document::PageMode Document::getPageMode() const /* inline void openAction() { - HPDF_SetOpenAction(_pdf, - HPDF_Destination open_action); + HPDF_SetOpenAction(_pdf, HPDF_Destination open_action); } */ @@ -394,6 +404,12 @@ inline void Document::addPageLabel(int pageNum, PageNumberStyle style, int first } +inline void Document::useUTF8Encoding() +{ + HPDF_UseUTFEncodings(_pdf); +} + + inline void Document::useJapaneseFonts() { HPDF_UseJPFonts(_pdf); @@ -478,6 +494,12 @@ inline std::size_t Document::pageCount() const } +inline HPDF_Doc& Document::handle() +{ + return _pdf; +} + + } } // namespace Poco::PDF diff --git a/PDF/include/Poco/PDF/Encoder.h b/PDF/include/Poco/PDF/Encoder.h index 31494c969..5ef334ab6 100644 --- a/PDF/include/Poco/PDF/Encoder.h +++ b/PDF/include/Poco/PDF/Encoder.h @@ -73,10 +73,10 @@ public: /// Returns the type of an encoding object. ByteType getByteType(const std::string& text, int index = 0) const; - /// Returns the type of byte in the text at position index + /// Returns the type of byte in the text at position index WriteMode writeMode(); - /// Returns the writing mode for the encoding object. + /// Returns the writing mode for the encoding object. }; @@ -95,7 +95,7 @@ inline Encoder::ByteType Encoder::getByteType(const std::string& text, int index if (index < 0) throw InvalidArgumentException("Negative values not allowed."); - return static_cast(HPDF_Encoder_GetByteType(handle(), + return static_cast(HPDF_Encoder_GetByteType(handle(), text.c_str(), static_cast(index))); } diff --git a/PDF/include/Poco/PDF/Font.h b/PDF/include/Poco/PDF/Font.h index 1000fb481..796024032 100644 --- a/PDF/include/Poco/PDF/Font.h +++ b/PDF/include/Poco/PDF/Font.h @@ -118,8 +118,8 @@ inline int Font::upperHeight() const inline TextWidth Font::textWidth(const std::string& text) { - return HPDF_Font_TextWidth(handle(), - reinterpret_cast(text.data()), + return HPDF_Font_TextWidth(handle(), + reinterpret_cast(text.data()), static_cast(text.size())); } diff --git a/PDF/include/Poco/PDF/PDF.h b/PDF/include/Poco/PDF/PDF.h index cf5e6d7af..c591540c4 100644 --- a/PDF/include/Poco/PDF/PDF.h +++ b/PDF/include/Poco/PDF/PDF.h @@ -37,7 +37,7 @@ // from a DLL simpler. All files within this DLL are compiled with the PDF_EXPORTS // symbol defined on the command line. this symbol should not be defined on any project // that uses this DLL. This way any other project whose source files include this file see -// PDF_API functions as being imported from a DLL, whereas this DLL sees symbols +// PDF_API functions as being imported from a DLL, wheras this DLL sees symbols // defined with this macro as being exported. // #if defined(_WIN32) && defined(POCO_DLL) diff --git a/PDF/include/Poco/PDF/Page.h b/PDF/include/Poco/PDF/Page.h index 54091148b..a249fcf91 100644 --- a/PDF/include/Poco/PDF/Page.h +++ b/PDF/include/Poco/PDF/Page.h @@ -34,6 +34,9 @@ namespace Poco { namespace PDF { +class Document; + + class PDF_API Page /// A Page represents a PDF page object. { @@ -45,7 +48,7 @@ public: enum Size { - PAGE_SIZE_LETTER = HPDF_PAGE_SIZE_LETTER, + PAGE_SIZE_LETTER = HPDF_PAGE_SIZE_LETTER, /// 8½ x 11 (Inches), 612 x 792 px PAGE_SIZE_LEGAL = HPDF_PAGE_SIZE_LEGAL, /// 8½ x 14 (Inches), 612 x 1008 px @@ -141,7 +144,7 @@ public: /// Add spaces between the words to justify both left and right side. }; - Page(HPDF_Doc* pPDF, + Page(Document* pDocument, const HPDF_Page& page, Size pageSize = PAGE_SIZE_LETTER, Orientation orientation = ORIENTATION_PORTRAIT); @@ -199,6 +202,13 @@ public: void setFont(const Font& font, float size); /// Sets the font. + void setFont(const std::string& fontName, float size, const std::string& encoding = ""); + /// Sets the font. The name must be a valid Base14 PDF internal font. + + void setTTFont(const std::string& name, float size, const std::string& encoding = "UTF-8", bool embed = true); + /// Sets the external true type font. Name must be a valid path to .ttf file. + /// If embed is tru, font will be embedded int othe document. + float textWidth(const std::string& text); /// Returns the width of the supplied text. @@ -222,7 +232,7 @@ public: /// prints the text at the current position on the page. void writeNextLineEx(float wordSpace, float charSpace, const std::string& text); - /// Moves the current text position to the start of the next line, sets the word spacing, + /// Moves the current text position to the start of the next line, sets the word spacing, /// character spacing and prints the text at the current position on the page. int writeOnceInRectangle(float left, @@ -231,7 +241,7 @@ public: float bottom, const std::string& text, TextAlignment align = TEXT_ALIGN_LEFT); - /// Begins, writes and ends text objectinside the specified region. + /// Begins, writes and ends text objectinside the specified region. /// Returns the number of characters written. int writeInRectangle(float left, @@ -240,7 +250,7 @@ public: float bottom, const std::string& text, TextAlignment align); - /// Writes the text inside the specified region. + /// Writes the text inside the specified region. /// Returns the number of characters written. void drawImage(Image image, float x, float y, float width, float height); @@ -249,18 +259,18 @@ public: const Destination& createDestination(const std::string& name); /// Creates ad returns reference to destination. - const TextAnnotation& createTextAnnotation(const std::string& name, + const TextAnnotation& createTextAnnotation(const std::string& name, const Rectangle& rect, const std::string& text, const Encoder& encoder); /// Creates ad returns reference to text annotation. - const LinkAnnotation& createLinkAnnotation(const std::string& name, + const LinkAnnotation& createLinkAnnotation(const std::string& name, const Rectangle& rect, const Destination& dest); /// Creates ad returns reference to destination link annotation. - const LinkAnnotation& createURILinkAnnotation(const std::string& name, + const LinkAnnotation& createURILinkAnnotation(const std::string& name, const Rectangle& rect, const std::string& uri); /// Creates ad returns reference to URI annotation. @@ -292,22 +302,22 @@ public: void curveTo(const std::vector& values); /// Appends a Bézier curve to the current path using two specified points. - /// The point (x1, y1) and the point (x2, y2) are used as the control points + /// The point (x1, y1) and the point (x2, y2) are used as the control points /// for a Bézier curve and current point is moved to the point (x3, y3) void curveToRight(float x2, float y2, float x3, float y3); /// Appends a Bézier curve to the right of the current point using two specified points. - /// The current point and the point (x2, y2) are used as the control points + /// The current point and the point (x2, y2) are used as the control points /// for a Bézier curve and current point is moved to the point (x3, y3) void curveToLeft(float x2, float y2, float x3, float y3); /// Appends a Bézier curve to the left of the current point using two specified points. - /// The current point and the point (x2, y2) are used as the control points + /// The current point and the point (x2, y2) are used as the control points /// for a Bézier curve and current point is moved to the point (x3, y3) void closePath(); /// Appends a straight line from the current point to the start point of sub path. - /// The current point is moved to the start point of sub path. + /// The current point is moved to the start point of sub path. void rectangle(float x, float y, float width, float height); /// Draws a rectangle. @@ -319,7 +329,7 @@ public: /// Draws an arc. void ellipse(float x, float y, float xRadius, float yRadius); - /// Draws an ellipse. + /// Draws an ellips. void stroke(); /// Paints the current path. @@ -340,7 +350,7 @@ public: /// Fills the current path using the even-odd rule and then paints it. void closeFillAndStroke(); - /// Closes the current path, fills the current path using the nonzero winding number + /// Closes the current path, fills the current path using the nonzero winding number /// rule and then paints it. void closeFillAndEOStroke(); @@ -363,22 +373,22 @@ public: void moveTextPos(float x, float y); /// Moves the current text position to the start of the next line - /// using specified offset values. If the start position of the current + /// using specified offset values. If the start position of the current /// line is (x1, y1), the start of the next line is (x1 + x, y1 + y). void moveTextNextLine(float x, float y); - /// Moves the current text position to the start of the next line - /// using specified offset values, and sets the text leading to -y. - /// If the start position of the current line is (x1, y1), the start - /// of the next line is (x1 + x, y1 + y). + /// Moves the current text position to the start of the next line + /// using specified offset values, and sets the text leading to -y. + /// If the start position of the current line is (x1, y1), the start + /// of the next line is (x1 + x, y1 + y). void moveTextNextLine(); /// Moves the current text position to the start of the next line. - /// If the start position of the current line is (x1, y1), the start of + /// If the start position of the current line is (x1, y1), the start of /// the next line is (x1, y1 - text leading). /// /// NOTE: - /// Since the default value of Text Leading is 0, an application has to + /// Since the default value of Text Leading is 0, an application has to /// invoke HPDF_Page_SetTextLeading() before HPDF_Page_MoveTextPos2() to set /// text leading. @@ -422,7 +432,7 @@ public: /// Returns current dash mode. void setDashMode(const PatternVec& pattern, int paramNo, int phase) const; - /// Sets the dash mode. + /// Sets teh dash mode. float getFlatness() const; /// Returns the current flatness. @@ -511,7 +521,7 @@ public: private: Page(); - HPDF_Doc* _pPDF; + Document* _pDocument; HPDF_Page _page; Size _size; Orientation _orientation; @@ -533,12 +543,6 @@ inline Page::operator const Page::Type& () const } -inline bool Page::operator == (const Page& other) const -{ - return _pPDF == other._pPDF && _page == other._page; -} - - inline void Page::setWidth(float value) { HPDF_Page_SetWidth(_page, value); @@ -635,7 +639,7 @@ inline void Page::restoreGraphics() inline void Page::concatenate(const std::vector& values) { - if (values.size() < 6) + if (values.size() < 6) throw InvalidArgumentException("Needs six values"); HPDF_Page_Concat(_page, @@ -662,7 +666,7 @@ inline void Page::lineTo(float x, float y) inline void Page::curveTo(const std::vector& values) { - if (values.size() < 6) + if (values.size() < 6) throw InvalidArgumentException("Needs six values"); HPDF_Page_CurveTo(_page, @@ -795,13 +799,6 @@ inline void Page::moveTextNextLine() } -inline const Font& Page::getFont() const -{ - delete _pCurrentFont; - return *(_pCurrentFont = new Font(_pPDF, HPDF_Page_GetCurrentFont(_page))); -} - - inline float Page::getFontSize() const { return HPDF_Page_GetCurrentFontSize(_page); @@ -876,7 +873,7 @@ inline DashMode Page::getDashMode() const inline void Page::setDashMode(const PatternVec& pattern, int paramNo, int phase) const { - HPDF_Page_SetDash(_page, &pattern[0], + HPDF_Page_SetDash(_page, &pattern[0], static_cast(paramNo), static_cast(phase)); } diff --git a/PDF/include/Poco/PDF/Resource.h b/PDF/include/Poco/PDF/Resource.h index db0db81c1..d020fa645 100644 --- a/PDF/include/Poco/PDF/Resource.h +++ b/PDF/include/Poco/PDF/Resource.h @@ -33,7 +33,7 @@ class Resource public: typedef R Type; - Resource(HPDF_Doc* pPDF, const R& resource, const std::string& name = ""): + Resource(HPDF_Doc* pPDF, const R& resource, const std::string& name = ""): _pPDF(pPDF), _resource(resource), _name(name) @@ -41,7 +41,7 @@ public: { } - Resource(const Resource& other): + Resource(const Resource& other): _pPDF(other._pPDF), _resource(other._resource), _name(other._name) diff --git a/PDF/include/Poco/PDF/deflate.h b/PDF/include/Poco/PDF/deflate.h index 0bfed3b3f..4caad87f4 100644 --- a/PDF/include/Poco/PDF/deflate.h +++ b/PDF/include/Poco/PDF/deflate.h @@ -188,7 +188,7 @@ typedef struct internal_state { int nice_match; /* Stop searching when current match exceeds this */ /* used by trees.c: */ - /* Didn't use ct_data typedef below to suppress compiler warning */ + /* Didn't use ct_data typedef below to supress compiler warning */ struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ diff --git a/PDF/include/Poco/PDF/hpdf.h b/PDF/include/Poco/PDF/hpdf.h index c849db8aa..e369f6744 100644 --- a/PDF/include/Poco/PDF/hpdf.h +++ b/PDF/include/Poco/PDF/hpdf.h @@ -1,7 +1,7 @@ /* * << Haru Free PDF Library 2.0.8 >> -- hpdf.h * - * URL http://libharu.sourceforge.net/ + * URL http://libharu.org/ * * Copyright (c) 1999-2006 Takeshi Kanno * @@ -17,6 +17,11 @@ #ifndef _HPDF_H #define _HPDF_H +#include "hpdf_config.h" +#include "hpdf_version.h" + +#define HPDF_UNUSED(a) ((void)(a)) + #ifdef HPDF_DLL_MAKE # define HPDF_EXPORT(A) __declspec(dllexport) A __stdcall #else @@ -57,10 +62,21 @@ typedef HPDF_HANDLE HPDF_Image; typedef HPDF_HANDLE HPDF_Font; typedef HPDF_HANDLE HPDF_Outline; typedef HPDF_HANDLE HPDF_Encoder; +typedef HPDF_HANDLE HPDF_3DMeasure; +typedef HPDF_HANDLE HPDF_ExData; typedef HPDF_HANDLE HPDF_Destination; typedef HPDF_HANDLE HPDF_XObject; typedef HPDF_HANDLE HPDF_Annotation; typedef HPDF_HANDLE HPDF_ExtGState; +typedef HPDF_HANDLE HPDF_FontDef; +typedef HPDF_HANDLE HPDF_U3D; +typedef HPDF_HANDLE HPDF_JavaScript; +typedef HPDF_HANDLE HPDF_Error; +typedef HPDF_HANDLE HPDF_MMgr; +typedef HPDF_HANDLE HPDF_Dict; +typedef HPDF_HANDLE HPDF_EmbeddedFile; +typedef HPDF_HANDLE HPDF_OutputIntent; +typedef HPDF_HANDLE HPDF_Xref; #else @@ -70,6 +86,8 @@ typedef HPDF_HANDLE HPDF_ExtGState; #include "hpdf_consts.h" #include "hpdf_doc.h" +#include "hpdf_error.h" +#include "hpdf_pdfa.h" #endif /* HPDF_SHARED */ @@ -121,6 +139,10 @@ HPDF_FreeDocAll (HPDF_Doc pdf); HPDF_EXPORT(HPDF_STATUS) HPDF_SaveToStream (HPDF_Doc pdf); +HPDF_EXPORT(HPDF_STATUS) +HPDF_GetContents (HPDF_Doc pdf, + HPDF_BYTE *buf, + HPDF_UINT32 *size); HPDF_EXPORT(HPDF_UINT32) HPDF_GetStreamSize (HPDF_Doc pdf); @@ -152,6 +174,10 @@ HPDF_EXPORT(void) HPDF_ResetError (HPDF_Doc pdf); +HPDF_EXPORT(HPDF_STATUS) +HPDF_CheckError (HPDF_Error error); + + HPDF_EXPORT(HPDF_STATUS) HPDF_SetPagesConfiguration (HPDF_Doc pdf, HPDF_UINT page_per_pages); @@ -233,6 +259,10 @@ HPDF_EXPORT(HPDF_STATUS) HPDF_Page_SetRotate (HPDF_Page page, HPDF_UINT16 angle); +HPDF_EXPORT(HPDF_STATUS) +HPDF_Page_SetZoom (HPDF_Page page, + HPDF_REAL zoom); + /*---------------------------------------------------------------------------*/ /*----- font handling -------------------------------------------------------*/ @@ -249,6 +279,11 @@ HPDF_LoadType1FontFromFile (HPDF_Doc pdf, const char *data_file_name); +HPDF_EXPORT(HPDF_FontDef) +HPDF_GetTTFontDefFromFile (HPDF_Doc pdf, + const char *file_name, + HPDF_BOOL embedding); + HPDF_EXPORT(const char*) HPDF_LoadTTFontFromFile (HPDF_Doc pdf, const char *file_name, @@ -411,15 +446,34 @@ HPDF_EXPORT(HPDF_STATUS) HPDF_UseCNTEncodings (HPDF_Doc pdf); +HPDF_EXPORT(HPDF_STATUS) +HPDF_UseUTFEncodings (HPDF_Doc pdf); + + /*--------------------------------------------------------------------------*/ /*----- annotation ---------------------------------------------------------*/ +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_Create3DAnnot (HPDF_Page page, + HPDF_Rect rect, + HPDF_U3D u3d); + HPDF_EXPORT(HPDF_Annotation) HPDF_Page_CreateTextAnnot (HPDF_Page page, HPDF_Rect rect, const char *text, HPDF_Encoder encoder); +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateFreeTextAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateLineAnnot (HPDF_Page page, + const char *text, + HPDF_Encoder encoder); HPDF_EXPORT(HPDF_Annotation) HPDF_Page_CreateLinkAnnot (HPDF_Page page, @@ -433,6 +487,67 @@ HPDF_Page_CreateURILinkAnnot (HPDF_Page page, const char *uri); +HPDF_Annotation +HPDF_Page_CreateTextMarkupAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder, + HPDF_AnnotType subType); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateHighlightAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateUnderlineAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateSquigglyAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateStrikeOutAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreatePopupAnnot ( HPDF_Page page, + HPDF_Rect rect, + HPDF_Annotation parent); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateStampAnnot ( HPDF_Page page, + HPDF_Rect rect, + HPDF_StampAnnotName name, + const char* text, + HPDF_Encoder encoder); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateProjectionAnnot(HPDF_Page page, + HPDF_Rect rect, + const char* text, + HPDF_Encoder encoder); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateSquareAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder); + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateCircleAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder); + HPDF_EXPORT(HPDF_STATUS) HPDF_LinkAnnot_SetHighlightMode (HPDF_Annotation annot, HPDF_AnnotHighlightMode mode); @@ -454,11 +569,179 @@ HPDF_EXPORT(HPDF_STATUS) HPDF_TextAnnot_SetOpened (HPDF_Annotation annot, HPDF_BOOL opened); +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_SetRGBColor (HPDF_Annotation annot, HPDF_RGBColor color); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_SetCMYKColor (HPDF_Annotation annot, HPDF_CMYKColor color); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_SetGrayColor (HPDF_Annotation annot, HPDF_REAL color); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_SetNoColor (HPDF_Annotation annot); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetTitle (HPDF_Annotation annot, const char* name); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetSubject (HPDF_Annotation annot, const char* name); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetCreationDate (HPDF_Annotation annot, HPDF_Date value); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetTransparency (HPDF_Annotation annot, HPDF_REAL value); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetIntent (HPDF_Annotation annot, HPDF_AnnotIntent intent); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetPopup (HPDF_Annotation annot, HPDF_Annotation popup); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetRectDiff (HPDF_Annotation annot, HPDF_Rect rect); /* RD entry */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetCloudEffect (HPDF_Annotation annot, HPDF_INT cloudIntensity); /* BE entry */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetInteriorRGBColor (HPDF_Annotation annot, HPDF_RGBColor color); /* IC with RGB entry */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetInteriorCMYKColor (HPDF_Annotation annot, HPDF_CMYKColor color); /* IC with CMYK entry */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetInteriorGrayColor (HPDF_Annotation annot, HPDF_REAL color); /* IC with Gray entry */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetInteriorTransparent (HPDF_Annotation annot); /* IC with No Color entry */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_TextMarkupAnnot_SetQuadPoints ( HPDF_Annotation annot, HPDF_Point lb, HPDF_Point rb, HPDF_Point rt, HPDF_Point lt); /* l-left, r-right, b-bottom, t-top positions */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_Set3DView ( HPDF_MMgr mmgr, + HPDF_Annotation annot, + HPDF_Annotation annot3d, + HPDF_Dict view); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_PopupAnnot_SetOpened (HPDF_Annotation annot, + HPDF_BOOL opened); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_FreeTextAnnot_SetLineEndingStyle (HPDF_Annotation annot, HPDF_LineAnnotEndingStyle startStyle, HPDF_LineAnnotEndingStyle endStyle); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_FreeTextAnnot_Set3PointCalloutLine (HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point kneePoint, HPDF_Point endPoint); /* Callout line will be in default user space */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_FreeTextAnnot_Set2PointCalloutLine (HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point endPoint); /* Callout line will be in default user space */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_FreeTextAnnot_SetDefaultStyle (HPDF_Annotation annot, const char* style); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_LineAnnot_SetPosition (HPDF_Annotation annot, + HPDF_Point startPoint, HPDF_LineAnnotEndingStyle startStyle, + HPDF_Point endPoint, HPDF_LineAnnotEndingStyle endStyle); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_LineAnnot_SetLeader (HPDF_Annotation annot, HPDF_INT leaderLen, HPDF_INT leaderExtLen, HPDF_INT leaderOffsetLen); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_LineAnnot_SetCaption (HPDF_Annotation annot, HPDF_BOOL showCaption, HPDF_LineAnnotCapPosition position, HPDF_INT horzOffset, HPDF_INT vertOffset); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annotation_SetBorderStyle (HPDF_Annotation annot, + HPDF_BSSubtype subtype, + HPDF_REAL width, + HPDF_UINT16 dash_on, + HPDF_UINT16 dash_off, + HPDF_UINT16 dash_phase); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_ProjectionAnnot_SetExData(HPDF_Annotation annot, HPDF_ExData exdata); +/*--------------------------------------------------------------------------*/ +/*----- 3D Measure ---------------------------------------------------------*/ +HPDF_EXPORT(HPDF_3DMeasure) +HPDF_Page_Create3DC3DMeasure(HPDF_Page page, + HPDF_Point3D firstanchorpoint, + HPDF_Point3D textanchorpoint + ); + +HPDF_EXPORT(HPDF_3DMeasure) +HPDF_Page_CreatePD33DMeasure(HPDF_Page page, + HPDF_Point3D annotationPlaneNormal, + HPDF_Point3D firstAnchorPoint, + HPDF_Point3D secondAnchorPoint, + HPDF_Point3D leaderLinesDirection, + HPDF_Point3D measurementValuePoint, + HPDF_Point3D textYDirection, + HPDF_REAL value, + const char* unitsString + ); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DMeasure_SetName(HPDF_3DMeasure measure, + const char* name); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DMeasure_SetColor(HPDF_3DMeasure measure, + HPDF_RGBColor color); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DMeasure_SetTextSize(HPDF_3DMeasure measure, + HPDF_REAL textsize); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DC3DMeasure_SetTextBoxSize(HPDF_3DMeasure measure, + HPDF_INT32 x, + HPDF_INT32 y); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DC3DMeasure_SetText(HPDF_3DMeasure measure, + const char* text, + HPDF_Encoder encoder); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DC3DMeasure_SetProjectionAnotation(HPDF_3DMeasure measure, + HPDF_Annotation projectionanotation); + +/*--------------------------------------------------------------------------*/ +/*----- External Data ---------------------------------------------------------*/ + +HPDF_EXPORT(HPDF_ExData) +HPDF_Page_Create3DAnnotExData(HPDF_Page page ); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DAnnotExData_Set3DMeasurement(HPDF_ExData exdata, HPDF_3DMeasure measure); + +/*--------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------------*/ +/*----- 3D View ---------------------------------------------------------*/ + +HPDF_EXPORT(HPDF_Dict) +HPDF_Page_Create3DView (HPDF_Page page, + HPDF_U3D u3d, + HPDF_Annotation annot3d, + const char *name); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DView_Add3DC3DMeasure(HPDF_Dict view, + HPDF_3DMeasure measure); + /*--------------------------------------------------------------------------*/ /*----- image data ---------------------------------------------------------*/ +HPDF_EXPORT(HPDF_Image) +HPDF_LoadPngImageFromMem (HPDF_Doc pdf, + const HPDF_BYTE *buffer, + HPDF_UINT size); + HPDF_EXPORT(HPDF_Image) HPDF_LoadPngImageFromFile (HPDF_Doc pdf, const char *filename); @@ -473,6 +756,29 @@ HPDF_EXPORT(HPDF_Image) HPDF_LoadJpegImageFromFile (HPDF_Doc pdf, const char *filename); +HPDF_EXPORT(HPDF_Image) +HPDF_LoadJpegImageFromMem (HPDF_Doc pdf, + const HPDF_BYTE *buffer, + HPDF_UINT size); + +HPDF_EXPORT(HPDF_Image) +HPDF_LoadU3DFromFile (HPDF_Doc pdf, + const char *filename); + +HPDF_EXPORT(HPDF_Image) +HPDF_LoadU3DFromMem (HPDF_Doc pdf, + const HPDF_BYTE *buffer, + HPDF_UINT size); + +HPDF_EXPORT(HPDF_Image) +HPDF_Image_LoadRaw1BitImageFromMem (HPDF_Doc pdf, + const HPDF_BYTE *buf, + HPDF_UINT width, + HPDF_UINT height, + HPDF_UINT line_width, + HPDF_BOOL black_is1, + HPDF_BOOL top_is_first); + HPDF_EXPORT(HPDF_Image) HPDF_LoadRawImageFromFile (HPDF_Doc pdf, @@ -490,6 +796,9 @@ HPDF_LoadRawImageFromMem (HPDF_Doc pdf, HPDF_ColorSpace color_space, HPDF_UINT bits_per_component); +HPDF_EXPORT(HPDF_STATUS) +HPDF_Image_AddSMask (HPDF_Image image, + HPDF_Image smask); HPDF_EXPORT(HPDF_Point) HPDF_Image_GetSize (HPDF_Image image); @@ -632,6 +941,14 @@ HPDF_Font_MeasureText (HPDF_Font font, HPDF_REAL *real_width); +/*--------------------------------------------------------------------------*/ +/*----- attachements -------------------------------------------------------*/ + +HPDF_EXPORT(HPDF_EmbeddedFile) +HPDF_AttachFile (HPDF_Doc pdf, + const char *file); + + /*--------------------------------------------------------------------------*/ /*----- extended graphics state --------------------------------------------*/ @@ -1148,6 +1465,17 @@ HPDF_EXPORT(HPDF_STATUS) HPDF_Page_ExecuteXObject (HPDF_Page page, HPDF_XObject obj); +/*--- Content streams ----------------------------------------------------*/ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Page_New_Content_Stream (HPDF_Page page, + HPDF_Dict* new_stream); + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Page_Insert_Shared_Content_Stream (HPDF_Page page, + HPDF_Dict shared_stream); + + /*--- Marked content -----------------------------------------------------*/ /* BMC --not implemented yet */ @@ -1219,6 +1547,18 @@ HPDF_Page_SetSlideShow (HPDF_Page page, HPDF_REAL trans_time); +HPDF_EXPORT(HPDF_OutputIntent) +HPDF_ICC_LoadIccFromMem (HPDF_Doc pdf, + HPDF_MMgr mmgr, + HPDF_Stream iccdata, + HPDF_Xref xref, + int numcomponent); + +HPDF_EXPORT(HPDF_OutputIntent) +HPDF_LoadIccProfileFromFile (HPDF_Doc pdf, + const char* icc_file_name, + int numcomponent); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/PDF/include/Poco/PDF/hpdf_3dmeasure.h b/PDF/include/Poco/PDF/hpdf_3dmeasure.h new file mode 100644 index 000000000..ebfa7b077 --- /dev/null +++ b/PDF/include/Poco/PDF/hpdf_3dmeasure.h @@ -0,0 +1,57 @@ +/* + * << Haru Free PDF Library >> -- hpdf_annotation.h + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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. + * + */ + +#ifndef _HPDF_3DMEASURE_H +#define _HPDF_3DMEASURE_H + +#include "hpdf_objects.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------------------------*/ +/*------ HPDF_3DMeasure -----------------------------------------------------*/ + + +HPDF_3DMeasure +HPDF_3DC3DMeasure_New(HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Point3D firstanchorpoint, + HPDF_Point3D textanchorpoint + ); + +HPDF_3DMeasure +HPDF_PD33DMeasure_New(HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Point3D annotationPlaneNormal, + HPDF_Point3D firstAnchorPoint, + HPDF_Point3D secondAnchorPoint, + HPDF_Point3D leaderLinesDirection, + HPDF_Point3D measurementValuePoint, + HPDF_Point3D textYDirection, + HPDF_REAL value, + const char* unitsString + ); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _HPDF_3DMEASURE_H */ + diff --git a/PDF/include/Poco/PDF/hpdf_annotation.h b/PDF/include/Poco/PDF/hpdf_annotation.h index 8ae3b38b8..699373ac0 100644 --- a/PDF/include/Poco/PDF/hpdf_annotation.h +++ b/PDF/include/Poco/PDF/hpdf_annotation.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_annotation.h + * << Haru Free PDF Library >> -- hpdf_annotation.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -47,21 +50,39 @@ HPDF_URILinkAnnot_New (HPDF_MMgr mmgr, HPDF_Annotation -HPDF_TextAnnot_New (HPDF_MMgr mmgr, - HPDF_Xref xref, - HPDF_Rect rect, - const char *text, - HPDF_Encoder encoder); +HPDF_3DAnnot_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Rect rect, + HPDF_U3D u3d); +HPDF_Annotation +HPDF_MarkupAnnot_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder, + HPDF_AnnotType subtype); -HPDF_STATUS -HPDF_Annotation_SetBorderStyle (HPDF_Annotation annot, - HPDF_BSSubtype subtype, - HPDF_REAL width, - HPDF_UINT16 dash_on, - HPDF_UINT16 dash_off, - HPDF_UINT16 dash_phase); +HPDF_Annotation +HPDF_PopupAnnot_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Rect rect, + HPDF_Annotation parent); +HPDF_Annotation +HPDF_StampAnnot_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Rect rect, + HPDF_StampAnnotName name, + const char* text, + HPDF_Encoder encoder); + +HPDF_Annotation +HPDF_ProjectionAnnot_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Rect rect, + const char* text, + HPDF_Encoder encoder); HPDF_BOOL HPDF_Annotation_Validate (HPDF_Annotation annot); diff --git a/PDF/include/Poco/PDF/hpdf_catalog.h b/PDF/include/Poco/PDF/hpdf_catalog.h index 882721b3b..469d2a48d 100644 --- a/PDF/include/Poco/PDF/hpdf_catalog.h +++ b/PDF/include/Poco/PDF/hpdf_catalog.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_catalog.h + * << Haru Free PDF Library >> -- hpdf_catalog.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -28,6 +31,15 @@ HPDF_Catalog_New (HPDF_MMgr mmgr, HPDF_Xref xref); +HPDF_NameDict +HPDF_Catalog_GetNames (HPDF_Catalog catalog); + + +HPDF_STATUS +HPDF_Catalog_SetNames (HPDF_Catalog catalog, + HPDF_NameDict dict); + + HPDF_Pages HPDF_Catalog_GetRoot (HPDF_Catalog catalog); diff --git a/PDF/include/Poco/PDF/hpdf_conf.h b/PDF/include/Poco/PDF/hpdf_conf.h index c99f474b6..d25b46466 100644 --- a/PDF/include/Poco/PDF/hpdf_conf.h +++ b/PDF/include/Poco/PDF/hpdf_conf.h @@ -1,9 +1,10 @@ /* - * << Haru Free PDF Library 2.0.7 >> -- hpdf_conf.h + * << Haru Free PDF Library >> -- hpdf_conf.h * - * URL http://libharu.sourceforge.net/ + * URL: http://libharu.org * - * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -19,6 +20,14 @@ #include #include +#if defined(_MSC_VER) +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES 1 +#endif /* _USE_MATH_DEFINES */ +#endif +#ifndef __USE_XOPEN +#define __USE_XOPEN /* for M_PI */ +#endif /* __USE_XOPEN */ #include /*----------------------------------------------------------------------------*/ diff --git a/PDF/include/Poco/PDF/hpdf_config.h b/PDF/include/Poco/PDF/hpdf_config.h new file mode 100644 index 000000000..d3aa381e6 --- /dev/null +++ b/PDF/include/Poco/PDF/hpdf_config.h @@ -0,0 +1,75 @@ +/* include/hpdf_config.h.in. Generated from configure.in by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef LIBHPDF_HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef LIBHPDF_HAVE_INTTYPES_H + +/* Define to 1 if you have the `png' library (-lpng). */ +#define LIBHPDF_HAVE_LIBPNG 1 + +/* Define to 1 if you have the `z' library (-lz). */ +#define LIBHPDF_HAVE_LIBZ 1 + +/* Define to 1 if you have the header file. */ +#undef LIBHPDF_HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef LIBHPDF_HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#define LIBHPDF_HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define LIBHPDF_HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define LIBHPDF_HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define LIBHPDF_HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#undef LIBHPDF_HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#define LIBHPDF_HAVE_UNISTD_H 1 + +/* define pi */ +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif /* M_PI */ + +/* debug build */ +#undef LIBHPDF_DEBUG + +/* debug trace enabled */ +#undef LIBHPDF_DEBUG_TRACE + +/* libpng is not available */ +#undef LIBHPDF_HAVE_NOPNGLIB + +/* zlib is not available */ +#undef LIBHPDF_HAVE_NOZLIB + +/* Define to the address where bug reports for this package should be sent. */ +#undef LIBHPDF_PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef LIBHPDF_PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#define LIBHPDF_PACKAGE_STRING "libhpdf 2.2.0" + +/* Define to the one symbol short name of this package. */ +#undef LIBHPDF_PACKAGE_TARNAME + +/* Define to the version of this package. */ +#define LIBHPDF_PACKAGE_VERSION "2.2.0" + +/* Define to 1 if you have the ANSI C header files. */ +#define LIBHPDF_STDC_HEADERS 1 + +/* Define to `unsigned int' if does not define. */ +#undef size_t diff --git a/PDF/include/Poco/PDF/hpdf_consts.h b/PDF/include/Poco/PDF/hpdf_consts.h index de237f9ea..d080f8df6 100644 --- a/PDF/include/Poco/PDF/hpdf_consts.h +++ b/PDF/include/Poco/PDF/hpdf_consts.h @@ -1,9 +1,10 @@ /* - * << Haru Free PDF Library 2.0.8 >> -- hpdf_consts.h + * << Haru Free PDF Library >> -- hpdf_consts.h * - * URL http://libharu.sourceforge.net/ + * URL: http://libharu.org * - * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -67,8 +68,6 @@ #define HPDF_DEF_PAGE_WIDTH 595.276F #define HPDF_DEF_PAGE_HEIGHT 841.89F -#define HPDF_VERSION_TEXT "2.0.8" - /*---------------------------------------------------------------------------*/ /*----- compression mode ----------------------------------------------------*/ @@ -101,6 +100,7 @@ #define HPDF_HIDE_WINDOW_UI 4 #define HPDF_FIT_WINDOW 8 #define HPDF_CENTER_WINDOW 16 +#define HPDF_PRINT_SCALING_NONE 32 /*---------------------------------------------------------------------------*/ @@ -115,7 +115,7 @@ #define HPDF_LIMIT_MAX_STRING_LEN 65535 #define HPDF_LIMIT_MAX_NAME_LEN 127 -#define HPDF_LIMIT_MAX_ARRAY 8191 +#define HPDF_LIMIT_MAX_ARRAY 32767 #define HPDF_LIMIT_MAX_DICT_ELEMENT 4095 #define HPDF_LIMIT_MAX_XREF_ELEMENT 8388607 #define HPDF_LIMIT_MAX_GSTATE 28 @@ -142,7 +142,7 @@ #define HPDF_MAX_WORDSPACE 300 #define HPDF_MIN_CHARSPACE -30 #define HPDF_MAX_CHARSPACE 300 -#define HPDF_MAX_FONTSIZE 300 +#define HPDF_MAX_FONTSIZE 600 #define HPDF_MAX_ZOOMSIZE 10 #define HPDF_MAX_LEADING 300 #define HPDF_MAX_LINEWIDTH 100 diff --git a/PDF/include/Poco/PDF/hpdf_destination.h b/PDF/include/Poco/PDF/hpdf_destination.h index 134cabf6d..daf08ed73 100644 --- a/PDF/include/Poco/PDF/hpdf_destination.h +++ b/PDF/include/Poco/PDF/hpdf_destination.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_destination.c + * << Haru Free PDF Library >> -- hpdf_destination.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_doc.h b/PDF/include/Poco/PDF/hpdf_doc.h index 831d0a3b1..fcf3039d9 100644 --- a/PDF/include/Poco/PDF/hpdf_doc.h +++ b/PDF/include/Poco/PDF/hpdf_doc.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_doc.h + * << Haru Free PDF Library >> -- hpdf_doc.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_encoder.h b/PDF/include/Poco/PDF/hpdf_encoder.h index f2ba73cce..820fe1fb6 100644 --- a/PDF/include/Poco/PDF/hpdf_encoder.h +++ b/PDF/include/Poco/PDF/hpdf_encoder.h @@ -1,9 +1,10 @@ /* - * << Haru Free PDF Library 2.0.2 >> -- hpdf_encoder.h + * << Haru Free PDF Library >> -- hpdf_encoder.h * - * URL http://libharu.sourceforge.net/ + * URL: http://libharu.org * - * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -92,6 +93,11 @@ typedef HPDF_UNICODE (*HPDF_Encoder_ToUnicode_Func) (HPDF_Encoder encoder, HPDF_UINT16 code); +typedef char * +(*HPDF_Encoder_EncodeText_Func) (HPDF_Encoder encoder, + const char *text, + HPDF_UINT len, + HPDF_UINT *encoded_length); typedef HPDF_STATUS (*HPDF_Encoder_Write_Func) (HPDF_Encoder encoder, @@ -108,13 +114,14 @@ typedef void typedef struct _HPDF_Encoder_Rec { HPDF_UINT32 sig_bytes; - char name[HPDF_LIMIT_MAX_NAME_LEN + 1]; + char name[HPDF_LIMIT_MAX_NAME_LEN + 1]; HPDF_MMgr mmgr; HPDF_Error error; HPDF_EncoderType type; HPDF_Encoder_ByteType_Func byte_type_fn; HPDF_Encoder_ToUnicode_Func to_unicode_fn; + HPDF_Encoder_EncodeText_Func encode_text_fn; HPDF_Encoder_Write_Func write_fn; HPDF_Encoder_Free_Func free_fn; HPDF_Encoder_Init_Func init_fn; @@ -230,7 +237,7 @@ typedef struct _HPDF_CMapEncoderAttr_Rec { HPDF_Encoder HPDF_CMapEncoder_New (HPDF_MMgr mmgr, - char *name, + char *name, HPDF_Encoder_Init_Func init_fn); diff --git a/PDF/include/Poco/PDF/hpdf_encrypt.h b/PDF/include/Poco/PDF/hpdf_encrypt.h index 3211e4905..a34cc3dd2 100644 --- a/PDF/include/Poco/PDF/hpdf_encrypt.h +++ b/PDF/include/Poco/PDF/hpdf_encrypt.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_encrypt.h + * << Haru Free PDF Library >> -- hpdf_encrypt.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_encryptdict.h b/PDF/include/Poco/PDF/hpdf_encryptdict.h index 1bda2c0e6..018b3dd62 100644 --- a/PDF/include/Poco/PDF/hpdf_encryptdict.h +++ b/PDF/include/Poco/PDF/hpdf_encryptdict.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_encryptdict.h + * << Haru Free PDF Library >> -- hpdf_encryptdict.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_error.h b/PDF/include/Poco/PDF/hpdf_error.h index dbc9176fe..b04e2cd11 100644 --- a/PDF/include/Poco/PDF/hpdf_error.h +++ b/PDF/include/Poco/PDF/hpdf_error.h @@ -1,9 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_error.h + * << Haru Free PDF Library >> -- hpdf_error.h * - * URL http://libharu.sourceforge.net/ + * URL: http://libharu.org * - * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -141,6 +142,11 @@ extern "C" { #define HPDF_EXT_GSTATE_OUT_OF_RANGE 0x1080 #define HPDF_INVALID_EXT_GSTATE 0x1081 #define HPDF_EXT_GSTATE_READ_ONLY 0x1082 +#define HPDF_INVALID_U3D_DATA 0x1083 +#define HPDF_NAME_CANNOT_GET_NAMES 0x1084 +#define HPDF_INVALID_ICC_COMPONENT_NUM 0x1085 + +/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /*----- HPDF_Error ----------------------------------------------------------*/ @@ -184,10 +190,6 @@ HPDF_SetError (HPDF_Error error, HPDF_STATUS detail_no); -HPDF_STATUS -HPDF_CheckError (HPDF_Error error); - - HPDF_STATUS HPDF_RaiseError (HPDF_Error error, HPDF_STATUS error_no, diff --git a/PDF/include/Poco/PDF/hpdf_exdata.h b/PDF/include/Poco/PDF/hpdf_exdata.h new file mode 100644 index 000000000..8d92e7909 --- /dev/null +++ b/PDF/include/Poco/PDF/hpdf_exdata.h @@ -0,0 +1,41 @@ +/* + * << Haru Free PDF Library >> -- hpdf_annotation.h + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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. + * + */ + +#ifndef _HPDF_EXDATA_H +#define _HPDF_EXDATA_H + +#include "hpdf_objects.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------------------------*/ +/*------ HPDF_ExData -----------------------------------------------------*/ + +HPDF_ExData +HPDF_3DAnnotExData_New(HPDF_MMgr mmgr, + HPDF_Xref xref ); + + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _HPDF_EXDATA_H */ + diff --git a/PDF/include/Poco/PDF/hpdf_ext_gstate.h b/PDF/include/Poco/PDF/hpdf_ext_gstate.h index 4d54aab19..7dae6d4bd 100644 --- a/PDF/include/Poco/PDF/hpdf_ext_gstate.h +++ b/PDF/include/Poco/PDF/hpdf_ext_gstate.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_ext_gstate.h + * << Haru Free PDF Library >> -- hpdf_ext_gstate.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -22,7 +25,7 @@ extern "C" { #endif HPDF_Dict -HPDF_ExtGState_New (HPDF_MMgr mmgr, +HPDF_ExtGState_New (HPDF_MMgr mmgr, HPDF_Xref xref); diff --git a/PDF/include/Poco/PDF/hpdf_font.h b/PDF/include/Poco/PDF/hpdf_font.h index 84a486485..fd3a25616 100644 --- a/PDF/include/Poco/PDF/hpdf_font.h +++ b/PDF/include/Poco/PDF/hpdf_font.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_font.h + * << Haru Free PDF Library >> -- hpdf_font.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -69,7 +72,7 @@ typedef struct _HPDF_FontAttr_Rec { HPDF_Encoder encoder; /* if the encoding-type is HPDF_ENCODER_TYPE_SINGLE_BYTE, the width of - * each characters are cashed in 'widths'. + * each charactors are cashed in 'widths'. * when HPDF_ENCODER_TYPE_DOUBLE_BYTE the width is calculate each time. */ HPDF_INT16* widths; diff --git a/PDF/include/Poco/PDF/hpdf_fontdef.h b/PDF/include/Poco/PDF/hpdf_fontdef.h index b18c1af33..792588c6c 100644 --- a/PDF/include/Poco/PDF/hpdf_fontdef.h +++ b/PDF/include/Poco/PDF/hpdf_fontdef.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.4 >> -- hpdf_fontdef.h + * << Haru Free PDF Library >> -- hpdf_fontdef.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -300,7 +303,8 @@ typedef struct _HPDF_TTFontDefAttr_Rec { HPDF_TTF_OffsetTbl offset_tbl; HPDF_TTF_CmapRange cmap; HPDF_UINT16 fs_type; - HPDF_BYTE panose[12]; + HPDF_BYTE sfamilyclass[2]; + HPDF_BYTE panose[10]; HPDF_UINT32 code_page_range1; HPDF_UINT32 code_page_range2; @@ -400,4 +404,3 @@ HPDF_CIDFontDef_ChangeStyle (HPDF_FontDef fontdef, #endif /* __cplusplus */ #endif /* _HPDF_FONTDEF_H */ - diff --git a/PDF/include/Poco/PDF/hpdf_gstate.h b/PDF/include/Poco/PDF/hpdf_gstate.h index c7147580c..233ae528f 100644 --- a/PDF/include/Poco/PDF/hpdf_gstate.h +++ b/PDF/include/Poco/PDF/hpdf_gstate.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_gstate.h + * << Haru Free PDF Library >> -- hpdf_gstate.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_image.h b/PDF/include/Poco/PDF/hpdf_image.h index a84de29bd..4e1aa6c09 100644 --- a/PDF/include/Poco/PDF/hpdf_image.h +++ b/PDF/include/Poco/PDF/hpdf_image.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_image.h + * << Haru Free PDF Library >> -- hpdf_image.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -21,7 +24,18 @@ extern "C" { #endif -#ifndef HPDF_NOPNGLIB +HPDF_Image +HPDF_Image_Load1BitImageFromMem (HPDF_MMgr mmgr, + const HPDF_BYTE *buf, + HPDF_Xref xref, + HPDF_UINT width, + HPDF_UINT height, + HPDF_UINT line_width, + HPDF_BOOL top_is_first + ); + + +#ifndef LIBHPDF_HAVE_NOPNGLIB HPDF_Image HPDF_Image_LoadPngImage (HPDF_MMgr mmgr, @@ -36,6 +50,11 @@ HPDF_Image_LoadJpegImage (HPDF_MMgr mmgr, HPDF_Stream jpeg_data, HPDF_Xref xref); +HPDF_Image +HPDF_Image_LoadJpegImageFromMem (HPDF_MMgr mmgr, + const HPDF_BYTE *buf, + HPDF_UINT size, + HPDF_Xref xref); HPDF_Image HPDF_Image_LoadRawImage (HPDF_MMgr mmgr, @@ -64,6 +83,14 @@ HPDF_STATUS HPDF_Image_SetMask (HPDF_Image image, HPDF_BOOL mask); +HPDF_STATUS +HPDF_Image_SetColorSpace (HPDF_Image image, + HPDF_Array colorspace); + +HPDF_STATUS +HPDF_Image_SetRenderingIntent (HPDF_Image image, + const char* intent); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/PDF/include/Poco/PDF/hpdf_info.h b/PDF/include/Poco/PDF/hpdf_info.h index 623c4c27b..14bcdd015 100644 --- a/PDF/include/Poco/PDF/hpdf_info.h +++ b/PDF/include/Poco/PDF/hpdf_info.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_info.c + * << Haru Free PDF Library >> -- hpdf_info.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_list.h b/PDF/include/Poco/PDF/hpdf_list.h index c0920e14c..c46d01319 100644 --- a/PDF/include/Poco/PDF/hpdf_list.h +++ b/PDF/include/Poco/PDF/hpdf_list.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_list.h + * << Haru Free PDF Library >> -- hpdf_list.h * - * Copyright (c) 1999-2005 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_mmgr.h b/PDF/include/Poco/PDF/hpdf_mmgr.h index 7e3683b27..d815afd65 100644 --- a/PDF/include/Poco/PDF/hpdf_mmgr.h +++ b/PDF/include/Poco/PDF/hpdf_mmgr.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_mmgr.h + * << Haru Free PDF Library >> -- hpdf_mmgr.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_namedict.h b/PDF/include/Poco/PDF/hpdf_namedict.h new file mode 100644 index 000000000..179d103df --- /dev/null +++ b/PDF/include/Poco/PDF/hpdf_namedict.h @@ -0,0 +1,76 @@ +/* + * << Haru Free PDF Library >> -- hpdf_namedict.h + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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. + * + */ + +#ifndef _HPDF_NAMEDICT_H +#define _HPDF_NAMEDICT_H + +#include "hpdf_objects.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +HPDF_NameDict +HPDF_NameDict_New (HPDF_MMgr mmgr, + HPDF_Xref xref); + +HPDF_NameTree +HPDF_NameDict_GetNameTree (HPDF_NameDict namedict, + HPDF_NameDictKey key); + +HPDF_STATUS +HPDF_NameDict_SetNameTree (HPDF_NameDict namedict, + HPDF_NameDictKey key, + HPDF_NameTree tree); + +HPDF_BOOL +HPDF_NameDict_Validate (HPDF_NameDict namedict); + + +/*------- NameTree -------*/ + +HPDF_NameTree +HPDF_NameTree_New (HPDF_MMgr mmgr, + HPDF_Xref xref); + +HPDF_STATUS +HPDF_NameTree_Add (HPDF_NameTree tree, + HPDF_String name, + void *obj); + +HPDF_BOOL +HPDF_NameTree_Validate (HPDF_NameTree tree); + + +/*------- EmbeddedFile -------*/ + +HPDF_EmbeddedFile +HPDF_EmbeddedFile_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + const char *file); + +HPDF_BOOL +HPDF_EmbeddedFile_Validate (HPDF_EmbeddedFile emfile); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _HPDF_NAMEDICT_H */ + diff --git a/PDF/include/Poco/PDF/hpdf_objects.h b/PDF/include/Poco/PDF/hpdf_objects.h index aaa11c966..525adda0c 100644 --- a/PDF/include/Poco/PDF/hpdf_objects.h +++ b/PDF/include/Poco/PDF/hpdf_objects.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.5 >> -- hpdf_objects.c + * << Haru Free PDF Library >> -- hpdf_objects.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -56,6 +59,8 @@ extern "C" { #define HPDF_OSUBCLASS_ENCRYPT 0x0900 #define HPDF_OSUBCLASS_EXT_GSTATE 0x0A00 #define HPDF_OSUBCLASS_EXT_GSTATE_R 0x0B00 /* read only object */ +#define HPDF_OSUBCLASS_NAMEDICT 0x0C00 +#define HPDF_OSUBCLASS_NAMETREE 0x0D00 @@ -268,10 +273,9 @@ HPDF_String_Write (HPDF_String obj, HPDF_Stream stream, HPDF_Encrypt e); - -HPDF_STATUS -HPDF_String_SetValue (HPDF_String obj, - const char *value); +HPDF_INT32 +HPDF_String_Cmp (HPDF_String s1, + HPDF_String s2); /*---------------------------------------------------------------------------*/ @@ -386,6 +390,10 @@ void HPDF_Array_Clear (HPDF_Array array); +HPDF_UINT +HPDF_Array_Items (HPDF_Array array); + + /*---------------------------------------------------------------------------*/ /*----- HPDF_Dict -----------------------------------------------------------*/ @@ -417,6 +425,7 @@ typedef struct _HPDF_Dict_Rec { HPDF_Dict_FreeFunc free_fn; HPDF_Stream stream; HPDF_UINT filter; + HPDF_Dict filterParams; void *attr; } HPDF_Dict_Rec; @@ -568,16 +577,24 @@ HPDF_Xref_GetEntryByObjectId (HPDF_Xref xref, +typedef HPDF_Dict HPDF_EmbeddedFile; +typedef HPDF_Dict HPDF_NameDict; +typedef HPDF_Dict HPDF_NameTree; typedef HPDF_Dict HPDF_Pages; typedef HPDF_Dict HPDF_Page; typedef HPDF_Dict HPDF_Annotation; +typedef HPDF_Dict HPDF_3DMeasure; +typedef HPDF_Dict HPDF_ExData; typedef HPDF_Dict HPDF_XObject; typedef HPDF_Dict HPDF_Image; typedef HPDF_Dict HPDF_Outline; typedef HPDF_Dict HPDF_EncryptDict; typedef HPDF_Dict HPDF_Action; typedef HPDF_Dict HPDF_ExtGState; -typedef HPDF_Array HPDF_Destination; +typedef HPDF_Array HPDF_Destination; +typedef HPDF_Dict HPDF_U3D; +typedef HPDF_Dict HPDF_OutputIntent; +typedef HPDF_Dict HPDF_JavaScript; #ifdef __cplusplus } diff --git a/PDF/include/Poco/PDF/hpdf_outline.h b/PDF/include/Poco/PDF/hpdf_outline.h index 0e8db6381..18cdb08de 100644 --- a/PDF/include/Poco/PDF/hpdf_outline.h +++ b/PDF/include/Poco/PDF/hpdf_outline.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_outline.h + * << Haru Free PDF Library >> -- hpdf_outline.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_page_label.h b/PDF/include/Poco/PDF/hpdf_page_label.h index 14fb22985..05f454fca 100644 --- a/PDF/include/Poco/PDF/hpdf_page_label.h +++ b/PDF/include/Poco/PDF/hpdf_page_label.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_page_label.h + * << Haru Free PDF Library >> -- hpdf_page_label.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/include/Poco/PDF/hpdf_pages.h b/PDF/include/Poco/PDF/hpdf_pages.h index df355ab6d..44b816c2c 100644 --- a/PDF/include/Poco/PDF/hpdf_pages.h +++ b/PDF/include/Poco/PDF/hpdf_pages.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_pages.c + * << Haru Free PDF Library >> -- hpdf_pages.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -62,7 +65,7 @@ typedef struct _HPDF_PageAttr_Rec { HPDF_Stream stream; HPDF_Xref xref; HPDF_UINT compression_mode; - HPDF_PDFVer *ver; + HPDF_PDFVer *ver; } HPDF_PageAttr_Rec; diff --git a/PDF/include/Poco/PDF/hpdf_pdfa.h b/PDF/include/Poco/PDF/hpdf_pdfa.h new file mode 100644 index 000000000..8566a3745 --- /dev/null +++ b/PDF/include/Poco/PDF/hpdf_pdfa.h @@ -0,0 +1,43 @@ +/* + * << Haru Free PDF Library >> -- hpdf_pdfa.h + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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. + * + */ + +#ifndef _HPDF_PDFA_H +#define _HPDF_PDFA_H + +#include "hpdf_doc.h" +#include "hpdf_objects.h" + + + +#ifdef __cplusplus +extern "C" { +#endif + +HPDF_STATUS +HPDF_PDFA_AppendOutputIntents(HPDF_Doc pdf, const char *iccname, HPDF_Dict iccdict); + +HPDF_STATUS +HPDF_PDFA_SetPDFAConformance (HPDF_Doc pdf, + HPDF_PDFAType pdfatype); + +HPDF_STATUS +HPDF_PDFA_GenerateID(HPDF_Doc); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/PDF/include/Poco/PDF/hpdf_streams.h b/PDF/include/Poco/PDF/hpdf_streams.h index 08cf73236..a24d046f3 100644 --- a/PDF/include/Poco/PDF/hpdf_streams.h +++ b/PDF/include/Poco/PDF/hpdf_streams.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_streams.h + * << Haru Free PDF Library >> -- hpdf_streams.h * - * Copyright (c) 1999-2004 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -31,7 +34,7 @@ typedef enum _HPDF_StreamType { HPDF_STREAM_UNKNOWN = 0, HPDF_STREAM_CALLBACK, HPDF_STREAM_FILE, - HPDF_STREAM_MEMORY, + HPDF_STREAM_MEMORY } HPDF_StreamType; #define HPDF_STREAM_FILTER_NONE 0x0000 @@ -39,6 +42,7 @@ typedef enum _HPDF_StreamType { #define HPDF_STREAM_FILTER_ASCII85 0x0200 #define HPDF_STREAM_FILTER_FLATE_DECODE 0x0400 #define HPDF_STREAM_FILTER_DCT_DECODE 0x0800 +#define HPDF_STREAM_FILTER_CCITT_DECODE 0x1000 typedef enum _HPDF_WhenceMode { HPDF_SEEK_SET = 0, diff --git a/PDF/include/Poco/PDF/hpdf_types.h b/PDF/include/Poco/PDF/hpdf_types.h index 6d94546ad..8b3e0a893 100644 --- a/PDF/include/Poco/PDF/hpdf_types.h +++ b/PDF/include/Poco/PDF/hpdf_types.h @@ -1,9 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_types.h + * << Haru Free PDF Library >> -- hpdf_types.h * - * URL http://libharu.sourceforge.net/ + * URL: http://libharu.org * - * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -107,6 +108,14 @@ typedef struct _HPDF_Rect { HPDF_REAL top; } HPDF_Rect; +/* HPDF_Point3D struct +*/ +typedef struct _HPDF_Point3D { + HPDF_REAL x; + HPDF_REAL y; + HPDF_REAL z; +} HPDF_Point3D; + typedef struct _HPDF_Rect HPDF_Box; /* HPDF_Date struct @@ -136,9 +145,19 @@ typedef enum _HPDF_InfoType { HPDF_INFO_TITLE, HPDF_INFO_SUBJECT, HPDF_INFO_KEYWORDS, + HPDF_INFO_TRAPPED, + HPDF_INFO_GTS_PDFX, HPDF_INFO_EOF } HPDF_InfoType; +/* PDF-A Types */ + +typedef enum _HPDF_PDFA_TYPE +{ + HPDF_PDFA_1A = 0, + HPDF_PDFA_1B = 1 +} HPDF_PDFAType; + typedef enum _HPDF_PdfVer { HPDF_VER_12 = 0, @@ -146,6 +165,7 @@ typedef enum _HPDF_PdfVer { HPDF_VER_14, HPDF_VER_15, HPDF_VER_16, + HPDF_VER_17, HPDF_VER_EOF } HPDF_PDFVer; @@ -290,6 +310,8 @@ typedef enum _HPDF_PageLayout { HPDF_PAGE_LAYOUT_ONE_COLUMN, HPDF_PAGE_LAYOUT_TWO_COLUMN_LEFT, HPDF_PAGE_LAYOUT_TWO_COLUMN_RIGHT, + HPDF_PAGE_LAYOUT_TWO_PAGE_LEFT, + HPDF_PAGE_LAYOUT_TWO_PAGE_RIGHT, HPDF_PAGE_LAYOUT_EOF } HPDF_PageLayout; @@ -342,7 +364,11 @@ typedef enum _HPDF_AnnotType { HPDF_ANNOT_UNDERLINE, HPDF_ANNOT_INK, HPDF_ANNOT_FILE_ATTACHMENT, - HPDF_ANNOT_POPUP + HPDF_ANNOT_POPUP, + HPDF_ANNOT_3D, + HPDF_ANNOT_SQUIGGLY, + HPDF_ANNOT_LINE, + HPDF_ANNOT_PROJECTION } HPDF_AnnotType; @@ -377,7 +403,50 @@ typedef enum _HPDF_AnnotIcon { HPDF_ANNOT_ICON_EOF } HPDF_AnnotIcon; +typedef enum _HPDF_AnnotIntent { + HPDF_ANNOT_INTENT_FREETEXTCALLOUT = 0, + HPDF_ANNOT_INTENT_FREETEXTTYPEWRITER, + HPDF_ANNOT_INTENT_LINEARROW, + HPDF_ANNOT_INTENT_LINEDIMENSION, + HPDF_ANNOT_INTENT_POLYGONCLOUD, + HPDF_ANNOT_INTENT_POLYLINEDIMENSION, + HPDF_ANNOT_INTENT_POLYGONDIMENSION +} HPDF_AnnotIntent; +typedef enum _HPDF_LineAnnotEndingStyle { + HPDF_LINE_ANNOT_NONE = 0, + HPDF_LINE_ANNOT_SQUARE, + HPDF_LINE_ANNOT_CIRCLE, + HPDF_LINE_ANNOT_DIAMOND, + HPDF_LINE_ANNOT_OPENARROW, + HPDF_LINE_ANNOT_CLOSEDARROW, + HPDF_LINE_ANNOT_BUTT, + HPDF_LINE_ANNOT_ROPENARROW, + HPDF_LINE_ANNOT_RCLOSEDARROW, + HPDF_LINE_ANNOT_SLASH +} HPDF_LineAnnotEndingStyle; + +typedef enum _HPDF_LineAnnotCapPosition{ + HPDF_LINE_ANNOT_CAP_INLINE = 0, + HPDF_LINE_ANNOT_CAP_TOP +} HPDF_LineAnnotCapPosition; + +typedef enum _HPDF_StampAnnotName{ + HPDF_STAMP_ANNOT_APPROVED = 0, + HPDF_STAMP_ANNOT_EXPERIMENTAL, + HPDF_STAMP_ANNOT_NOTAPPROVED, + HPDF_STAMP_ANNOT_ASIS, + HPDF_STAMP_ANNOT_EXPIRED, + HPDF_STAMP_ANNOT_NOTFORPUBLICRELEASE, + HPDF_STAMP_ANNOT_CONFIDENTIAL, + HPDF_STAMP_ANNOT_FINAL, + HPDF_STAMP_ANNOT_SOLD, + HPDF_STAMP_ANNOT_DEPARTMENTAL, + HPDF_STAMP_ANNOT_FORCOMMENT, + HPDF_STAMP_ANNOT_TOPSECRET, + HPDF_STAMP_ANNOT_DRAFT, + HPDF_STAMP_ANNOT_FORPUBLICRELEASE +} HPDF_StampAnnotName; /*----------------------------------------------------------------------------*/ /*------ border stype --------------------------------------------------------*/ @@ -430,7 +499,7 @@ typedef enum _HPDF_TransitionStyle { HPDF_TS_GLITTER_TOP_LEFT_TO_BOTTOM_RIGHT, HPDF_TS_REPLACE, HPDF_TS_EOF -} HPDF_TransitionStyle; +} HPDF_TransitionStyle; /*----------------------------------------------------------------------------*/ @@ -480,6 +549,14 @@ typedef enum _HPDF_TextAlignment { HPDF_TALIGN_JUSTIFY } HPDF_TextAlignment; +/*----------------------------------------------------------------------------*/ + +/* Name Dictionary values -- see PDF reference section 7.7.4 */ +typedef enum _HPDF_NameDictKey { + HPDF_NAME_EMBEDDED_FILES = 0, /* TODO the rest */ + HPDF_NAME_EOF +} HPDF_NameDictKey; + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/PDF/include/Poco/PDF/hpdf_u3d.h b/PDF/include/Poco/PDF/hpdf_u3d.h new file mode 100644 index 000000000..9a3dba869 --- /dev/null +++ b/PDF/include/Poco/PDF/hpdf_u3d.h @@ -0,0 +1,53 @@ +/* + * << Haru Free PDF Library >> -- hpdf_u3d.h + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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. + * + */ + +#ifndef _HPDF_U3D_H +#define _HPDF_U3D_H + +#include "hpdf_objects.h" + +#ifdef __cplusplus +extern "C" { +#endif + +HPDF_EXPORT(HPDF_JavaScript) HPDF_CreateJavaScript(HPDF_Doc pdf, const char *code); + + +HPDF_EXPORT(HPDF_U3D) HPDF_LoadU3DFromFile (HPDF_Doc pdf, const char *filename); +HPDF_EXPORT(HPDF_Image) HPDF_LoadU3DFromMem (HPDF_Doc pdf, const HPDF_BYTE *buffer, HPDF_UINT size); +HPDF_EXPORT(HPDF_Dict) HPDF_Create3DView (HPDF_MMgr mmgr, const char *name); +HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_Add3DView(HPDF_U3D u3d, HPDF_Dict view); +HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_SetDefault3DView(HPDF_U3D u3d, const char *name); +HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_AddOnInstanciate(HPDF_U3D u3d, HPDF_JavaScript javaScript); +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_AddNode(HPDF_Dict view, const char *name, HPDF_REAL opacity, HPDF_BOOL visible); +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetLighting(HPDF_Dict view, const char *scheme); +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetBackgroundColor(HPDF_Dict view, HPDF_REAL r, HPDF_REAL g, HPDF_REAL b); +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetPerspectiveProjection(HPDF_Dict view, HPDF_REAL fov); +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetOrthogonalProjection(HPDF_Dict view, HPDF_REAL mag); +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetCamera(HPDF_Dict view, HPDF_REAL coox, HPDF_REAL cooy, HPDF_REAL cooz, HPDF_REAL c2cx, HPDF_REAL c2cy, HPDF_REAL c2cz, HPDF_REAL roo, HPDF_REAL roll); + +HPDF_Dict +HPDF_3DView_New ( HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_U3D u3d, + const char *name); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _HPDF_U3D_H */ + diff --git a/PDF/include/Poco/PDF/hpdf_utils.h b/PDF/include/Poco/PDF/hpdf_utils.h index d20a86397..9028004a2 100644 --- a/PDF/include/Poco/PDF/hpdf_utils.h +++ b/PDF/include/Poco/PDF/hpdf_utils.h @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- fpdf_utils.h + * << Haru Free PDF Library >> -- fpdf_utils.h + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -15,6 +18,7 @@ #ifndef _HPDF_UTILS_H #define _HPDF_UTILS_H +#include "hpdf_config.h" #include "hpdf_types.h" #ifdef __cplusplus @@ -114,7 +118,7 @@ HPDF_UInt16Swap (HPDF_UINT16 *value); } #endif /* __cplusplus */ -#define HPDF_NEEDS_ESCAPE(c) (c < 0x21 || \ +#define HPDF_NEEDS_ESCAPE(c) (c < 0x20 || \ c > 0x7e || \ c == '\\' || \ c == '%' || \ @@ -139,11 +143,11 @@ HPDF_UInt16Swap (HPDF_UINT16 *value); /*----------------------------------------------------------------------------*/ /*----- macros for debug -----------------------------------------------------*/ -#ifdef HPDF_DEBUG +#ifdef LIBHPDF_DEBUG_TRACE #ifndef HPDF_PTRACE_ON #define HPDF_PTRACE_ON #endif /* HPDF_PTRACE_ON */ -#endif /* HPDF_DEBUG */ +#endif /* LIBHPDF_DEBUG_TRACE */ #ifdef HPDF_PTRACE_ON #define HPDF_PTRACE(ARGS) HPDF_PRINTF ARGS @@ -151,7 +155,7 @@ HPDF_UInt16Swap (HPDF_UINT16 *value); #define HPDF_PTRACE(ARGS) /* do nothing */ #endif /* HPDF_PTRACE */ -#ifdef HPDF_DEBUG +#ifdef LIBHPDF_DEBUG #define HPDF_PRINT_BINARY(BUF, LEN, CAPTION) HPDF_PrintBinary(BUF, LEN, CAPTION) #else #define HPDF_PRINT_BINARY(BUF, LEN, CAPTION) /* do nothing */ diff --git a/PDF/include/Poco/PDF/hpdf_version.h b/PDF/include/Poco/PDF/hpdf_version.h new file mode 100644 index 000000000..99a07a62d --- /dev/null +++ b/PDF/include/Poco/PDF/hpdf_version.h @@ -0,0 +1,8 @@ +/* automatically generated by configure */ +/* edit configure.in to change version number */ +#define HPDF_MAJOR_VERSION 2 +#define HPDF_MINOR_VERSION 3 +#define HPDF_BUGFIX_VERSION 0 +#define HPDF_EXTRA_VERSION "RC2" +#define HPDF_VERSION_TEXT "2.3.0RC2" +#define HPDF_VERSION_ID 20300 diff --git a/PDF/include/Poco/PDF/png.h b/PDF/include/Poco/PDF/png.h index 47fa026a2..3ac393ea3 100644 --- a/PDF/include/Poco/PDF/png.h +++ b/PDF/include/Poco/PDF/png.h @@ -400,7 +400,7 @@ #define PNG_LIBPNG_BUILD_RC 3 #define PNG_LIBPNG_BUILD_STABLE 4 #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7 - + /* Release-Specific Flags */ #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with PNG_LIBPNG_BUILD_STABLE only */ @@ -431,12 +431,12 @@ /* Ref MSDN: Private as priority over Special * VS_FF_PRIVATEBUILD File *was not* built using standard release * procedures. If this value is given, the StringFileInfo block must - * contain a PrivateBuild string. + * contain a PrivateBuild string. * * VS_FF_SPECIALBUILD File *was* built by the original company using * standard release procedures but is a variation of the standard * file of the same version number. If this value is given, the - * StringFileInfo block must contain a SpecialBuild string. + * StringFileInfo block must contain a SpecialBuild string. */ #if defined(PNG_USER_PRIVATEBUILD) @@ -911,7 +911,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) /* The sCAL chunk describes the actual physical dimensions of the * subject matter of the graphic. The chunk contains a unit specification * a byte value, and two ASCII strings representing floating-point - * values. The values are width and height corresponding to one pixel + * values. The values are width and height corresponsing to one pixel * in the image. This external representation is converted to double * here. Data values are valid if (valid & PNG_INFO_sCAL) is non-zero. */ diff --git a/PDF/include/Poco/PDF/pngconf.h b/PDF/include/Poco/PDF/pngconf.h index 9fbae8b61..c40507446 100644 --- a/PDF/include/Poco/PDF/pngconf.h +++ b/PDF/include/Poco/PDF/pngconf.h @@ -19,7 +19,7 @@ #define PNG_1_2_X -/* +/* * PNG_USER_CONFIG has to be defined on the compiler command line. This * includes the resource compiler for Windows DLL configurations. */ @@ -39,7 +39,7 @@ /* * Added at libpng-1.2.8 - * + * * If you create a private DLL you need to define in "pngusr.h" the followings: * #define PNG_USER_PRIVATEBUILD @@ -50,8 +50,8 @@ * number and must match your private DLL name> * e.g. // private DLL "libpng13gx.dll" * #define PNG_USER_DLLFNAME_POSTFIX "gx" - * - * The following macros are also at your disposal if you want to complete the + * + * The following macros are also at your disposal if you want to complete the * DLL VERSIONINFO structure. * - PNG_USER_VERSIONINFO_COMMENTS * - PNG_USER_VERSIONINFO_COMPANYNAME @@ -147,9 +147,9 @@ * 'Cygwin' defines/defaults: * PNG_BUILD_DLL -- (ignored) building the dll * (no define) -- (ignored) building an application, linking to the dll - * PNG_STATIC -- (ignored) building the static lib, or building an + * PNG_STATIC -- (ignored) building the static lib, or building an * application that links to the static lib. - * ALL_STATIC -- (ignored) building various static libs, or building an + * ALL_STATIC -- (ignored) building various static libs, or building an * application that links to the static libs. * Thus, * a cygwin user should define either PNG_BUILD_DLL or PNG_STATIC, and @@ -162,12 +162,12 @@ * PNG_BUILD_DLL * PNG_STATIC * (nothing) == PNG_USE_DLL - * + * * CYGWIN (2002-01-20): The preceding is now obsolete. With the advent - * of auto-import in binutils, we no longer need to worry about + * of auto-import in binutils, we no longer need to worry about * __declspec(dllexport) / __declspec(dllimport) and friends. Therefore, * we don't need to worry about PNG_STATIC or ALL_STATIC when it comes - * to __declspec() stuff. However, we DO need to worry about + * to __declspec() stuff. However, we DO need to worry about * PNG_BUILD_DLL and PNG_STATIC because those change some defaults * such as CONSOLE_IO and whether GLOBAL_ARRAYS are allowed. */ @@ -211,8 +211,8 @@ # if !defined(PNG_DLL) # define PNG_DLL # endif -# endif -# endif +# endif +# endif # endif #endif @@ -731,7 +731,7 @@ # define PNG_EASY_ACCESS_SUPPORTED #endif -/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0 +/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0 * and removed from version 1.2.20. The following will be removed * from libpng-1.4.0 */ @@ -829,7 +829,7 @@ */ /* Any chunks you are not interested in, you can undef here. The - * ones that allocate memory may be especially important (hIST, + * ones that allocate memory may be expecially important (hIST, * tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info * a bit smaller. */ @@ -1306,7 +1306,7 @@ typedef z_stream FAR * png_zstreamp; # define PNGAPI __cdecl # undef PNG_IMPEXP # define PNG_IMPEXP -#endif +#endif /* If you define PNGAPI, e.g., with compiler option "-DPNGAPI=__stdcall", * you may get warnings regarding the linkage of png_zalloc and png_zfree. diff --git a/PDF/samples/Image/Image.pdf b/PDF/samples/Image/Image.pdf new file mode 100644 index 000000000..314adc172 Binary files /dev/null and b/PDF/samples/Image/Image.pdf differ diff --git a/PDF/samples/Image/Image.progen b/PDF/samples/Image/Image.progen deleted file mode 100644 index 8749e7c75..000000000 --- a/PDF/samples/Image/Image.progen +++ /dev/null @@ -1,10 +0,0 @@ -vc.project.guid = ${vc.project.guidFromName} -vc.project.name = ${vc.project.baseName} -vc.project.target = ${vc.project.name} -vc.project.type = executable -vc.project.pocobase = ..\\..\\.. -vc.project.platforms = Win32, x64 -vc.project.configurations = debug_shared, release_shared, debug_static_mt, release_static_mt, debug_static_md, release_static_md -vc.project.prototype = ${vc.project.name}_vs90.vcproj -vc.project.compiler.include = ..\\..\\..\\Foundation\\include;..\\..\\..\\PDF\\include -vc.project.linker.dependencies = diff --git a/PDF/samples/Image/Image_vs140.vcxproj.filters b/PDF/samples/Image/Image_vs140.vcxproj.filters index c6c313737..1f507eb04 100644 --- a/PDF/samples/Image/Image_vs140.vcxproj.filters +++ b/PDF/samples/Image/Image_vs140.vcxproj.filters @@ -2,10 +2,10 @@ - {3e187bb0-1d2b-4a01-ba2b-3675ce2c1c84} + {2e38e39e-14e5-4544-be3f-1903c2fa8fa5} - {98c2cbaf-7e65-4bce-add0-cc6b755fd70e} + {d4825186-6266-4146-9a77-b4fb64b2d0ba} diff --git a/PDF/samples/Image/Image_vs150.vcxproj.filters b/PDF/samples/Image/Image_vs150.vcxproj.filters index c6c313737..1f507eb04 100644 --- a/PDF/samples/Image/Image_vs150.vcxproj.filters +++ b/PDF/samples/Image/Image_vs150.vcxproj.filters @@ -2,10 +2,10 @@ - {3e187bb0-1d2b-4a01-ba2b-3675ce2c1c84} + {2e38e39e-14e5-4544-be3f-1903c2fa8fa5} - {98c2cbaf-7e65-4bce-add0-cc6b755fd70e} + {d4825186-6266-4146-9a77-b4fb64b2d0ba} diff --git a/PDF/samples/Image/Image_x64_vs140.vcxproj.filters b/PDF/samples/Image/Image_x64_vs140.vcxproj.filters index ab12fa327..952dde03f 100644 --- a/PDF/samples/Image/Image_x64_vs140.vcxproj.filters +++ b/PDF/samples/Image/Image_x64_vs140.vcxproj.filters @@ -2,10 +2,10 @@ - {04d30b11-8aca-41d2-92dc-bdd1e46f2d2e} + {77c73edd-e907-4bfa-9faa-ea733f5f76d9} - {caa26a08-07f7-41eb-b223-2d2aa5e686f8} + {0531a35b-9ad3-4753-aded-84ca49e9d694} diff --git a/PDF/samples/Image/Image_x64_vs150.vcxproj.filters b/PDF/samples/Image/Image_x64_vs150.vcxproj.filters index ab12fa327..952dde03f 100644 --- a/PDF/samples/Image/Image_x64_vs150.vcxproj.filters +++ b/PDF/samples/Image/Image_x64_vs150.vcxproj.filters @@ -2,10 +2,10 @@ - {04d30b11-8aca-41d2-92dc-bdd1e46f2d2e} + {77c73edd-e907-4bfa-9faa-ea733f5f76d9} - {caa26a08-07f7-41eb-b223-2d2aa5e686f8} + {0531a35b-9ad3-4753-aded-84ca49e9d694} diff --git a/PDF/samples/Image/src/Image.cpp b/PDF/samples/Image/src/Image.cpp index ca9fcc300..e5854ecd4 100644 --- a/PDF/samples/Image/src/Image.cpp +++ b/PDF/samples/Image/src/Image.cpp @@ -1,16 +1,13 @@ // // Image.cpp // -// This sample demonstrates the Data library. +// This sample demonstrates the generation and saving of a PDF +// document that contains an mbedded image loaded from external file. // -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// All rights reserved. +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. // -// This is unpublished proprietary source code of Applied Informatics -// Software Engineering GmbH. -// The contents of this pdfFile may not be disclosed to third parties, -// copied or duplicated in any form, in whole or in part, without -// prior written permission from Applied Informatics. +// SPDX-License-Identifier: BSL-1.0 // #include "Poco/PDF/Document.h" diff --git a/PDF/samples/Text/DejaVuLGCSans.ttf b/PDF/samples/Text/DejaVuLGCSans.ttf new file mode 100644 index 000000000..0cf18a8b1 Binary files /dev/null and b/PDF/samples/Text/DejaVuLGCSans.ttf differ diff --git a/PDF/samples/Text/Text.pdf b/PDF/samples/Text/Text.pdf new file mode 100644 index 000000000..f8f746ddd Binary files /dev/null and b/PDF/samples/Text/Text.pdf differ diff --git a/PDF/samples/Text/Text.progen b/PDF/samples/Text/Text.progen deleted file mode 100644 index 8749e7c75..000000000 --- a/PDF/samples/Text/Text.progen +++ /dev/null @@ -1,10 +0,0 @@ -vc.project.guid = ${vc.project.guidFromName} -vc.project.name = ${vc.project.baseName} -vc.project.target = ${vc.project.name} -vc.project.type = executable -vc.project.pocobase = ..\\..\\.. -vc.project.platforms = Win32, x64 -vc.project.configurations = debug_shared, release_shared, debug_static_mt, release_static_mt, debug_static_md, release_static_md -vc.project.prototype = ${vc.project.name}_vs90.vcproj -vc.project.compiler.include = ..\\..\\..\\Foundation\\include;..\\..\\..\\PDF\\include -vc.project.linker.dependencies = diff --git a/PDF/samples/Text/Text_vs140.vcxproj.filters b/PDF/samples/Text/Text_vs140.vcxproj.filters index 9bad9d4f8..5a7180933 100644 --- a/PDF/samples/Text/Text_vs140.vcxproj.filters +++ b/PDF/samples/Text/Text_vs140.vcxproj.filters @@ -2,10 +2,10 @@ - {c3ea6789-01d4-4bcf-9fe7-c011c458e565} + {4c4db3d3-ea83-4452-8c9f-b73ebbafe843} - {6f12f7ad-3ab0-4ce8-b573-8c77781dff88} + {31d158d4-1a35-4d7a-a9eb-1447d82290f6} diff --git a/PDF/samples/Text/Text_vs150.vcxproj.filters b/PDF/samples/Text/Text_vs150.vcxproj.filters index 9bad9d4f8..5a7180933 100644 --- a/PDF/samples/Text/Text_vs150.vcxproj.filters +++ b/PDF/samples/Text/Text_vs150.vcxproj.filters @@ -2,10 +2,10 @@ - {c3ea6789-01d4-4bcf-9fe7-c011c458e565} + {4c4db3d3-ea83-4452-8c9f-b73ebbafe843} - {6f12f7ad-3ab0-4ce8-b573-8c77781dff88} + {31d158d4-1a35-4d7a-a9eb-1447d82290f6} diff --git a/PDF/samples/Text/Text_x64_vs140.vcxproj.filters b/PDF/samples/Text/Text_x64_vs140.vcxproj.filters index 7c71a2053..9479c1270 100644 --- a/PDF/samples/Text/Text_x64_vs140.vcxproj.filters +++ b/PDF/samples/Text/Text_x64_vs140.vcxproj.filters @@ -2,10 +2,10 @@ - {e9f525fd-6b5c-4c75-b127-151e5723b951} + {03d7e5f2-118d-4ff0-ae9a-8ea1c05b9580} - {a4fb5caa-2dbd-481c-bade-9b11ea193129} + {fa61639f-1a64-4692-b040-e61923e163cf} diff --git a/PDF/samples/Text/Text_x64_vs150.vcxproj.filters b/PDF/samples/Text/Text_x64_vs150.vcxproj.filters index 7c71a2053..9479c1270 100644 --- a/PDF/samples/Text/Text_x64_vs150.vcxproj.filters +++ b/PDF/samples/Text/Text_x64_vs150.vcxproj.filters @@ -2,10 +2,10 @@ - {e9f525fd-6b5c-4c75-b127-151e5723b951} + {03d7e5f2-118d-4ff0-ae9a-8ea1c05b9580} - {a4fb5caa-2dbd-481c-bade-9b11ea193129} + {fa61639f-1a64-4692-b040-e61923e163cf} diff --git a/PDF/samples/Text/src/Text.cpp b/PDF/samples/Text/src/Text.cpp index f26398d66..a6f75a07a 100644 --- a/PDF/samples/Text/src/Text.cpp +++ b/PDF/samples/Text/src/Text.cpp @@ -1,16 +1,12 @@ -// // Text.cpp // -// This sample demonstrates the Data library. +// This sample demonstrates the generation and saving of a text PDF +// document, using external TTF font and UTF-8 encoding. // -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// All rights reserved. +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. // -// This is unpublished proprietary source code of Applied Informatics -// Software Engineering GmbH. -// The contents of this file may not be disclosed to third parties, -// copied or duplicated in any form, in whole or in part, without -// prior written permission from Applied Informatics. +// SPDX-License-Identifier: BSL-1.0 // #include "Poco/PDF/Document.h" @@ -39,13 +35,16 @@ int main(int argc, char** argv) Document document(file.path()); - Font helv = document.font("Helvetica"); + Font font = document.font(document.loadTTFont("DejaVuLGCSans.ttf", true), "UTF-8"); Page page = document[0]; - page.setFont(helv, 24); + page.setFont(font, 24); std::string hello = "Hello PDF World from C++ Portable Components"; float tw = page.textWidth(hello); page.writeOnce((page.getWidth() - tw) / 2, page.getHeight() - 50, hello); - + page.setFont(font, 14); + hello = "~ Courtesy of G\xC3\xBCnter Obiltschnig & Aleksandar Fabijani\xC4\x87 ~"; + tw = page.textWidth(hello); + page.writeOnce((page.getWidth() - tw) / 2, page.getHeight() - 100, hello); document.save(); return 0; } diff --git a/PDF/samples/build.gradle b/PDF/samples/build.gradle new file mode 100644 index 000000000..f76ecb555 --- /dev/null +++ b/PDF/samples/build.gradle @@ -0,0 +1,34 @@ +model { + components { + Image(NativeExecutableSpec) { + sources { + cpp.source { srcDir 'Image/src' include '**/*.cpp' } + cpp.lib project: ':PDF', library: 'PDF' + cpp.lib project: ':Foundation', library: 'Foundation' + } + } + Text(NativeExecutableSpec) { + sources { + cpp.source { srcDir 'Image/src' include '**/*.cpp' } + cpp.lib project: ':PDF', library: 'PDF' + cpp.lib project: ':Foundation', library: 'Foundation' + } + } + } + binaries { + all { + } + withType(SharedLibraryBinarySpec) { + lib project: ':Foundation', library: 'Foundation', linkage: 'shared' + } + withType(StaticLibraryBinarySpec) { + lib project: ':Foundation', library: 'Foundation', linkage: 'static' + } + withType(NativeExecutableSpec) { + lib project: ':Foundation', library: 'Foundation', linkage: 'static' + } + } +} +task samples { dependsOn "assemble" } + + diff --git a/PDF/samples/samples.progen b/PDF/samples/samples.progen deleted file mode 100644 index 1af0b9211..000000000 --- a/PDF/samples/samples.progen +++ /dev/null @@ -1,6 +0,0 @@ -vc.project.platforms = Win32, x64 -vc.project.configurations = debug_shared, release_shared, debug_static_mt, release_static_mt, debug_static_md, release_static_md -vc.solution.create = true -vc.solution.include = \ - Image\\Image;\ - Text\\Text; diff --git a/PDF/src/Destination.cpp b/PDF/src/Destination.cpp index 192f6eab5..ddfef4d8d 100644 --- a/PDF/src/Destination.cpp +++ b/PDF/src/Destination.cpp @@ -21,7 +21,7 @@ namespace PDF { Destination::Destination(HPDF_Doc* pPDF, const HPDF_Destination& destination, - const std::string& name): + const std::string& name): Resource(pPDF, destination, name) { } diff --git a/PDF/src/Document.cpp b/PDF/src/Document.cpp index c225a0c27..a96a219ed 100644 --- a/PDF/src/Document.cpp +++ b/PDF/src/Document.cpp @@ -30,28 +30,24 @@ namespace PDF { Document::Document(const std::string fileName, Poco::UInt32 pageCount, Page::Size pageSize, - Page::Orientation orientation): + Page::Orientation orientation): _pdf(HPDF_New(HPDF_Error_Handler, 0)), _fileName(fileName), _pRawData(0), _size(0) { - compression(COMPRESSION_ALL); - for (Poco::UInt32 i = 0; i < pageCount; ++i) - addPage(pageSize, orientation); + init(pageCount, pageSize, orientation); } Document::Document(Poco::UInt32 pageCount, Page::Size pageSize, - Page::Orientation orientation): + Page::Orientation orientation): _pdf(HPDF_New(HPDF_Error_Handler, 0)), _pRawData(0), _size(0) { - compression(COMPRESSION_ALL); - for (Poco::UInt32 i = 0; i < pageCount; ++i) - addPage(); + init(pageCount, pageSize, orientation); } @@ -62,6 +58,16 @@ Document::~Document() } +void Document::init(Poco::UInt32 pageCount, + Page::Size pageSize, Page::Orientation orientation) +{ + useUTF8Encoding(); + compression(COMPRESSION_ALL); + for (Poco::UInt32 i = 0; i < pageCount; ++i) + addPage(pageSize, orientation); +} + + void Document::createNew(bool resetAll) { reset(resetAll); @@ -99,7 +105,7 @@ Document::SizeType Document::size() const Page& Document::addPage(Page::Size pageSize, Page::Orientation orientation) { - Page page(&_pdf, HPDF_AddPage(_pdf), pageSize); + Page page(this, HPDF_AddPage(_pdf), pageSize); page.setSizeAndOrientation(pageSize, orientation); _pages.push_back(page); return _pages.back(); @@ -114,7 +120,7 @@ const Page& Document::insertPage(int index, poco_assert (index < _pages.size()); HPDF_Page target = *((HPDF_Page*) HPDF_List_ItemAt(_pdf->page_list, static_cast(index))); return *_pages.insert(_pages.begin() + index, - Page(&_pdf, + Page(this, HPDF_InsertPage(_pdf, target), pageSize, orientation)); @@ -123,7 +129,7 @@ const Page& Document::insertPage(int index, const Page& Document::getCurrentPage() { - Page p(&_pdf, HPDF_GetCurrentPage(_pdf)); + Page p(this, HPDF_GetCurrentPage(_pdf)); PageContainer::iterator it = _pages.begin(); PageContainer::iterator end = _pages.end(); for (;it != end; ++it) @@ -136,7 +142,7 @@ const Page& Document::getCurrentPage() const Font& Document::loadFont(const std::string& name, const std::string& encoding) { Font font(&_pdf, HPDF_GetFont(_pdf, name.c_str(), encoding.empty() ? 0 : encoding.c_str())); - std::pair ret = + std::pair ret = _fonts.insert(FontContainer::value_type(name, font)); if (ret.second) return ret.first->second; @@ -149,7 +155,7 @@ const Font& Document::font(const std::string& name, const std::string& encoding) { FontContainer::iterator it = _fonts.find(name); if (_fonts.end() != it) return it->second; - + return loadFont(name, encoding); } @@ -160,20 +166,20 @@ std::string Document::loadType1Font(const std::string& afmFileName, const std::s } -std::string Document::loadTTFont(const std::string& fileName, bool embedding, int index) +std::string Document::loadTTFont(const std::string& fileName, bool embed, int index) { if (-1 == index) { return HPDF_LoadTTFontFromFile(_pdf, fileName.c_str(), - embedding ? HPDF_TRUE : HPDF_FALSE); + embed ? HPDF_TRUE : HPDF_FALSE); } else if (index >= 0) { - return HPDF_LoadTTFontFromFile2(_pdf, - fileName.c_str(), - static_cast(index), - embedding ? HPDF_TRUE : HPDF_FALSE); + return HPDF_LoadTTFontFromFile2(_pdf, + fileName.c_str(), + static_cast(index), + embed ? HPDF_TRUE : HPDF_FALSE); } else throw InvalidArgumentException("Invalid font index."); @@ -200,7 +206,7 @@ const Image& Document::loadPNGImageImpl(const std::string& fileName, bool doLoad if (it.second) return it.first->second; else throw IllegalStateException("Could not insert image."); } - else + else throw NotFoundException("File not found: " + fileName); } @@ -217,7 +223,7 @@ const Image& Document::loadJPEGImage(const std::string& fileName) if (it.second) return it.first->second; else throw IllegalStateException("Could not insert image."); } - else + else throw NotFoundException("File not found: " + fileName); } @@ -239,7 +245,7 @@ const Encoder& Document::loadEncoder(const std::string& name) if (_encoders.end() == it) return it->second; Encoder enc(&_pdf, HPDF_GetEncoder(_pdf, name.c_str()), name); - std::pair ret = + std::pair ret = _encoders.insert(EncoderContainer::value_type(name, enc)); if (ret.second) return ret.first->second; diff --git a/PDF/src/Encoder.cpp b/PDF/src/Encoder.cpp index d4bc352ba..1d05fc246 100644 --- a/PDF/src/Encoder.cpp +++ b/PDF/src/Encoder.cpp @@ -21,7 +21,7 @@ namespace PDF { Encoder::Encoder(HPDF_Doc* pPDF, const HPDF_Encoder& encoder, - const std::string& name): + const std::string& name): Resource(pPDF, encoder, name) { } diff --git a/PDF/src/Font.cpp b/PDF/src/Font.cpp index 08ad85cbc..27d3131b3 100644 --- a/PDF/src/Font.cpp +++ b/PDF/src/Font.cpp @@ -19,7 +19,7 @@ namespace Poco { namespace PDF { -Font::Font(HPDF_Doc* pPDF, const HPDF_Font& font): +Font::Font(HPDF_Doc* pPDF, const HPDF_Font& font): Resource(pPDF, font, HPDF_Font_GetFontName(font)) { } diff --git a/PDF/src/Image.cpp b/PDF/src/Image.cpp index 760f96db7..dcd05970b 100644 --- a/PDF/src/Image.cpp +++ b/PDF/src/Image.cpp @@ -19,7 +19,7 @@ namespace Poco { namespace PDF { -Image::Image(HPDF_Doc* pPDF, const HPDF_Image& resource, const std::string& name): +Image::Image(HPDF_Doc* pPDF, const HPDF_Image& resource, const std::string& name): Resource(pPDF, resource, name) { } diff --git a/PDF/src/LinkAnnotation.cpp b/PDF/src/LinkAnnotation.cpp index e95ba78a2..a0390214e 100644 --- a/PDF/src/LinkAnnotation.cpp +++ b/PDF/src/LinkAnnotation.cpp @@ -22,7 +22,7 @@ namespace PDF { LinkAnnotation::LinkAnnotation(HPDF_Doc* pPDF, const HPDF_Annotation& annotation, - const std::string& name): + const std::string& name): Resource(pPDF, annotation, name) { } diff --git a/PDF/src/Outline.cpp b/PDF/src/Outline.cpp index 7500bd301..69a874033 100644 --- a/PDF/src/Outline.cpp +++ b/PDF/src/Outline.cpp @@ -20,7 +20,7 @@ namespace Poco { namespace PDF { -Outline::Outline(HPDF_Doc* pPDF, const HPDF_Outline& outline, const std::string& name): +Outline::Outline(HPDF_Doc* pPDF, const HPDF_Outline& outline, const std::string& name): Resource(pPDF, outline, name) { open(); diff --git a/PDF/src/PDFException.cpp b/PDF/src/PDFException.cpp index f192bde33..7f109faaf 100644 --- a/PDF/src/PDFException.cpp +++ b/PDF/src/PDFException.cpp @@ -26,20 +26,20 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ { switch (error_no) { - case HPDF_ARRAY_COUNT_ERR: + case HPDF_ARRAY_COUNT_ERR: throw InvalidArgumentException("Internal error. The consistency of the data was lost."); - case HPDF_ARRAY_ITEM_NOT_FOUND: + case HPDF_ARRAY_ITEM_NOT_FOUND: throw NotFoundException("Internal error. The consistency of the data was lost."); case HPDF_ARRAY_ITEM_UNEXPECTED_TYPE: throw InvalidArgumentException("Internal error. The consistency of the data was lost."); case HPDF_BINARY_LENGTH_ERR: throw InvalidArgumentException("The length of the data exceeds HPDF_LIMIT_MAX_STRING_LEN."); case HPDF_CANNOT_GET_PALLET: - throw NotFoundException("Cannot get a pallet data from PNG image."); + throw NotFoundException("Cannot get a pallet data from PNG image."); case HPDF_DICT_COUNT_ERR: throw InvalidArgumentException("The count of elements of a dictionary exceeds HPDF_LIMIT_MAX_DICT_ELEMENT"); case HPDF_DICT_ITEM_NOT_FOUND: - throw NotFoundException("Internal error. The consistency of the data was lost."); + throw NotFoundException("Internal error. The consistency of the data was lost."); case HPDF_DICT_ITEM_UNEXPECTED_TYPE: throw InvalidArgumentException("Internal error. The consistency of the data was lost."); case HPDF_DICT_STREAM_LENGTH_NOT_FOUND: @@ -47,7 +47,7 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ case HPDF_DOC_ENCRYPTDICT_NOT_FOUND: throw NotFoundException("HPDF_SetPermission() OR HPDF_SetEncryptMode() was called before a password is set."); case HPDF_DOC_INVALID_OBJECT: - throw IllegalStateException("Internal error. The consistency of the data was lost."); + throw IllegalStateException("Internal error. The consistency of the data was lost."); case HPDF_DUPLICATE_REGISTRATION: throw IllegalStateException("Tried to register a font that has been registered."); case HPDF_EXCEED_JWW_CODE_NUM_LIMIT: @@ -55,7 +55,7 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ case HPDF_ENCRYPT_INVALID_PASSWORD: throw IllegalStateException("Tried to set the owner password to NULL."); case HPDF_ERR_UNKNOWN_CLASS: - throw InvalidArgumentException("Internal error. The consistency of the data was lost."); + throw InvalidArgumentException("Internal error. The consistency of the data was lost."); case HPDF_EXCEED_GSTATE_LIMIT: throw IllegalStateException("The depth of the stack exceeded HPDF_LIMIT_MAX_GSTATE."); case HPDF_FAILD_TO_ALLOC_MEM: @@ -65,13 +65,13 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ case HPDF_FILE_OPEN_ERROR: throw IOException("Cannot open a file. (A detailed code is set.)"); case HPDF_FONT_EXISTS: - throw IllegalStateException("Tried to load a font that has been registered."); + throw IllegalStateException("Tried to load a font that has been registered."); case HPDF_FONT_INVALID_WIDTHS_TABLE: - throw IllegalStateException("The format of a font-file is invalid. Internal error. The consistency of the data was lost."); + throw IllegalStateException("The format of a font-file is invalid. Internal error. The consistency of the data was lost."); case HPDF_INVALID_AFM_HEADER: throw IllegalStateException("Cannot recognize a header of an afm file."); case HPDF_INVALID_ANNOTATION: - throw IllegalStateException("The specified annotation handle is invalid."); + throw IllegalStateException("The specified annotation handle is invalid."); case HPDF_INVALID_BIT_PER_COMPONENT: throw IllegalStateException("Bit-per-component of a image which was set as mask-image is invalid."); case HPDF_INVALID_CHAR_MATRICS_DATA: @@ -79,11 +79,11 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ case HPDF_INVALID_COLOR_SPACE: switch (detail_no) { - case 1: + case 1: throw InvalidArgumentException("The color_space parameter of HPDF_LoadRawImage is invalid."); - case 2: + case 2: throw InvalidArgumentException("Color-space of a image which was set as mask-image is invalid."); - case 3: + case 3: throw InvalidArgumentException("The function which is invalid in the present color-space was invoked."); default: throw PDFException(); @@ -109,7 +109,7 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ case HPDF_INVALID_FONTDEF_DATA: switch (detail_no) { - case 1: + case 1: throw InvalidArgumentException("An invalid font handle was set."); case 2: throw InvalidArgumentException("Unsupported font format."); @@ -131,7 +131,7 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ { case 1: throw IllegalStateException("An invalid object is set."); - case 2: + case 2: throw IllegalStateException("Internal error. The consistency of the data was lost."); default: throw PDFException(); @@ -167,15 +167,15 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ case HPDF_INVALID_WX_DATA: throw IOException("Cannot read a width-data from an afm file."); case HPDF_ITEM_NOT_FOUND: - throw NotFoundException("Internal error. The consistency of the data was lost."); + throw NotFoundException("Internal error. The consistency of the data was lost."); case HPDF_LIBPNG_ERROR: throw IOException("An error has returned from PNGLIB while loading an image."); case HPDF_NAME_INVALID_VALUE: throw InvalidArgumentException("Internal error. The consistency of the data was lost."); case HPDF_NAME_OUT_OF_RANGE: - throw InvalidArgumentException("Internal error. The consistency of the data was lost."); + throw InvalidArgumentException("Internal error. The consistency of the data was lost."); case HPDF_PAGES_MISSING_KIDS_ENTRY: - throw IllegalStateException("Internal error. The consistency of the data was lost."); + throw IllegalStateException("Internal error. The consistency of the data was lost."); case HPDF_PAGE_CANNOT_FIND_OBJECT: throw NotFoundException("Internal error. The consistency of the data was lost."); case HPDF_PAGE_CANNOT_GET_ROOT_PAGES: @@ -197,7 +197,7 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ case HPDF_PAGE_INVALID_ROTATE_VALUE: throw InvalidArgumentException("The specified value is not a multiple of 90."); case HPDF_PAGE_INVALID_SIZE: - throw InvalidArgumentException("An invalid page-size was set."); + throw InvalidArgumentException("An invalid page-size was set."); case HPDF_PAGE_INVALID_XOBJECT: throw InvalidArgumentException("An invalid image-handle was set."); case HPDF_PAGE_OUT_OF_RANGE: @@ -219,7 +219,7 @@ void HPDF_Error_Handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_ case HPDF_TTF_INVALID_FOMAT: throw InvalidArgumentException("Unsupported ttf format."); case HPDF_TTF_MISSING_TABLE: - throw InvalidArgumentException("Unsupported ttf format. (cannot find a necessary table)"); + throw InvalidArgumentException("Unsupported ttf format. (cannot find a necessary table)"); case HPDF_UNSUPPORTED_FONT_TYPE: throw InvalidArgumentException("Internal error. The consistency of the data was lost."); case HPDF_UNSUPPORTED_FUNC: diff --git a/PDF/src/Page.cpp b/PDF/src/Page.cpp index e2c3f0b0e..a02d717ff 100644 --- a/PDF/src/Page.cpp +++ b/PDF/src/Page.cpp @@ -13,6 +13,7 @@ #include "Poco/PDF/Page.h" +#include "Poco/PDF/Document.h" #include "Poco/PDF/PDFException.h" #undef min #undef max @@ -23,24 +24,25 @@ namespace Poco { namespace PDF { -Page::Page(HPDF_Doc* pPDF, +Page::Page(Document* pDocument, const HPDF_Page& page, Size pageSize, Orientation orientation): - _pPDF(pPDF), - _page(page), - _size(pageSize), - _orientation(orientation), - _pCurrentFont(0) + _pDocument(pDocument), + _page(page), + _size(pageSize), + _orientation(orientation), + _pCurrentFont(0) { } Page::Page(const Page& other): - _pPDF(other._pPDF), + _pDocument(other._pDocument), _page(other._page), _size(other._size), - _orientation(other._orientation) + _orientation(other._orientation), + _pCurrentFont(other._pCurrentFont ? new Font(*other._pCurrentFont) : (Font*)0) { } @@ -58,14 +60,21 @@ Page& Page::operator = (const Page& page) } +bool Page::operator == (const Page& other) const +{ + return &_pDocument->handle() == &other._pDocument->handle() && _page == other._page; +} + + void Page::swap(Page& other) { using std::swap; - - swap(_pPDF, other._pPDF); + + swap(_pDocument, other._pDocument); swap(_page, other._page); swap(_size, other._size); swap(_orientation, other._orientation); + swap(_pCurrentFont, other._pCurrentFont); } @@ -97,6 +106,25 @@ float Page::textWidth(const std::string& text) } +void Page::setFont(const std::string& name, float size, const std::string& encoding) +{ + setFont(_pDocument->font(name, encoding), size); +} + + +void Page::setTTFont(const std::string& name, float size, const std::string& encoding, bool embed) +{ + setFont(_pDocument->font(_pDocument->loadTTFont(name, embed), encoding), size); +} + + +const Font& Page::getFont() const +{ + delete _pCurrentFont; + return *(_pCurrentFont = new Font(&_pDocument->handle(), HPDF_Page_GetCurrentFont(_page))); +} + + void Page::setRotation(int angle) { if (0 != angle % 90 || angle > std::numeric_limits::max()) @@ -109,11 +137,11 @@ void Page::setRotation(int angle) const Destination& Page::createDestination(const std::string& name) { DestinationContainer::iterator it = _destinations.find(name); - if (_destinations.end() != it) + if (_destinations.end() != it) throw InvalidArgumentException("Destination already exists."); - Destination dest(_pPDF, HPDF_Page_CreateDestination(_page), name); - std::pair ret = + Destination dest(&_pDocument->handle(), HPDF_Page_CreateDestination(_page), name); + std::pair ret = _destinations.insert(DestinationContainer::value_type(name, dest)); if (ret.second) return ret.first->second; @@ -122,20 +150,20 @@ const Destination& Page::createDestination(const std::string& name) } -const TextAnnotation& Page::createTextAnnotation(const std::string& name, +const TextAnnotation& Page::createTextAnnotation(const std::string& name, const Rectangle& rect, const std::string& text, const Encoder& encoder) { TextAnnotationContainer::iterator it = _textAnnotations.find(name); - if (_textAnnotations.end() != it) + if (_textAnnotations.end() != it) throw InvalidArgumentException("Annotation already exists."); - TextAnnotation ann(_pPDF, + TextAnnotation ann(&_pDocument->handle(), HPDF_Page_CreateTextAnnot(_page, rect, text.c_str(), encoder), name); - std::pair ret = + std::pair ret = _textAnnotations.insert(TextAnnotationContainer::value_type(name, ann)); if (ret.second) return ret.first->second; @@ -144,18 +172,18 @@ const TextAnnotation& Page::createTextAnnotation(const std::string& name, } -const LinkAnnotation& Page::createLinkAnnotation(const std::string& name, +const LinkAnnotation& Page::createLinkAnnotation(const std::string& name, const Rectangle& rect, const Destination& dest) { LinkAnnotationContainer::iterator it = _linkAnnotations.find(name); - if (_linkAnnotations.end() != it) + if (_linkAnnotations.end() != it) throw InvalidArgumentException("Annotation already exists."); - LinkAnnotation ann(_pPDF, + LinkAnnotation ann(&_pDocument->handle(), HPDF_Page_CreateLinkAnnot(_page, rect, dest), name); - std::pair ret = + std::pair ret = _linkAnnotations.insert(LinkAnnotationContainer::value_type(name, ann)); if (ret.second) return ret.first->second; @@ -164,18 +192,18 @@ const LinkAnnotation& Page::createLinkAnnotation(const std::string& name, } -const LinkAnnotation& Page::createURILinkAnnotation(const std::string& name, +const LinkAnnotation& Page::createURILinkAnnotation(const std::string& name, const Rectangle& rect, const std::string& uri) { LinkAnnotationContainer::iterator it = _linkAnnotations.find(name); - if (_linkAnnotations.end() != it) + if (_linkAnnotations.end() != it) throw InvalidArgumentException("Annotation already exists."); - LinkAnnotation ann(_pPDF, + LinkAnnotation ann(&_pDocument->handle(), HPDF_Page_CreateURILinkAnnot(_page, rect, uri.c_str()), name); - std::pair ret = + std::pair ret = _linkAnnotations.insert(LinkAnnotationContainer::value_type(name, ann)); if (ret.second) return ret.first->second; diff --git a/PDF/src/TextAnnotation.cpp b/PDF/src/TextAnnotation.cpp index d2e9f3d9c..0b8d7f132 100644 --- a/PDF/src/TextAnnotation.cpp +++ b/PDF/src/TextAnnotation.cpp @@ -22,7 +22,7 @@ namespace PDF { TextAnnotation::TextAnnotation(HPDF_Doc* pPDF, const HPDF_Annotation& annotation, - const std::string& name): + const std::string& name): Resource(pPDF, annotation, name) { open(); diff --git a/PDF/src/gzio.c b/PDF/src/gzio.c index cce085734..2354bc5ba 100644 --- a/PDF/src/gzio.c +++ b/PDF/src/gzio.c @@ -256,7 +256,7 @@ int ZEXPORT gzsetparams (file, level, strategy) /* =========================================================================== Read a byte from a gz_stream; update next_in and avail_in. Return EOF for end of file. - IN assertion: the stream s has been successfully opened for reading. + IN assertion: the stream s has been sucessfully opened for reading. */ local int get_byte(s) gz_stream *s; @@ -281,7 +281,7 @@ local int get_byte(s) mode to transparent if the gzip magic header is not present; set s->err to Z_DATA_ERROR if the magic header is present but the rest of the header is incorrect. - IN assertion: the stream s has already been created successfully; + IN assertion: the stream s has already been created sucessfully; s->stream.avail_in is zero for the first time, but may be non-zero for concatenated .gz files. */ diff --git a/PDF/src/hpdf_3dmeasure.c b/PDF/src/hpdf_3dmeasure.c new file mode 100644 index 000000000..aaa1e811d --- /dev/null +++ b/PDF/src/hpdf_3dmeasure.c @@ -0,0 +1,235 @@ +/* + * << Haru Free PDF Library >> -- hpdf_annotation.c + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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 "hpdf_conf.h" +#include "hpdf_utils.h" +#include "hpdf_info.h" +#include "hpdf_3dmeasure.h" +#include "hpdf.h" + +/*----------------------------------------------------------------------------*/ +/*------ HPDF_3DMeasure -----------------------------------------------------*/ + +HPDF_STATUS +HPDF_Dict_AddPoint3D(HPDF_Dict dict, const char* key, HPDF_Point3D point) +{ + HPDF_Array array; + HPDF_STATUS ret = HPDF_OK; + array = HPDF_Array_New (dict->mmgr); + if (!array) + return HPDF_Error_GetCode ( dict->error); + + if (HPDF_Dict_Add (dict, key, array) != HPDF_OK) + return HPDF_Error_GetCode ( dict->error); + + ret += HPDF_Array_AddReal(array, point.x); + ret += HPDF_Array_AddReal(array, point.y); + ret += HPDF_Array_AddReal(array, point.z); + + return ret; +} + + + + +HPDF_3DMeasure +HPDF_3DC3DMeasure_New(HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Point3D firstanchorpoint, + HPDF_Point3D textanchorpoint + ) +{ + HPDF_3DMeasure measure; + HPDF_STATUS ret = HPDF_OK; + + + HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n")); + + measure = HPDF_Dict_New (mmgr); + if (!measure) + return NULL; + + if (HPDF_Xref_Add (xref, measure) != HPDF_OK) + return NULL; + + ret += HPDF_Dict_AddPoint3D(measure, "A1", firstanchorpoint); + ret += HPDF_Dict_AddPoint3D(measure, "TP", textanchorpoint); + + ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure"); + ret += HPDF_Dict_AddName (measure, "Subtype", "3DC"); + + if (ret != HPDF_OK) + return NULL; + + return measure; +} + + + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DMeasure_SetColor(HPDF_3DMeasure measure, + HPDF_RGBColor color) +{ + HPDF_Array array; + HPDF_STATUS ret = HPDF_OK; + + array = HPDF_Array_New (measure->mmgr); + if (!array) + return HPDF_Error_GetCode (measure->error); + + ret = HPDF_Dict_Add (measure, "C", array); + if (ret != HPDF_OK) + return ret; + + ret += HPDF_Array_AddName(array, "DeviceRGB"); + ret += HPDF_Array_AddReal(array, color.r); + ret += HPDF_Array_AddReal(array, color.g); + ret += HPDF_Array_AddReal(array, color.b); + + return ret; +} + + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DMeasure_SetTextSize(HPDF_3DMeasure measure, + HPDF_REAL textsize) +{ + HPDF_STATUS ret = HPDF_OK; + + ret = HPDF_Dict_AddReal(measure, "TS", textsize); + + return ret; +} + + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DMeasure_SetName(HPDF_3DMeasure measure, + const char* name) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_String s; + + s = HPDF_String_New (measure->mmgr, name, 0); + if (!s) + return HPDF_Error_GetCode ( s->error); + + ret = HPDF_Dict_Add(measure, "TRL", s); + + return ret; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DC3DMeasure_SetTextBoxSize(HPDF_3DMeasure measure, + HPDF_INT32 x, + HPDF_INT32 y) +{ + HPDF_Array array; + HPDF_STATUS ret = HPDF_OK; + + array = HPDF_Array_New (measure->mmgr); + if (!array) + return HPDF_Error_GetCode (measure->error); + + ret = HPDF_Dict_Add (measure, "TB", array); + if (ret != HPDF_OK) + return ret; + + ret += HPDF_Array_AddNumber(array, x); + ret += HPDF_Array_AddNumber(array, y); + + return ret; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DC3DMeasure_SetText(HPDF_3DMeasure measure, + const char* text, + HPDF_Encoder encoder) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_String s; + + s = HPDF_String_New (measure->mmgr, text, encoder); + if (!s) + return HPDF_Error_GetCode ( s->error); + + ret = HPDF_Dict_Add(measure, "UT", s); + + return ret; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DC3DMeasure_SetProjectionAnotation(HPDF_3DMeasure measure, + HPDF_Annotation projectionanotation) +{ + HPDF_STATUS ret = HPDF_OK; + + ret = HPDF_Dict_Add(measure, "S", projectionanotation); + + return ret; +} + + +HPDF_3DMeasure +HPDF_PD33DMeasure_New(HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Point3D annotationPlaneNormal, + HPDF_Point3D firstAnchorPoint, + HPDF_Point3D secondAnchorPoint, + HPDF_Point3D leaderLinesDirection, + HPDF_Point3D measurementValuePoint, + HPDF_Point3D textYDirection, + HPDF_REAL value, + const char* unitsString + ) +{ + HPDF_3DMeasure measure; + HPDF_STATUS ret = HPDF_OK; + HPDF_String s; + + HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n")); + + measure = HPDF_Dict_New (mmgr); + if (!measure) + return NULL; + + if (HPDF_Xref_Add (xref, measure) != HPDF_OK) + return NULL; + + ret += HPDF_Dict_AddPoint3D(measure, "AP", annotationPlaneNormal); + ret += HPDF_Dict_AddPoint3D(measure, "A1", firstAnchorPoint); + ret += HPDF_Dict_AddPoint3D(measure, "A2", secondAnchorPoint); + ret += HPDF_Dict_AddPoint3D(measure, "D1", leaderLinesDirection); + ret += HPDF_Dict_AddPoint3D(measure, "TP", measurementValuePoint); + ret += HPDF_Dict_AddPoint3D(measure, "TY", textYDirection); + + ret += HPDF_Dict_AddReal(measure, "V", value); + + s = HPDF_String_New (measure->mmgr, unitsString, 0); + if (!s) + return NULL; + + ret = HPDF_Dict_Add(measure, "U", s); + + ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure"); + ret += HPDF_Dict_AddName (measure, "Subtype", "PD3"); + + if (ret != HPDF_OK) + return NULL; + + return measure; +} + diff --git a/PDF/src/hpdf_annotation.c b/PDF/src/hpdf_annotation.c index 874e1d783..f90500619 100644 --- a/PDF/src/hpdf_annotation.c +++ b/PDF/src/hpdf_annotation.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_annotation.c + * << Haru Free PDF Library >> -- hpdf_annotation.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -14,10 +17,11 @@ #include "hpdf_conf.h" #include "hpdf_utils.h" +#include "hpdf_info.h" #include "hpdf_annotation.h" #include "hpdf.h" -const static char *HPDF_ANNOT_TYPE_NAMES[] = { +static const char * const HPDF_ANNOT_TYPE_NAMES[] = { "Text", "Link", "Sound", @@ -30,10 +34,14 @@ const static char *HPDF_ANNOT_TYPE_NAMES[] = { "Underline", "Ink", "FileAttachment", - "Popup" + "Popup", + "3D", + "Squiggly", + "Line", + "Projection" }; -const static char *HPDF_ANNOT_ICON_NAMES_NAMES[] = { +static const char * const HPDF_ANNOT_ICON_NAMES_NAMES[] = { "Comment", "Key", "Note", @@ -43,6 +51,50 @@ const static char *HPDF_ANNOT_ICON_NAMES_NAMES[] = { "Insert" }; +static const char * const HPDF_ANNOT_INTENT_NAMES[] = { + "FreeTextCallout", + "FreeTextTypeWriter", + "LineArrow", + "LineDimension", + "PolygonCloud", + "PolyLineDimension", + "PolygonDimension" + }; + +static const char * const HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[] = { + "None", + "Square", + "Circle", + "Diamond", + "OpenArrow", + "ClosedArrow", + "Butt", + "ROpenArrow", + "RClosedArrow", + "Slash" + }; + +static const char * const HPDF_LINE_ANNOT_CAP_POSITION_NAMES[] = { + "Inline", + "Top" + }; + +static const char * const HPDF_STAMP_ANNOT_NAME_NAMES[] = { + "Approved", + "Experimental", + "NotApproved", + "AsIs", + "Expired", + "NotForPublicRelease", + "Confidential", + "Final", + "Sold", + "Departmental", + "ForComment", + "TopSecret", + "Draft", + "ForPublicRelease" + }; static HPDF_BOOL CheckSubType (HPDF_Annotation annot, @@ -104,7 +156,7 @@ HPDF_Annotation_New (HPDF_MMgr mmgr, } -HPDF_STATUS +HPDF_EXPORT(HPDF_STATUS) HPDF_Annotation_SetBorderStyle (HPDF_Annotation annot, HPDF_BSSubtype subtype, HPDF_REAL width, @@ -268,12 +320,12 @@ HPDF_LinkAnnot_SetBorderStyle (HPDF_Annotation annot, ret += HPDF_Array_AddNumber (dash, dash_on); ret += HPDF_Array_AddNumber (dash, dash_off); + + if (ret != HPDF_OK) + return HPDF_CheckError (annot->error); } - if (ret != HPDF_OK) - return HPDF_CheckError (annot->error); - - return ret; + return HPDF_OK; } HPDF_EXPORT(HPDF_STATUS) @@ -309,19 +361,101 @@ HPDF_LinkAnnot_SetHighlightMode (HPDF_Annotation annot, return ret; } + HPDF_Annotation -HPDF_TextAnnot_New (HPDF_MMgr mmgr, +HPDF_3DAnnot_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Rect rect, + HPDF_U3D u3d) +{ + HPDF_Annotation annot; + HPDF_Dict action, appearance, stream; + HPDF_STATUS ret; + + HPDF_PTRACE((" HPDF_3DAnnot_New\n")); + + annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_3D, rect); + if (!annot) { + return NULL; + } + + HPDF_Dict_Add(annot, "Contents", HPDF_String_New (mmgr, "3D Model", NULL)); + + action = HPDF_Dict_New (mmgr); + if (!action) { + return NULL; + } + + ret = HPDF_Dict_Add (annot, "3DA", action); + if (ret != HPDF_OK) { + return NULL; + } + + ret += HPDF_Dict_AddName (action, "A", "PV"); + + ret += HPDF_Dict_AddBoolean(action, "TB", HPDF_FALSE); + + if (ret != HPDF_OK) { + return NULL; + } + + if (HPDF_Dict_Add (annot, "3DD", u3d) != HPDF_OK) { + return NULL; + } + + appearance = HPDF_Dict_New (mmgr); + if (!appearance) { + return NULL; + } + + ret = HPDF_Dict_Add (annot, "AP", appearance); + if (ret != HPDF_OK) { + return NULL; + } + + stream = HPDF_Dict_New (mmgr); + if (!stream) { + return NULL; + } + ret = HPDF_Dict_Add (appearance, "N", stream); + if (ret != HPDF_OK) { + return NULL; + } + + return annot; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DAnnot_Set3DView (HPDF_Annotation annot) +{ + HPDF_Boolean b; + + HPDF_PTRACE((" HPDF_3DAnnot_Set3DView\n")); + + if (!CheckSubType (annot, HPDF_ANNOT_3D)) + return HPDF_INVALID_ANNOTATION; + + b = HPDF_Boolean_New (annot->mmgr, 0); + if (!b) + return HPDF_CheckError (annot->error); + + return HPDF_Dict_Add (annot, "3DD", b); +} + +HPDF_Annotation +HPDF_MarkupAnnot_New (HPDF_MMgr mmgr, HPDF_Xref xref, HPDF_Rect rect, const char *text, - HPDF_Encoder encoder) + HPDF_Encoder encoder, + HPDF_AnnotType subtype) { HPDF_Annotation annot; HPDF_String s; - HPDF_PTRACE((" HPDF_TextAnnot_New\n")); + HPDF_PTRACE((" HPDF_MarkupAnnot_New\n")); - annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_TEXT_NOTES, rect); + annot = HPDF_Annotation_New (mmgr, xref, subtype, rect); if (!annot) return NULL; @@ -335,6 +469,90 @@ HPDF_TextAnnot_New (HPDF_MMgr mmgr, return annot; } +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_SetRGBColor (HPDF_Annotation annot, HPDF_RGBColor color) +{ + HPDF_Array cArray; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_Annot_SetRGBColor\n")); + + cArray = HPDF_Array_New ( annot->mmgr); + if (!cArray) + return HPDF_Error_GetCode ( annot->error); + + ret += HPDF_Dict_Add (annot, "C", cArray); + ret += HPDF_Array_AddReal (cArray, color.r); + ret += HPDF_Array_AddReal (cArray, color.g); + ret += HPDF_Array_AddReal (cArray, color.b); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (annot->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_SetCMYKColor (HPDF_Annotation annot, HPDF_CMYKColor color) +{ + HPDF_Array cArray; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_Annot_SetCMYKColor\n")); + + cArray = HPDF_Array_New (annot->mmgr); + if (!cArray) + return HPDF_Error_GetCode (annot->error); + + ret += HPDF_Dict_Add (annot, "C", cArray); + ret += HPDF_Array_AddReal (cArray, color.c); + ret += HPDF_Array_AddReal (cArray, color.m); + ret += HPDF_Array_AddReal (cArray, color.y); + ret += HPDF_Array_AddReal (cArray, color.k); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (annot->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_SetGrayColor (HPDF_Annotation annot, HPDF_REAL color) +{ + HPDF_Array cArray; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_Annot_SetGrayColor\n")); + + cArray = HPDF_Array_New (annot->mmgr); + if (!cArray) + return HPDF_Error_GetCode ( annot->error); + + ret += HPDF_Dict_Add (annot, "C", cArray); + ret += HPDF_Array_AddReal ( cArray, color); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode ( annot->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_SetNoColor (HPDF_Annotation annot) +{ + HPDF_Array cArray; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_Annot_SetNoColor\n")); + + cArray = HPDF_Array_New (annot->mmgr); + if (!cArray) + return HPDF_Error_GetCode ( annot->error); + + ret = HPDF_Dict_Add (annot, "C", cArray); + + return ret; +} HPDF_EXPORT(HPDF_STATUS) HPDF_TextAnnot_SetIcon (HPDF_Annotation annot, @@ -345,7 +563,7 @@ HPDF_TextAnnot_SetIcon (HPDF_Annotation annot, if (!CheckSubType (annot, HPDF_ANNOT_TEXT_NOTES)) return HPDF_INVALID_ANNOTATION; - if (icon < 0 || icon >= HPDF_ANNOT_ICON_EOF) + if (icon >= HPDF_ANNOT_ICON_EOF) return HPDF_RaiseError (annot->error, HPDF_ANNOT_INVALID_ICON, (HPDF_STATUS)icon); @@ -375,6 +593,162 @@ HPDF_TextAnnot_SetOpened (HPDF_Annotation annot, return HPDF_Dict_Add (annot, "Open", b); } +HPDF_EXPORT(HPDF_STATUS) +HPDF_PopupAnnot_SetOpened (HPDF_Annotation annot, + HPDF_BOOL opened) +{ + HPDF_Boolean b; + + HPDF_PTRACE((" HPDF_TextAnnot_SetOpend\n")); + + if (!CheckSubType (annot, HPDF_ANNOT_POPUP)) + return HPDF_INVALID_ANNOTATION; + + b = HPDF_Boolean_New (annot->mmgr, opened); + if (!b) + return HPDF_CheckError (annot->error); + + return HPDF_Dict_Add (annot, "Open", b); +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetTitle (HPDF_Annotation annot, const char* name) +{ + HPDF_PTRACE((" HPDF_MarkupAnnot_SetTitle\n")); + + return HPDF_Dict_Add( annot, "T", HPDF_String_New( annot->mmgr, name, NULL)); +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetSubject (HPDF_Annotation annot, const char* name) +{ + HPDF_PTRACE((" HPDF_MarkupAnnot_SetSubject\n")); + + return HPDF_Dict_Add( annot, "Subj", HPDF_String_New( annot->mmgr, name, NULL)); +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetCreationDate (HPDF_Annotation annot, HPDF_Date value) +{ + HPDF_PTRACE((" HPDF_MarkupAnnot_SetCreationDate\n")); + + return HPDF_Info_SetInfoDateAttr( annot, HPDF_INFO_CREATION_DATE, value); +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetTransparency (HPDF_Annotation annot, HPDF_REAL value) +{ + HPDF_PTRACE((" HPDF_MarkupAnnot_SetTransparency\n")); + + return HPDF_Dict_AddReal( annot, "CA", value); +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetIntent (HPDF_Annotation annot, + HPDF_AnnotIntent intent) +{ + HPDF_PTRACE((" HPDF_MarkupAnnot_SetIntent\n")); + + if (HPDF_Dict_AddName (annot, "IT", + HPDF_ANNOT_INTENT_NAMES[(HPDF_INT)intent]) != HPDF_OK) + return HPDF_CheckError (annot->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetPopup (HPDF_Annotation annot, + HPDF_Annotation popup) +{ + HPDF_PTRACE((" HPDF_MarkupAnnot_SetPopup\n")); + + return HPDF_Dict_Add( annot, "Popup", popup); +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetInteriorRGBColor (HPDF_Annotation annot, HPDF_RGBColor color)/* IC with RGB entry */ +{ + HPDF_Array cArray; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorRGBColor\n")); + + cArray = HPDF_Array_New ( annot->mmgr); + if (!cArray) + return HPDF_Error_GetCode ( annot->error); + + ret += HPDF_Dict_Add (annot, "IC", cArray); + ret += HPDF_Array_AddReal (cArray, color.r); + ret += HPDF_Array_AddReal (cArray, color.g); + ret += HPDF_Array_AddReal (cArray, color.b); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (annot->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetInteriorCMYKColor (HPDF_Annotation annot, HPDF_CMYKColor color)/* IC with CMYK entry */ +{ + HPDF_Array cArray; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorCMYKColor\n")); + + cArray = HPDF_Array_New ( annot->mmgr); + if (!cArray) + return HPDF_Error_GetCode ( annot->error); + + ret += HPDF_Dict_Add (annot, "IC", cArray); + ret += HPDF_Array_AddReal (cArray, color.c); + ret += HPDF_Array_AddReal (cArray, color.m); + ret += HPDF_Array_AddReal (cArray, color.y); + ret += HPDF_Array_AddReal (cArray, color.k); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (annot->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetInteriorGrayColor (HPDF_Annotation annot, HPDF_REAL color)/* IC with Gray entry */ +{ + HPDF_Array cArray; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorGrayColor\n")); + + cArray = HPDF_Array_New ( annot->mmgr); + if (!cArray) + return HPDF_Error_GetCode ( annot->error); + + ret += HPDF_Dict_Add (annot, "IC", cArray); + ret += HPDF_Array_AddReal (cArray, color); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode ( annot->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetInteriorTransparent (HPDF_Annotation annot) /* IC with No Color entry */ +{ + HPDF_Array cArray; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorTransparent\n")); + + cArray = HPDF_Array_New ( annot->mmgr); + if (!cArray) + return HPDF_Error_GetCode ( annot->error); + + ret = HPDF_Dict_Add (annot, "IC", cArray); + + return ret; +} HPDF_BOOL HPDF_Annotation_Validate (HPDF_Annotation annot) @@ -413,3 +787,380 @@ CheckSubType (HPDF_Annotation annot, return HPDF_TRUE; } +HPDF_EXPORT(HPDF_STATUS) +HPDF_Annot_Set3DView ( HPDF_MMgr mmgr, + HPDF_Annotation annot, + HPDF_Annotation annot3d, + HPDF_Dict view3d) +{ + HPDF_Proxy proxyView3d; + HPDF_Dict exData = HPDF_Dict_New( mmgr); + HPDF_STATUS retS = HPDF_OK; + + retS += HPDF_Dict_AddName( exData, "Type", "ExData"); + retS += HPDF_Dict_AddName( exData, "Subtype", "Markup3D"); + retS += HPDF_Dict_Add( exData, "3DA", annot3d); + + proxyView3d = HPDF_Proxy_New( mmgr, view3d); + + retS += HPDF_Dict_Add( exData, "3DV", proxyView3d); + retS += HPDF_Dict_Add( annot, "ExData", exData); + return retS; +} + + +HPDF_Annotation +HPDF_PopupAnnot_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Rect rect, + HPDF_Annotation parent) +{ + HPDF_Annotation annot; + + HPDF_PTRACE((" HPDF_PopupAnnot_New\n")); + + annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_POPUP, rect); + if (!annot) + return NULL; + + if (HPDF_Dict_Add (annot, "Parent", parent) != HPDF_OK) + return NULL; + + return annot; +} + +HPDF_Annotation +HPDF_StampAnnot_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Rect rect, + HPDF_StampAnnotName name, + const char* text, + HPDF_Encoder encoder) +{ + HPDF_Annotation annot; + HPDF_String s; + HPDF_PTRACE((" HPDF_StampAnnot_New\n")); + + annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_STAMP, rect); + if (!annot) + return NULL; + + if (HPDF_Dict_AddName ( annot, "Name", HPDF_STAMP_ANNOT_NAME_NAMES[name]) != HPDF_OK) + return NULL; + + s = HPDF_String_New (mmgr, text, encoder); + if (!s) + return NULL; + + if (HPDF_Dict_Add (annot, "Contents", s) != HPDF_OK) + return NULL; + + return annot; +} + +HPDF_Annotation +HPDF_ProjectionAnnot_New(HPDF_MMgr mmgr, + HPDF_Xref xref, + HPDF_Rect rect, + const char* text, + HPDF_Encoder encoder) +{ + HPDF_Annotation annot; + HPDF_String s; + HPDF_PTRACE((" HPDF_StampAnnot_New\n")); + + annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_PROJECTION, rect); + if (!annot) + return NULL; + + s = HPDF_String_New (mmgr, text, encoder); + if (!s) + return NULL; + + if (HPDF_Dict_Add (annot, "Contents", s) != HPDF_OK) + return NULL; + + return annot; +} + + +HPDF_EXPORT(HPDF_STATUS) +HPDF_TextMarkupAnnot_SetQuadPoints ( HPDF_Annotation annot, HPDF_Point lb, HPDF_Point rb, HPDF_Point lt, HPDF_Point rt) /* l-left, r-right, b-bottom, t-top positions */ +{ + HPDF_Array quadPoints; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_TextMarkupAnnot_SetQuadPoints\n")); + + quadPoints = HPDF_Array_New ( annot->mmgr); + if ( !quadPoints) + return HPDF_Error_GetCode ( annot->error); + + if ((ret = HPDF_Dict_Add ( annot, "QuadPoints", quadPoints)) != HPDF_OK) + return ret; + + ret += HPDF_Array_AddReal (quadPoints, lb.x); + ret += HPDF_Array_AddReal (quadPoints, lb.y); + ret += HPDF_Array_AddReal (quadPoints, rb.x); + ret += HPDF_Array_AddReal (quadPoints, rb.y); + ret += HPDF_Array_AddReal (quadPoints, lt.x); + ret += HPDF_Array_AddReal (quadPoints, lt.y); + ret += HPDF_Array_AddReal (quadPoints, rt.x); + ret += HPDF_Array_AddReal (quadPoints, rt.y); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (quadPoints->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_FreeTextAnnot_SetLineEndingStyle (HPDF_Annotation annot, HPDF_LineAnnotEndingStyle startStyle, HPDF_LineAnnotEndingStyle endStyle) +{ + HPDF_Array lineEndStyles; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_FreeTextAnnot_SetLineEndingStyle\n")); + + lineEndStyles = HPDF_Array_New ( annot->mmgr); + if ( !lineEndStyles) + return HPDF_Error_GetCode ( annot->error); + + if ((ret = HPDF_Dict_Add ( annot, "LE", lineEndStyles)) != HPDF_OK) + return ret; + + ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)startStyle]); + ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)endStyle]); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (lineEndStyles->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetRectDiff (HPDF_Annotation annot, HPDF_Rect rect) /* RD entry : this is the difference between Rect and the text annotation rectangle */ +{ + HPDF_Array array; + HPDF_STATUS ret = HPDF_OK; + HPDF_REAL tmp; + + HPDF_PTRACE((" HPDF_MarkupAnnot_SetRectDiff\n")); + + array = HPDF_Array_New ( annot->mmgr); + if ( !array) + return HPDF_Error_GetCode ( annot->error); + + if ((ret = HPDF_Dict_Add ( annot, "RD", array)) != HPDF_OK) + return ret; + + if (rect.top < rect.bottom) { + tmp = rect.top; + rect.top = rect.bottom; + rect.bottom = tmp; + } + + ret += HPDF_Array_AddReal (array, rect.left); + ret += HPDF_Array_AddReal (array, rect.bottom); + ret += HPDF_Array_AddReal (array, rect.right); + ret += HPDF_Array_AddReal (array, rect.top); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (array->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_FreeTextAnnot_SetDefaultStyle (HPDF_Annotation annot, + const char* style) +{ + HPDF_String s; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_FreeTextAnnot_SetDefaultStyle\n")); + + s = HPDF_String_New ( annot->mmgr, style, NULL); + if ( !s) + return HPDF_Error_GetCode ( annot->error); + + ret = HPDF_Dict_Add ( annot, "DS", s); + + return ret; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_FreeTextAnnot_Set3PointCalloutLine ( HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point kneePoint, HPDF_Point endPoint) /* Callout line will be in default user space */ +{ + HPDF_Array clPoints; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_FreeTextAnnot_Set3PointCalloutLine\n")); + + clPoints = HPDF_Array_New ( annot->mmgr); + if ( !clPoints) + return HPDF_Error_GetCode ( annot->error); + + if ((ret = HPDF_Dict_Add ( annot, "CL", clPoints)) != HPDF_OK) + return ret; + + ret += HPDF_Array_AddReal (clPoints, startPoint.x); + ret += HPDF_Array_AddReal (clPoints, startPoint.y); + ret += HPDF_Array_AddReal (clPoints, kneePoint.x); + ret += HPDF_Array_AddReal (clPoints, kneePoint.y); + ret += HPDF_Array_AddReal (clPoints, endPoint.x); + ret += HPDF_Array_AddReal (clPoints, endPoint.y); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (clPoints->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_FreeTextAnnot_Set2PointCalloutLine ( HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point endPoint) /* Callout line will be in default user space */ +{ + HPDF_Array clPoints; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_FreeTextAnnot_Set3PointCalloutLine\n")); + + clPoints = HPDF_Array_New ( annot->mmgr); + if ( !clPoints) + return HPDF_Error_GetCode ( annot->error); + + if ((ret = HPDF_Dict_Add ( annot, "CL", clPoints)) != HPDF_OK) + return ret; + + ret += HPDF_Array_AddReal (clPoints, startPoint.x); + ret += HPDF_Array_AddReal (clPoints, startPoint.y); + ret += HPDF_Array_AddReal (clPoints, endPoint.x); + ret += HPDF_Array_AddReal (clPoints, endPoint.y); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (clPoints->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_MarkupAnnot_SetCloudEffect (HPDF_Annotation annot, HPDF_INT cloudIntensity) /* BE entry */ +{ + HPDF_Dict borderEffect; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_MarkupAnnot_SetCloudEffect\n")); + + borderEffect = HPDF_Dict_New ( annot->mmgr); + if (!borderEffect) + return HPDF_Error_GetCode ( annot->error); + + ret += HPDF_Dict_Add ( annot, "BE", borderEffect); + ret += HPDF_Dict_AddName ( borderEffect, "S", "C"); + ret += HPDF_Dict_AddNumber ( borderEffect, "I", cloudIntensity); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (annot->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_LineAnnot_SetPosition (HPDF_Annotation annot, + HPDF_Point startPoint, HPDF_LineAnnotEndingStyle startStyle, + HPDF_Point endPoint, HPDF_LineAnnotEndingStyle endStyle) +{ + HPDF_Array lineEndPoints; + HPDF_Array lineEndStyles; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_LineAnnot_SetPosition\n")); + + lineEndPoints = HPDF_Array_New ( annot->mmgr); + if ( !lineEndPoints) + return HPDF_Error_GetCode ( annot->error); + + if ((ret = HPDF_Dict_Add ( annot, "L", lineEndPoints)) != HPDF_OK) + return ret; + + ret += HPDF_Array_AddReal (lineEndPoints, startPoint.x); + ret += HPDF_Array_AddReal (lineEndPoints, startPoint.y); + ret += HPDF_Array_AddReal (lineEndPoints, endPoint.x); + ret += HPDF_Array_AddReal (lineEndPoints, endPoint.y); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode ( lineEndPoints->error); + + lineEndStyles = HPDF_Array_New ( annot->mmgr); + if ( !lineEndStyles) + return HPDF_Error_GetCode ( annot->error); + + if ((ret = HPDF_Dict_Add ( annot, "LE", lineEndStyles)) != HPDF_OK) + return ret; + + ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)startStyle]); + ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)endStyle]); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode ( lineEndStyles->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_LineAnnot_SetLeader (HPDF_Annotation annot, HPDF_INT leaderLen, HPDF_INT leaderExtLen, HPDF_INT leaderOffsetLen) +{ + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_LineAnnot_SetLeader\n")); + + ret += HPDF_Dict_AddNumber ( annot, "LL", leaderLen); + ret += HPDF_Dict_AddNumber ( annot, "LLE", leaderExtLen); + ret += HPDF_Dict_AddNumber ( annot, "LLO", leaderOffsetLen); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode ( annot->error); + + return HPDF_OK; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_LineAnnot_SetCaption (HPDF_Annotation annot, HPDF_BOOL showCaption, HPDF_LineAnnotCapPosition position, HPDF_INT horzOffset, HPDF_INT vertOffset) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_Array capOffset; + HPDF_PTRACE((" HPDF_LineAnnot_SetCaption\n")); + + ret += HPDF_Dict_AddBoolean ( annot, "Cap", showCaption); + ret += HPDF_Dict_AddName( annot, "CP", HPDF_LINE_ANNOT_CAP_POSITION_NAMES[(HPDF_INT)position]); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode ( annot->error); + + capOffset = HPDF_Array_New ( annot->mmgr); + if ( !capOffset) + return HPDF_Error_GetCode ( annot->error); + + if ((ret = HPDF_Dict_Add ( annot, "CO", capOffset)) != HPDF_OK) + return ret; + + ret += HPDF_Array_AddNumber (capOffset, horzOffset); + ret += HPDF_Array_AddNumber (capOffset, vertOffset); + + if (ret != HPDF_OK) + return HPDF_Error_GetCode (capOffset->error); + + return HPDF_OK; +} + + + +HPDF_EXPORT(HPDF_STATUS) +HPDF_ProjectionAnnot_SetExData(HPDF_Annotation annot, HPDF_ExData exdata) +{ + HPDF_STATUS ret = HPDF_OK; + + ret = HPDF_Dict_Add(annot, "ExData", exdata); + + return ret; +} diff --git a/PDF/src/hpdf_array.c b/PDF/src/hpdf_array.c index 0f9fdf0c8..0984867ef 100644 --- a/PDF/src/hpdf_array.c +++ b/PDF/src/hpdf_array.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_array.c + * << Haru Free PDF Library >> -- hpdf_array.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -211,6 +214,13 @@ HPDF_Array_Add (HPDF_Array array, } +HPDF_UINT +HPDF_Array_Items (HPDF_Array array) +{ + return array->list->count; +} + + HPDF_STATUS HPDF_Array_Insert (HPDF_Array array, void *target, diff --git a/PDF/src/hpdf_binary.c b/PDF/src/hpdf_binary.c index 667650203..64cd0f5da 100644 --- a/PDF/src/hpdf_binary.c +++ b/PDF/src/hpdf_binary.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_binary.c + * << Haru Free PDF Library >> -- hpdf_binary.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_boolean.c b/PDF/src/hpdf_boolean.c index baba49a96..b8d3f6d9b 100644 --- a/PDF/src/hpdf_boolean.c +++ b/PDF/src/hpdf_boolean.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_boolean.h + * << Haru Free PDF Library >> -- hpdf_boolean.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_catalog.c b/PDF/src/hpdf_catalog.c index 34b82e669..6c3107104 100644 --- a/PDF/src/hpdf_catalog.c +++ b/PDF/src/hpdf_catalog.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.5 >> -- hpdf_catalog.c + * << Haru Free PDF Library >> -- hpdf_catalog.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -10,8 +13,6 @@ * in supporting documentation. * It is provided "as is" without express or implied warranty. * - * 2006.08.07 modified. - * 2006.09.01 added ViewerPreference functions. */ #include "hpdf_conf.h" @@ -19,16 +20,18 @@ #include "hpdf_catalog.h" #include "hpdf_pages.h" -static const char *HPDF_PAGE_LAYOUT_NAMES[] = { +static const char * const HPDF_PAGE_LAYOUT_NAMES[] = { "SinglePage", "OneColumn", "TwoColumnLeft", "TwoColumnRight", + "TwoPageLeft", + "TwoPageRight", NULL }; -static const char *HPDF_PAGE_MODE_NAMES[] = { +static const char * const HPDF_PAGE_MODE_NAMES[] = { "UseNone", "UseOutlines", "UseThumbs", @@ -83,6 +86,23 @@ HPDF_Catalog_GetRoot (HPDF_Catalog catalog) } +HPDF_NameDict +HPDF_Catalog_GetNames (HPDF_Catalog catalog) +{ + if (!catalog) + return NULL; + return HPDF_Dict_GetItem (catalog, "Names", HPDF_OCLASS_DICT); +} + + +HPDF_STATUS +HPDF_Catalog_SetNames (HPDF_Catalog catalog, + HPDF_NameDict dict) +{ + return HPDF_Dict_Add (catalog, "Names", dict); +} + + HPDF_PageLayout HPDF_Catalog_GetPageLayout (HPDF_Catalog catalog) { @@ -296,6 +316,17 @@ HPDF_Catalog_SetViewerPreference (HPDF_Catalog catalog, return ret; } + if (value & HPDF_PRINT_SCALING_NONE) { + if ((ret = HPDF_Dict_AddName (preferences, "PrintScaling", + "None")) != HPDF_OK) + return ret; + } else { + if ((ret = HPDF_Dict_RemoveElement (preferences, "PrintScaling")) != + HPDF_OK) + if (ret != HPDF_DICT_ITEM_NOT_FOUND) + return ret; + } + return HPDF_OK; } diff --git a/PDF/src/hpdf_destination.c b/PDF/src/hpdf_destination.c index fed8e47f2..e2566c890 100644 --- a/PDF/src/hpdf_destination.c +++ b/PDF/src/hpdf_destination.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_destination.c + * << Haru Free PDF Library >> -- hpdf_destination.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -16,7 +19,7 @@ #include "hpdf_utils.h" #include "hpdf.h" -const char *HPDF_DESTINATION_TYPE_NAMES[] = { +const char * const HPDF_DESTINATION_TYPE_NAMES[] = { "XYZ", "Fit", "FitH", @@ -82,8 +85,10 @@ HPDF_Destination_Validate (HPDF_Destination dst) return HPDF_FALSE; target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT); - if (!HPDF_Page_Validate (target)) - return HPDF_SetError (dst->error, HPDF_INVALID_PAGE, 0); + if (!HPDF_Page_Validate (target)) { + HPDF_SetError (dst->error, HPDF_INVALID_PAGE, 0); + return HPDF_FALSE; + } return HPDF_TRUE; } diff --git a/PDF/src/hpdf_dict.c b/PDF/src/hpdf_dict.c index e4fc5f926..b537649e5 100644 --- a/PDF/src/hpdf_dict.c +++ b/PDF/src/hpdf_dict.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.5 >> -- HPDF_Dict.c + * << Haru Free PDF Library >> -- hpdf_dict.c * - * Copyright (c) 1999-2004 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -113,6 +116,25 @@ HPDF_Dict_Free (HPDF_Dict dict) HPDF_FreeMem (dict->mmgr, dict); } +HPDF_STATUS +HPDF_Dict_Add_FilterParams(HPDF_Dict dict, HPDF_Dict filterParam) +{ + HPDF_Array paramArray; + /* prepare params object */ + paramArray = HPDF_Dict_GetItem (dict, "DecodeParms", + HPDF_OCLASS_ARRAY); + if(paramArray==NULL) { + paramArray = HPDF_Array_New (dict->mmgr); + if (!paramArray) + return HPDF_Error_GetCode (dict->error); + + /* add parameters */ + HPDF_Dict_Add(dict, "DecodeParms", paramArray); + } + HPDF_Array_Add(paramArray, filterParam); + return HPDF_OK; +} + HPDF_STATUS HPDF_Dict_Write (HPDF_Dict dict, @@ -155,13 +177,21 @@ HPDF_Dict_Write (HPDF_Dict dict, HPDF_Array_Clear (array); -#ifndef HPDF_NOZLIB +#ifndef LIBHPDF_HAVE_NOZLIB if (dict->filter & HPDF_STREAM_FILTER_FLATE_DECODE) HPDF_Array_AddName (array, "FlateDecode"); -#endif /* HPDF_NOZLIB */ +#endif /* LIBHPDF_HAVE_NOZLIB */ if (dict->filter & HPDF_STREAM_FILTER_DCT_DECODE) HPDF_Array_AddName (array, "DCTDecode"); + + if(dict->filter & HPDF_STREAM_FILTER_CCITT_DECODE) + HPDF_Array_AddName (array, "CCITTFaxDecode"); + + if(dict->filterParams!=NULL) + { + HPDF_Dict_Add_FilterParams(dict, dict->filterParams); + } } } @@ -220,7 +250,7 @@ HPDF_Dict_Write (HPDF_Dict dict, 0); } - if ((ret = HPDF_Stream_WriteStr (stream, "\012stream\015\012")) + if ((ret = HPDF_Stream_WriteStr (stream, "\012stream\015\012")) /* Acrobat 8.15 requires both \r and \n here */ != HPDF_OK) return ret; diff --git a/PDF/src/hpdf_doc.c b/PDF/src/hpdf_doc.c index a95dfd10d..7d9eb1a44 100644 --- a/PDF/src/hpdf_doc.c +++ b/PDF/src/hpdf_doc.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.5 >> -- hpdf_doc.c + * << Haru Free PDF Library >> -- hpdf_doc.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -16,18 +19,20 @@ #include "hpdf_conf.h" #include "hpdf_utils.h" #include "hpdf_encryptdict.h" +#include "hpdf_namedict.h" #include "hpdf_destination.h" #include "hpdf_info.h" #include "hpdf_page_label.h" #include "hpdf.h" -static const char *HPDF_VERSION_STR[5] = { +static const char * const HPDF_VERSION_STR[6] = { "%PDF-1.2\012%\267\276\255\252\012", "%PDF-1.3\012%\267\276\255\252\012", "%PDF-1.4\012%\267\276\255\252\012", "%PDF-1.5\012%\267\276\255\252\012", - "%PDF-1.6\012%\267\276\255\252\012" + "%PDF-1.6\012%\267\276\255\252\012", + "%PDF-1.7\012%\267\276\255\252\012" }; @@ -255,7 +260,7 @@ HPDF_NewDoc (HPDF_Doc pdf) pdf->cur_pages = pdf->root_pages; - ptr = HPDF_StrCpy (ptr, "Haru Free PDF Library ", eptr); + ptr = (char *)HPDF_StrCpy (ptr, (const char *)"Haru Free PDF Library ", eptr); version = HPDF_GetVersion (); HPDF_StrCpy (ptr, version, eptr); @@ -647,6 +652,39 @@ HPDF_SaveToStream (HPDF_Doc pdf) return HPDF_OK; } +HPDF_EXPORT(HPDF_STATUS) +HPDF_GetContents (HPDF_Doc pdf, + HPDF_BYTE *buf, + HPDF_UINT32 *size) +{ + HPDF_Stream stream; + HPDF_UINT isize = *size; + HPDF_STATUS ret; + + HPDF_PTRACE ((" HPDF_GetContents\n")); + + if (!HPDF_HasDoc (pdf)) { + return HPDF_INVALID_DOCUMENT; + } + + stream = HPDF_MemStream_New (pdf->mmgr, HPDF_STREAM_BUF_SIZ); + + if (!stream) { + return HPDF_CheckError (&pdf->error); + } + + if (InternalSaveToStream (pdf, stream) != HPDF_OK) { + HPDF_Stream_Free (stream); + return HPDF_CheckError (&pdf->error); + } + + ret = HPDF_Stream_Read (stream, buf, &isize); + + *size = isize; + HPDF_Stream_Free (stream); + + return ret; +} HPDF_EXPORT(HPDF_UINT32) HPDF_GetStreamSize (HPDF_Doc pdf) @@ -1186,11 +1224,12 @@ HPDF_SetCurrentEncoder (HPDF_Doc pdf, return HPDF_GetError (pdf); encoder = HPDF_GetEncoder (pdf, encoding_name); - pdf->cur_encoder = encoder; - if (!pdf) + if (!encoder) return HPDF_GetError (pdf); + pdf->cur_encoder = encoder; + return HPDF_OK; } @@ -1281,6 +1320,11 @@ HPDF_GetFont (HPDF_Doc pdf, return NULL; } + if (!encoder) { + HPDF_CheckError (&pdf->error); + return NULL; + } + font = HPDF_Doc_FindFont (pdf, font_name, encoder->name); } else { font = HPDF_Doc_FindFont (pdf, font_name, encoding_name); @@ -1412,10 +1456,33 @@ LoadType1FontFromStream (HPDF_Doc pdf, HPDF_FontDef_Free (def); return NULL; } + return def->base_font; } - return def->base_font; + return NULL; } +HPDF_EXPORT(HPDF_FontDef) +HPDF_GetTTFontDefFromFile (HPDF_Doc pdf, + const char *file_name, + HPDF_BOOL embedding) +{ + HPDF_Stream font_data; + HPDF_FontDef def; + + HPDF_PTRACE ((" HPDF_GetTTFontDefFromFile\n")); + + /* create file stream */ + font_data = HPDF_FileReader_New (pdf->mmgr, file_name); + + if (HPDF_Stream_Validate (font_data)) { + def = HPDF_TTFontDef_Load (pdf->mmgr, font_data, embedding); + } else { + HPDF_CheckError (&pdf->error); + return NULL; + } + + return def; +} HPDF_EXPORT(const char*) HPDF_LoadTTFontFromFile (HPDF_Doc pdf, @@ -1454,14 +1521,14 @@ LoadTTFontFromStream (HPDF_Doc pdf, HPDF_FontDef def; HPDF_PTRACE ((" HPDF_LoadTTFontFromStream\n")); + HPDF_UNUSED (file_name); def = HPDF_TTFontDef_Load (pdf->mmgr, font_data, embedding); if (def) { HPDF_FontDef tmpdef = HPDF_Doc_FindFontDef (pdf, def->base_font); if (tmpdef) { HPDF_FontDef_Free (def); - HPDF_SetError (&pdf->error, HPDF_FONT_EXISTS, 0); - return NULL; + return tmpdef->base_font; } if (HPDF_List_Add (pdf->fontdef_list, def) != HPDF_OK) { @@ -1473,7 +1540,7 @@ LoadTTFontFromStream (HPDF_Doc pdf, if (embedding) { if (pdf->ttfont_tag[0] == 0) { - HPDF_MemCpy (pdf->ttfont_tag, "HPDFAA", 6); + HPDF_MemCpy (pdf->ttfont_tag, (HPDF_BYTE *)"HPDFAA", 6); } else { HPDF_INT i; @@ -1486,7 +1553,7 @@ LoadTTFontFromStream (HPDF_Doc pdf, } } - HPDF_TTFontDef_SetTagName (def, pdf->ttfont_tag); + HPDF_TTFontDef_SetTagName (def, (char *)pdf->ttfont_tag); } return def->base_font; @@ -1532,14 +1599,14 @@ LoadTTFontFromStream2 (HPDF_Doc pdf, HPDF_FontDef def; HPDF_PTRACE ((" HPDF_LoadTTFontFromStream2\n")); + HPDF_UNUSED (file_name); def = HPDF_TTFontDef_Load2 (pdf->mmgr, font_data, index, embedding); if (def) { HPDF_FontDef tmpdef = HPDF_Doc_FindFontDef (pdf, def->base_font); if (tmpdef) { HPDF_FontDef_Free (def); - HPDF_SetError (&pdf->error, HPDF_FONT_EXISTS, 0); - return NULL; + return tmpdef->base_font; } if (HPDF_List_Add (pdf->fontdef_list, def) != HPDF_OK) { @@ -1551,7 +1618,7 @@ LoadTTFontFromStream2 (HPDF_Doc pdf, if (embedding) { if (pdf->ttfont_tag[0] == 0) { - HPDF_MemCpy (pdf->ttfont_tag, "HPDFAA", 6); + HPDF_MemCpy (pdf->ttfont_tag, (HPDF_BYTE *)"HPDFAA", 6); } else { HPDF_INT i; @@ -1564,7 +1631,7 @@ LoadTTFontFromStream2 (HPDF_Doc pdf, } } - HPDF_TTFontDef_SetTagName (def, pdf->ttfont_tag); + HPDF_TTFontDef_SetTagName (def, (char *)pdf->ttfont_tag); } return def->base_font; @@ -1601,7 +1668,7 @@ HPDF_LoadRawImageFromFile (HPDF_Doc pdf, if (!image) HPDF_CheckError (&pdf->error); - if (pdf->compression_mode & HPDF_COMP_IMAGE) + if (image && pdf->compression_mode & HPDF_COMP_IMAGE) image->filter = HPDF_STREAM_FILTER_FLATE_DECODE; return image; @@ -1623,14 +1690,19 @@ HPDF_LoadRawImageFromMem (HPDF_Doc pdf, if (!HPDF_HasDoc (pdf)) return NULL; - image = HPDF_Image_LoadRawImageFromMem (pdf->mmgr, buf, pdf->xref, width, - height, color_space, bits_per_component); + /* Use directly HPDF_Image_LoadRaw1BitImageFromMem to save B/W images */ + if(color_space == HPDF_CS_DEVICE_GRAY && bits_per_component == 1) { + return HPDF_Image_LoadRaw1BitImageFromMem (pdf, buf, width, height, (width+7)/8, HPDF_TRUE, HPDF_TRUE); + } + + image = HPDF_Image_LoadRawImageFromMem (pdf->mmgr, buf, pdf->xref, width, height, color_space, bits_per_component); if (!image) HPDF_CheckError (&pdf->error); - if (pdf->compression_mode & HPDF_COMP_IMAGE) + if (image && pdf->compression_mode & HPDF_COMP_IMAGE) { image->filter = HPDF_STREAM_FILTER_FLATE_DECODE; + } return image; } @@ -1665,6 +1737,27 @@ HPDF_LoadJpegImageFromFile (HPDF_Doc pdf, return image; } +HPDF_EXPORT(HPDF_Image) +HPDF_LoadJpegImageFromMem (HPDF_Doc pdf, + const HPDF_BYTE *buffer, + HPDF_UINT size) +{ + HPDF_Image image; + + HPDF_PTRACE ((" HPDF_LoadJpegImageFromMem\n")); + + if (!HPDF_HasDoc (pdf)) { + return NULL; + } + + image = HPDF_Image_LoadJpegImageFromMem (pdf->mmgr, buffer, size , pdf->xref); + + if (!image) { + HPDF_CheckError (&pdf->error); + } + + return image; +} /*----- Catalog ------------------------------------------------------------*/ @@ -1695,6 +1788,9 @@ HPDF_SetPageLayout (HPDF_Doc pdf, return HPDF_RaiseError (&pdf->error, HPDF_PAGE_LAYOUT_OUT_OF_RANGE, (HPDF_STATUS)layout); + if ((layout == HPDF_PAGE_LAYOUT_TWO_PAGE_LEFT || layout == HPDF_PAGE_LAYOUT_TWO_PAGE_RIGHT) && pdf->pdf_version < HPDF_VER_15) + pdf->pdf_version = HPDF_VER_15 ; + ret = HPDF_Catalog_SetPageLayout (pdf->catalog, layout); if (ret != HPDF_OK) HPDF_CheckError (&pdf->error); @@ -1786,6 +1882,8 @@ HPDF_SetViewerPreference (HPDF_Doc pdf, if (ret != HPDF_OK) return HPDF_CheckError (&pdf->error); + pdf->pdf_version = HPDF_VER_16; + return HPDF_OK; } @@ -1822,6 +1920,58 @@ HPDF_AddPageLabel (HPDF_Doc pdf, } +HPDF_EXPORT(HPDF_EmbeddedFile) +HPDF_AttachFile (HPDF_Doc pdf, + const char *file) +{ + HPDF_NameDict names; + HPDF_NameTree ntree; + HPDF_EmbeddedFile efile; + HPDF_String name; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE ((" HPDF_AttachFile\n")); + + if (!HPDF_HasDoc (pdf)) + return NULL; + + names = HPDF_Catalog_GetNames (pdf->catalog); + if (!names) { + names = HPDF_NameDict_New (pdf->mmgr, pdf->xref); + if (!names) + return NULL; + + ret = HPDF_Catalog_SetNames (pdf->catalog, names); + if (ret != HPDF_OK) + return NULL; + } + + ntree = HPDF_NameDict_GetNameTree (names, HPDF_NAME_EMBEDDED_FILES); + if (!ntree) { + ntree = HPDF_NameTree_New (pdf->mmgr, pdf->xref); + if (!ntree) + return NULL; + + ret = HPDF_NameDict_SetNameTree (names, HPDF_NAME_EMBEDDED_FILES, ntree); + if (ret != HPDF_OK) + return NULL; + } + + efile = HPDF_EmbeddedFile_New (pdf->mmgr, pdf->xref, file); + if (!efile) + return NULL; + + name = HPDF_String_New (pdf->mmgr, file, NULL); + if (!name) + return NULL; + + ret += HPDF_NameTree_Add (ntree, name, efile); + if (ret != HPDF_OK) + return NULL; + + return efile; +} + /*----- Info ---------------------------------------------------------------*/ static HPDF_Dict @@ -1976,16 +2126,16 @@ HPDF_SetCompressionMode (HPDF_Doc pdf, if (mode != (mode & HPDF_COMP_MASK)) return HPDF_RaiseError (&pdf->error, HPDF_INVALID_COMPRESSION_MODE, 0); -#ifndef HPDF_NOZLIB +#ifndef LIBHPDF_HAVE_NOZLIB pdf->compression_mode = mode; return HPDF_OK; -#else /* HPDF_NOZLIB */ +#else /* LIBHPDF_HAVE_NOZLIB */ return HPDF_INVALID_COMPRESSION_MODE; -#endif /* HPDF_NOZLIB */ +#endif /* LIBHPDF_HAVE_NOZLIB */ } @@ -2018,3 +2168,201 @@ HPDF_ResetError (HPDF_Doc pdf) HPDF_Error_Reset (&pdf->error); } +/* + * create an intententry + */ +HPDF_EXPORT(HPDF_OutputIntent) +HPDF_OutputIntent_New (HPDF_Doc pdf, + const char* identifier, + const char* condition, + const char* registry, + const char* info, + HPDF_Array outputprofile) +{ + HPDF_OutputIntent intent; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_OutputIntent_New\n")); + + if (!HPDF_HasDoc (pdf)) + return NULL; + + intent = HPDF_Dict_New (pdf->mmgr); + if (!intent) + return NULL; + + if (HPDF_Xref_Add (pdf->xref, intent) != HPDF_OK) { + HPDF_Dict_Free(intent); + return NULL; + } + + ret += HPDF_Dict_AddName (intent, "Type", "OutputIntent"); + ret += HPDF_Dict_AddName (intent, "S", "GTS_PDFX"); + ret += HPDF_Dict_Add (intent, "OutputConditionIdentifier", HPDF_String_New (pdf->mmgr, identifier, NULL)); + ret += HPDF_Dict_Add (intent, "OutputCondition", HPDF_String_New (pdf->mmgr, condition,NULL)); + ret += HPDF_Dict_Add (intent, "RegistryName", HPDF_String_New (pdf->mmgr, registry, NULL)); + + if (info != NULL) { + ret += HPDF_Dict_Add (intent, "Info", HPDF_String_New (pdf->mmgr, info, NULL)); + } + + /* add ICC base stream */ + if (outputprofile != NULL) { + ret += HPDF_Dict_Add (intent, "DestOutputProfile ", outputprofile); + } + + if (ret != HPDF_OK) { + HPDF_Dict_Free(intent); + return NULL; + } + + return intent; +} + +HPDF_EXPORT(HPDF_STATUS) +HPDF_AddIntent(HPDF_Doc pdf, + HPDF_OutputIntent intent) +{ + HPDF_Array intents; + if (!HPDF_HasDoc (pdf)) + return HPDF_INVALID_DOCUMENT; + + intents = HPDF_Dict_GetItem (pdf->catalog, "OutputIntents", HPDF_OCLASS_ARRAY); + if (intents == NULL) { + intents = HPDF_Array_New (pdf->mmgr); + if (intents) { + HPDF_STATUS ret = HPDF_Dict_Add (pdf->catalog, "OutputIntents", intents); + if (ret != HPDF_OK) { + HPDF_CheckError (&pdf->error); + return HPDF_Error_GetDetailCode (&pdf->error); + } + } + } + HPDF_Array_Add(intents,intent); + return HPDF_Error_GetDetailCode (&pdf->error); +} + +/* "Perceptual", "RelativeColorimetric", "Saturation", "AbsoluteColorimetric" */ +HPDF_EXPORT(HPDF_OutputIntent) +HPDF_ICC_LoadIccFromMem (HPDF_Doc pdf, + HPDF_MMgr mmgr, + HPDF_Stream iccdata, + HPDF_Xref xref, + int numcomponent) +{ + HPDF_OutputIntent icc; + HPDF_STATUS ret; + + HPDF_PTRACE ((" HPDF_ICC_LoadIccFromMem\n")); + + icc = HPDF_DictStream_New (mmgr, xref); + if (!icc) + return NULL; + + HPDF_Dict_AddNumber (icc, "N", numcomponent); + switch (numcomponent) { + case 1 : + HPDF_Dict_AddName (icc, "Alternate", "DeviceGray"); + break; + case 3 : + HPDF_Dict_AddName (icc, "Alternate", "DeviceRGB"); + break; + case 4 : + HPDF_Dict_AddName (icc, "Alternate", "DeviceCMYK"); + break; + default : /* unsupported */ + HPDF_RaiseError (&pdf->error, HPDF_INVALID_ICC_COMPONENT_NUM, 0); + HPDF_Dict_Free(icc); + return NULL; + } + + for (;;) { + HPDF_BYTE buf[HPDF_STREAM_BUF_SIZ]; + HPDF_UINT len = HPDF_STREAM_BUF_SIZ; + ret = HPDF_Stream_Read (iccdata, buf, &len); + + if (ret != HPDF_OK) { + if (ret == HPDF_STREAM_EOF) { + if (len > 0) { + ret = HPDF_Stream_Write (icc->stream, buf, len); + if (ret != HPDF_OK) { + HPDF_Dict_Free(icc); + return NULL; + } + } + break; + } else { + HPDF_Dict_Free(icc); + return NULL; + } + } + + if (HPDF_Stream_Write (icc->stream, buf, len) != HPDF_OK) { + HPDF_Dict_Free(icc); + return NULL; + } + } + + return icc; +} + +HPDF_EXPORT(HPDF_Array) +HPDF_AddColorspaceFromProfile (HPDF_Doc pdf, + HPDF_Dict icc) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_Array iccentry; + + if (!HPDF_HasDoc (pdf)) + return NULL; + + iccentry = HPDF_Array_New(pdf->mmgr); + if (!iccentry) + return NULL; + + ret = HPDF_Array_AddName (iccentry, "ICCBased" ); + if (ret != HPDF_OK) { + HPDF_Array_Free(iccentry); + HPDF_CheckError (&pdf->error); + return NULL; + } + + ret = HPDF_Array_Add (iccentry, icc ); + if (ret != HPDF_OK) { + HPDF_Array_Free(iccentry); + return NULL; + } + return iccentry; +} + +HPDF_EXPORT(HPDF_OutputIntent) +HPDF_LoadIccProfileFromFile (HPDF_Doc pdf, + const char* icc_file_name, + int numcomponent) +{ + HPDF_Stream iccdata; + HPDF_OutputIntent iccentry; + + HPDF_PTRACE ((" HPDF_LoadIccProfileFromFile\n")); + + if (!HPDF_HasDoc (pdf)) + return NULL; + + /* create file stream */ + iccdata = HPDF_FileReader_New (pdf->mmgr, icc_file_name); + + if (HPDF_Stream_Validate (iccdata)) { + iccentry = HPDF_ICC_LoadIccFromMem(pdf, pdf->mmgr, iccdata, pdf->xref, numcomponent); + } else + iccentry = NULL; + + /* destroy file stream */ + if (iccdata) + HPDF_Stream_Free (iccdata); + + if (!iccentry) + HPDF_CheckError (&pdf->error); + + return iccentry; +} + diff --git a/PDF/src/hpdf_doc_png.c b/PDF/src/hpdf_doc_png.c index 227cebfef..bad87c655 100644 --- a/PDF/src/hpdf_doc_png.c +++ b/PDF/src/hpdf_doc_png.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_doc_png.c + * << Haru Free PDF Library >> -- hpdf_doc_png.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -24,6 +27,46 @@ LoadPngImageFromStream (HPDF_Doc pdf, HPDF_Stream imagedata, HPDF_BOOL delayed_loading); +HPDF_EXPORT(HPDF_Image) +HPDF_LoadPngImageFromMem (HPDF_Doc pdf, + const HPDF_BYTE *buffer, + HPDF_UINT size) +{ + HPDF_Stream imagedata; + HPDF_Image image; + + HPDF_PTRACE ((" HPDF_LoadPngImageFromFile\n")); + + if (!HPDF_HasDoc (pdf)) { + return NULL; + } + + /* create file stream */ + imagedata = HPDF_MemStream_New (pdf->mmgr, size); + + if (!HPDF_Stream_Validate (imagedata)) { + HPDF_RaiseError (&pdf->error, HPDF_INVALID_STREAM, 0); + return NULL; + } + + if (HPDF_Stream_Write (imagedata, buffer, size) != HPDF_OK) { + HPDF_Stream_Free (imagedata); + return NULL; + } + + image = LoadPngImageFromStream (pdf, imagedata, HPDF_FALSE); + + /* destroy file stream */ + HPDF_Stream_Free (imagedata); + + if (!image) { + HPDF_CheckError (&pdf->error); + } + + return image; + +} + HPDF_EXPORT(HPDF_Image) HPDF_LoadPngImageFromFile (HPDF_Doc pdf, @@ -81,8 +124,10 @@ HPDF_LoadPngImageFromFile2 (HPDF_Doc pdf, if (imagedata) HPDF_Stream_Free (imagedata); - if (!image) + if (!image) { HPDF_CheckError (&pdf->error); + return NULL; + } /* add file-name to image dictionary as a hidden entry. * it is used when the image data is needed. @@ -103,7 +148,7 @@ HPDF_LoadPngImageFromFile2 (HPDF_Doc pdf, return image; } -#ifndef HPDF_NOPNGLIB +#ifndef LIBHPDF_HAVE_NOPNGLIB static HPDF_Image LoadPngImageFromStream (HPDF_Doc pdf, HPDF_Stream imagedata, @@ -129,9 +174,11 @@ LoadPngImageFromStream (HPDF_Doc pdf, HPDF_BOOL delayed_loading) { HPDF_SetError (&pdf->error, HPDF_UNSUPPORTED_FUNC, 0); + HPDF_UNUSED (delayed_loading); + HPDF_UNUSED (imagedata); return NULL; } -#endif /* HPDF_NOPNGLIB */ +#endif /* LIBHPDF_HAVE_NOPNGLIB */ diff --git a/PDF/src/hpdf_encoder.c b/PDF/src/hpdf_encoder.c index 16b4e9bef..a1cbb4b82 100644 --- a/PDF/src/hpdf_encoder.c +++ b/PDF/src/hpdf_encoder.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder.c + * << Haru Free PDF Library >> -- hpdf_encoder.c * - * Copyright (c) 1999-2004 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -1094,7 +1097,7 @@ static const HPDF_UNICODE HPDF_UNICODE_MAP_STANDARD[] = { 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x00D1, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -1129,9 +1132,9 @@ static const HPDF_UNICODE HPDF_UNICODE_MAP_WIN_ANSI[] = { 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000, 0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x017E, 0x0178, - 0x0000, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, - 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x0000, 0x00AE, 0x00AF, - 0x02DA, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, + 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, + 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, + 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, @@ -1156,21 +1159,21 @@ static const HPDF_UNICODE HPDF_UNICODE_MAP_MAC_ROMAN[] = { 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x0000, - 0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x0000, 0x00D6, 0x00DC, 0x00E1, + 0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1, 0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8, 0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3, 0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC, 0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF, - 0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x0000, 0x00C6, 0x00D8, - 0x0000, 0x00B1, 0x0000, 0x0000, 0x00A5, 0x00B5, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x00AA, 0x00BA, 0x0000, 0x00E6, 0x00F8, - 0x00BF, 0x00A1, 0x00AC, 0x0000, 0x0192, 0x0000, 0x0000, 0x00AB, - 0x00BB, 0x2026, 0x0020, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153, - 0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x0000, - 0x00FF, 0x0178, 0x2044, 0x00A4, 0x2039, 0x203A, 0xFB01, 0xFB02, + 0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8, + 0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211, + 0x220F, 0x03C0, 0x222B, 0x00AA, 0x00BA, 0x03A9, 0x00E6, 0x00F8, + 0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB, + 0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153, + 0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA, + 0x00FF, 0x0178, 0x2044, 0x20AC, 0x2039, 0x203A, 0xFB01, 0xFB02, 0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1, 0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4, - 0x0000, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC, + 0xF8FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC, 0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7 }; @@ -2232,6 +2235,7 @@ HPDF_BasicEncoder_New (HPDF_MMgr mmgr, encoder->error = mmgr->error; encoder->type = HPDF_ENCODER_TYPE_SINGLE_BYTE; encoder->to_unicode_fn = HPDF_BasicEncoder_ToUnicode; + encoder->encode_text_fn = NULL; encoder->write_fn = HPDF_BasicEncoder_Write; encoder->free_fn = HPDF_BasicEncoder_Free; @@ -2478,11 +2482,11 @@ HPDF_BasicEncoder_Write (HPDF_Encoder encoder, const char* char_name = HPDF_UnicodeToGryphName (attr->unicode_map[i]); - ptmp = HPDF_IToA (ptmp, i, tmp + HPDF_TMP_BUF_SIZ - 1); + ptmp = HPDF_IToA (ptmp, i, tmp + HPDF_TEXT_DEFAULT_LEN - 1); *ptmp++ = ' '; *ptmp++ = '/'; - ptmp = HPDF_StrCpy (ptmp, char_name, tmp + - HPDF_TMP_BUF_SIZ - 1); + ptmp = (char *)HPDF_StrCpy (ptmp, char_name, tmp + + HPDF_TEXT_DEFAULT_LEN - 1); *ptmp++ = ' '; *ptmp = 0; @@ -2517,7 +2521,7 @@ HPDF_Encoder_Validate (HPDF_Encoder encoder) HPDF_Encoder HPDF_CMapEncoder_New (HPDF_MMgr mmgr, - char *name, + char *name, HPDF_Encoder_Init_Func init_fn) { HPDF_Encoder encoder; @@ -2573,7 +2577,7 @@ HPDF_CMapEncoder_InitAttr (HPDF_Encoder encoder) for (i = 0; i <= 255; i++) { for (j = 0; j <= 255; j++) { - /* undefined characters are replaced to square */ + /* undefined charactors are replaced to square */ encoder_attr->unicode_map[i][j] = 0x25A1; } } @@ -2602,8 +2606,8 @@ HPDF_UNICODE HPDF_CMapEncoder_ToUnicode (HPDF_Encoder encoder, HPDF_UINT16 code) { - HPDF_BYTE l = code; - HPDF_BYTE h = code >> 8; + HPDF_BYTE l = (HPDF_BYTE)code; + HPDF_BYTE h = (HPDF_BYTE)(code >> 8); HPDF_CMapEncoderAttr attr = (HPDF_CMapEncoderAttr)encoder->attr; return attr->unicode_map[l][h]; @@ -2614,15 +2618,14 @@ HPDF_UINT16 HPDF_CMapEncoder_ToCID (HPDF_Encoder encoder, HPDF_UINT16 code) { - HPDF_BYTE l = code; - HPDF_BYTE h = code >> 8; + HPDF_BYTE l = (HPDF_BYTE)code; + HPDF_BYTE h = (HPDF_BYTE)(code >> 8); HPDF_CMapEncoderAttr attr = (HPDF_CMapEncoderAttr)encoder->attr; return attr->cid_map[l][h]; } - void HPDF_CMapEncoder_Free (HPDF_Encoder encoder) { @@ -2674,6 +2677,8 @@ HPDF_CMapEncoder_Write (HPDF_Encoder encoder, HPDF_Stream out) { HPDF_STATUS ret = HPDF_OK; + HPDF_UNUSED (out); + HPDF_UNUSED (encoder); return ret; } @@ -2686,6 +2691,7 @@ HPDF_Encoder_SetParseText (HPDF_Encoder encoder, HPDF_UINT len) { HPDF_PTRACE ((" HPDF_CMapEncoder_SetParseText\n")); + HPDF_UNUSED (encoder); state->text = text; state->index = 0; @@ -2745,20 +2751,26 @@ HPDF_CMapEncoder_AddCMap (HPDF_Encoder encoder, HPDF_PTRACE ((" HPDF_CMapEncoder_AddCMap\n")); /* Copy specified pdf_cid_range array to fRangeArray. */ - while (range->from != 0xffff && range->to != 0xffff) { - HPDF_UINT16 code = range->from; - HPDF_UINT16 cid = range->cid; - HPDF_CidRange_Rec *prange; - HPDF_STATUS ret; + while (range->from != 0xffff || range->to != 0xffff) { + HPDF_CidRange_Rec *prange; + HPDF_STATUS ret; - while (code <= range->to) { - HPDF_BYTE l = code; - HPDF_BYTE h = code >> 8; + /* + * Only if we have the default to_unicode_fn + */ + if (encoder->to_unicode_fn == HPDF_CMapEncoder_ToUnicode) { + HPDF_UINT16 code = range->from; + HPDF_UINT16 cid = range->cid; - attr->cid_map[l][h] = cid; - code++; - cid++; - } + while (code <= range->to) { + HPDF_BYTE l = code; + HPDF_BYTE h = code >> 8; + + attr->cid_map[l][h] = cid; + code++; + cid++; + } + } prange = HPDF_GetMem (encoder->mmgr, sizeof(HPDF_CidRange_Rec)); if (!prange) @@ -2840,8 +2852,8 @@ HPDF_CMapEncoder_SetUnicodeArray (HPDF_Encoder encoder, if (array != NULL) while (array->unicode != 0xffff) { - HPDF_BYTE l = array->code; - HPDF_BYTE h = array->code >> 8; + HPDF_BYTE l = (HPDF_BYTE)array->code; + HPDF_BYTE h = (HPDF_BYTE)(array->code >> 8); attr->unicode_map[l][h] = array->unicode; array++; } @@ -2943,7 +2955,7 @@ HPDF_Encoder_GetByteType (HPDF_Encoder encoder, if (encoder->type != HPDF_ENCODER_TYPE_DOUBLE_BYTE) return HPDF_BYTE_TYPE_SINGLE; - HPDF_Encoder_SetParseText (encoder, &parse_state, text, index + 1); + HPDF_Encoder_SetParseText (encoder, &parse_state, (HPDF_BYTE *)text, index + 1); for (;;) { btype = HPDF_CMapEncoder_ByteType (encoder, &parse_state); @@ -2988,4 +3000,3 @@ HPDF_Encoder_GetWritingMode (HPDF_Encoder encoder) return HPDF_WMODE_HORIZONTAL; } - diff --git a/PDF/src/hpdf_encoder_cns.c b/PDF/src/hpdf_encoder_cns.c index 8660de2ca..e525c233f 100644 --- a/PDF/src/hpdf_encoder_cns.c +++ b/PDF/src/hpdf_encoder_cns.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder_cns.c + * << Haru Free PDF Library >> -- hpdf_encoder_cns.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -36074,6 +36077,7 @@ static HPDF_BOOL GBK_EUC_IsLeadByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return ((b >= 0x81 && b <= 0xfe)); } @@ -36082,6 +36086,7 @@ static HPDF_BOOL GBK_EUC_IsTrialByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0x40 && b <= 0xfe); } @@ -36197,6 +36202,7 @@ static HPDF_BOOL GB_EUC_IsLeadByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0xa1 && b <= 0xfe); } @@ -36205,6 +36211,7 @@ static HPDF_BOOL GB_EUC_IsTrialByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0xa1 && b <= 0xfe); } diff --git a/PDF/src/hpdf_encoder_cnt.c b/PDF/src/hpdf_encoder_cnt.c index e8538cce8..a3714fc72 100644 --- a/PDF/src/hpdf_encoder_cnt.c +++ b/PDF/src/hpdf_encoder_cnt.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder_cnt.c + * << Haru Free PDF Library >> -- hpdf_encoder_cnt.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -15155,6 +15158,7 @@ static HPDF_BOOL ETen_B5_IsLeadByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return ((b >= 0x81 && b <= 0xfe)); } @@ -15163,6 +15167,7 @@ static HPDF_BOOL ETen_B5_IsTrialByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0x40 && b <= 0xfe); } diff --git a/PDF/src/hpdf_encoder_jp.c b/PDF/src/hpdf_encoder_jp.c index 20e878f9c..11e5daf17 100644 --- a/PDF/src/hpdf_encoder_jp.c +++ b/PDF/src/hpdf_encoder_jp.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder_jp.c + * << Haru Free PDF Library >> -- hpdf_encoder_jp.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -15769,6 +15772,7 @@ static HPDF_BOOL RKSJ_IsLeadByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return ((b >= 0x81 && b <= 0x9f) || (b >= 0xe0 && b <= 0xfc)); } @@ -15777,6 +15781,7 @@ static HPDF_BOOL RKSJ_IsTrialByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0x40 && b <= 0xfc && b != 0x7f); } @@ -15950,6 +15955,7 @@ static HPDF_BOOL EUC_IsLeadByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return ((b >= 0xa1 && b <= 0xfe) || b == 0x8e); } @@ -15958,6 +15964,7 @@ static HPDF_BOOL EUC_IsTrialByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0xa0 && b <= 0xfe); } diff --git a/PDF/src/hpdf_encoder_kr.c b/PDF/src/hpdf_encoder_kr.c index 77fc4d21d..540b109f4 100644 --- a/PDF/src/hpdf_encoder_kr.c +++ b/PDF/src/hpdf_encoder_kr.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder_kr.c + * << Haru Free PDF Library >> -- hpdf_encoder_kr.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -27639,6 +27642,7 @@ static HPDF_BOOL KSCms_UHC_IsLeadByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0x81 && b <= 0xFE); } @@ -27647,6 +27651,7 @@ static HPDF_BOOL KSCms_UHC_IsTrialByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0x41 && b <= 0xfe); } @@ -27804,6 +27809,7 @@ static HPDF_BOOL KSC_EUC_IsLeadByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0xa1 && b <= 0xfe); } @@ -27812,6 +27818,7 @@ static HPDF_BOOL KSC_EUC_IsTrialByte (HPDF_Encoder encoder, HPDF_BYTE b) { + HPDF_UNUSED (encoder); return (b >= 0xa0 && b <= 0xfe); } diff --git a/PDF/src/hpdf_encoder_utf.c b/PDF/src/hpdf_encoder_utf.c new file mode 100644 index 000000000..b8dd7342f --- /dev/null +++ b/PDF/src/hpdf_encoder_utf.c @@ -0,0 +1,276 @@ +/* + * << Haru Free PDF Library >> -- hpdf_encoder_utf.c + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2008 Antony Dovgal + * Copyright (c) 2010 Sergey Konovalov + * Copyright (c) 2011 Koen Deforche + * + * 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 "hpdf_conf.h" +#include "hpdf_utils.h" +#include "hpdf_encoder.h" +#include "hpdf.h" + +typedef struct _UTF8_EncoderAttr_Rec *UTF8_EncoderAttr; +typedef struct _UTF8_EncoderAttr_Rec { + HPDF_BYTE current_byte; + HPDF_BYTE end_byte; + HPDF_BYTE utf8_bytes[8]; +} UTF8_EncoderAttr_Rec; + +static const HPDF_CidRange_Rec UTF8_NOTDEF_RANGE = {0x0000, 0x001F, 1}; +static const HPDF_CidRange_Rec UTF8_SPACE_RANGE = {0x0000, 0xFFFF, 0}; +static const HPDF_CidRange_Rec UTF8_CID_RANGE[] = { + { 0x0000, 0xFFFF, 0x0 }, + { 0xFFFF, 0xFFFF, 0x0 } +}; + +static HPDF_ByteType +UTF8_Encoder_ByteType_Func (HPDF_Encoder encoder, + HPDF_ParseText_Rec *state); + +static HPDF_UNICODE +UTF8_Encoder_ToUnicode_Func (HPDF_Encoder encoder, + HPDF_UINT16 code); + +static char * +UTF8_Encoder_EncodeText_Func (HPDF_Encoder encoder, + const char *text, + HPDF_UINT len, + HPDF_UINT *length); + +static HPDF_STATUS +UTF8_Init (HPDF_Encoder encoder); + +/*--------------------------------------------------------------------------*/ + + +/* + * This function is taken from hpdf_encoder_utf8.c, originally submitted + * to libharu by 'Mirco' + */ +static HPDF_ByteType +UTF8_Encoder_ByteType_Func (HPDF_Encoder encoder, + HPDF_ParseText_Rec *state) +{ + // This function is supposed to increment state->index + // Not logical ! (look at function HPDF_String_Write in hpdf_string.c) + + // When HPDF_BYTE_TYPE_SINGLE is returned, the current byte is the + // CODE argument in call ToUnicode_Func + // When HPDF_BYTE_TYPE_LEAD is returned, the current byte (msb) and the + // next byte (lsb) is the CODE arguement in call ToUnicodeFunc + // When HPDF_BYTE_TYPE_TRIAL is returned, the current byte is ignored + + HPDF_CMapEncoderAttr encoder_attr; + HPDF_BYTE byte; + UTF8_EncoderAttr utf8_attr; + + encoder_attr = (HPDF_CMapEncoderAttr) encoder->attr; + utf8_attr = (UTF8_EncoderAttr) ((void *)encoder_attr->cid_map[0]); + + if (state->index == 0) { + //First byte, initialize. + HPDF_PTRACE ((" UTF8_Encoder_ByteType_Func - Initialize: (%u) %s\n", + state->len, state->text)); + + utf8_attr->current_byte = 0; + } + + byte = state->text[state->index]; + state->index++; + + HPDF_PTRACE ((" UTF8_Encoder_ByteType_Func - Byte: %hx\n", byte)); + + if (utf8_attr->current_byte == 0) { + utf8_attr->utf8_bytes[0] = byte; + utf8_attr->current_byte = 1; + + if (!(byte & 0x80)) { + utf8_attr->current_byte = 0; + utf8_attr->end_byte = 0; + return HPDF_BYTE_TYPE_SINGLE; + } + + if ((byte & 0xf8) == 0xf0) + utf8_attr->end_byte = 3; + else if ((byte & 0xf0) == 0xe0) + utf8_attr->end_byte = 2; + else if ((byte & 0xe0) == 0xc0) + utf8_attr->end_byte = 1; + else + utf8_attr->current_byte = 0; //ERROR, skip this byte + } else { + utf8_attr->utf8_bytes[utf8_attr->current_byte] = byte; + if (utf8_attr->current_byte == utf8_attr->end_byte) { + utf8_attr->current_byte = 0; + return HPDF_BYTE_TYPE_SINGLE; + } + + utf8_attr->current_byte++; + } + + return HPDF_BYTE_TYPE_TRIAL; +} + +/* + * This function is taken from hpdf_encoder_utf8.c, originally submitted + * to libharu by 'Mirco' + */ +static HPDF_UNICODE +UTF8_Encoder_ToUnicode_Func (HPDF_Encoder encoder, + HPDF_UINT16 code) +{ + // Supposed to convert CODE to unicode. + // This function is allways called after ByteType_Func. + // ByteType_Func recognizes the utf-8 bytes belonging to one character. + + HPDF_CMapEncoderAttr encoder_attr; + UTF8_EncoderAttr utf8_attr; + unsigned int val; + + encoder_attr = (HPDF_CMapEncoderAttr) encoder->attr; + utf8_attr = (UTF8_EncoderAttr) ((void *)encoder_attr->cid_map[0]); + + switch (utf8_attr->end_byte) { + case 3: + val = (unsigned int) ((utf8_attr->utf8_bytes[0] & 0x7) << 18) + + (unsigned int) ((utf8_attr->utf8_bytes[1]) << 12) + + (unsigned int) ((utf8_attr->utf8_bytes[2] & 0x3f) << 6) + + (unsigned int) ((utf8_attr->utf8_bytes[3] & 0x3f)); + break; + case 2: + val = (unsigned int) ((utf8_attr->utf8_bytes[0] & 0xf) << 12) + + (unsigned int) ((utf8_attr->utf8_bytes[1] & 0x3f) << 6) + + (unsigned int) ((utf8_attr->utf8_bytes[2] & 0x3f)); + break; + case 1: + val = (unsigned int) ((utf8_attr->utf8_bytes[0] & 0x1f) << 6) + + (unsigned int) ((utf8_attr->utf8_bytes[1] & 0x3f)); + break; + case 0: + val = (unsigned int) utf8_attr->utf8_bytes[0]; + break; + default: + val = 32; // Unknown character + } + + if (val > 65535) //Convert everything outside UCS-2 to space + val = 32; + + return val; +} + +static char * +UTF8_Encoder_EncodeText_Func (HPDF_Encoder encoder, + const char *text, + HPDF_UINT len, + HPDF_UINT *length) +{ + char *result = malloc(len * 2); + char *c = result; + HPDF_ParseText_Rec parse_state; + HPDF_UINT i; + + HPDF_Encoder_SetParseText (encoder, &parse_state, + (const HPDF_BYTE *)text, len); + + for (i = 0; i < len; i++) { + HPDF_UNICODE tmp_unicode; + HPDF_ByteType btype = HPDF_Encoder_ByteType (encoder, &parse_state); + + if (btype != HPDF_BYTE_TYPE_TRIAL) { + tmp_unicode = HPDF_Encoder_ToUnicode (encoder, 0); + + HPDF_UInt16Swap (&tmp_unicode); + HPDF_MemCpy ((HPDF_BYTE *)c, (const HPDF_BYTE*)&tmp_unicode, 2); + c += 2; + } + } + + *length = c - result; + + return result; +} + +static HPDF_STATUS +UTF8_Init (HPDF_Encoder encoder) +{ + HPDF_CMapEncoderAttr attr; + HPDF_STATUS ret; + + if ((ret = HPDF_CMapEncoder_InitAttr (encoder)) != HPDF_OK) + return ret; + + /* + * We override these two + */ + encoder->byte_type_fn = UTF8_Encoder_ByteType_Func; + encoder->to_unicode_fn = UTF8_Encoder_ToUnicode_Func; + encoder->encode_text_fn = UTF8_Encoder_EncodeText_Func; + + attr = (HPDF_CMapEncoderAttr)encoder->attr; + + if (HPDF_CMapEncoder_AddCMap (encoder, UTF8_CID_RANGE) != HPDF_OK) + return encoder->error->error_no; + + if (HPDF_CMapEncoder_AddCodeSpaceRange (encoder, UTF8_SPACE_RANGE) + != HPDF_OK) + return encoder->error->error_no; + + if (HPDF_CMapEncoder_AddNotDefRange (encoder, UTF8_NOTDEF_RANGE) + != HPDF_OK) + return encoder->error->error_no; + + attr->is_lead_byte_fn = NULL; + attr->is_trial_byte_fn = NULL; + + HPDF_StrCpy (attr->registry, "Adobe", attr->registry + + HPDF_LIMIT_MAX_NAME_LEN); + HPDF_StrCpy (attr->ordering, "Identity-H", attr->ordering + + HPDF_LIMIT_MAX_NAME_LEN); + attr->suppliment = 0; + attr->writing_mode = HPDF_WMODE_HORIZONTAL; + + /* Not sure about this + attr->uid_offset = 0; + attr->xuid[0] = 0; + attr->xuid[1] = 0; + attr->xuid[2] = 0; + */ + + encoder->type = HPDF_ENCODER_TYPE_DOUBLE_BYTE; + + return HPDF_OK; +} + +/*--------------------------------------------------------------------------*/ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_UseUTFEncodings (HPDF_Doc pdf) +{ + HPDF_Encoder encoder; + HPDF_STATUS ret; + + if (!HPDF_HasDoc (pdf)) + return HPDF_INVALID_DOCUMENT; + + encoder = HPDF_CMapEncoder_New (pdf->mmgr, "UTF-8", + UTF8_Init); + + if ((ret = HPDF_Doc_RegisterEncoder (pdf, encoder)) != HPDF_OK) + return ret; + + return HPDF_OK; +} diff --git a/PDF/src/hpdf_encrypt.c b/PDF/src/hpdf_encrypt.c index 8f94d137d..a534995f5 100644 --- a/PDF/src/hpdf_encrypt.c +++ b/PDF/src/hpdf_encrypt.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_encryor.c + * << Haru Free PDF Library >> -- hpdf_encryor.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -314,13 +317,13 @@ HPDF_PadOrTrancatePasswd (const char *pwd, HPDF_MemSet (new_pwd, 0x00, HPDF_PASSWD_LEN); - if (len >= HPDF_PASSWD_LEN) - HPDF_MemCpy (new_pwd, pwd, HPDF_PASSWD_LEN); - else { - if (len > 0) - HPDF_MemCpy (new_pwd, pwd, len); - HPDF_MemCpy (new_pwd + len, HPDF_PADDING_STRING, - HPDF_PASSWD_LEN - len); + if (len >= HPDF_PASSWD_LEN) { + HPDF_MemCpy (new_pwd, (HPDF_BYTE *)pwd, HPDF_PASSWD_LEN); + } else { + if (len > 0) { + HPDF_MemCpy (new_pwd, (HPDF_BYTE *)pwd, len); + } + HPDF_MemCpy (new_pwd + len, HPDF_PADDING_STRING, HPDF_PASSWD_LEN - len); } } @@ -365,7 +368,7 @@ HPDF_Encrypt_CreateOwnerKey (HPDF_Encrypt attr) for (i = 0; i < 50; i++) { HPDF_MD5Init(&md5_ctx); - //HPDF_MD5Update (&md5_ctx, digest, HPDF_MD5_KEY_LEN); + /* HPDF_MD5Update (&md5_ctx, digest, HPDF_MD5_KEY_LEN); */ HPDF_MD5Update (&md5_ctx, digest, attr->key_len); HPDF_MD5Final(digest, &md5_ctx); @@ -395,7 +398,7 @@ HPDF_Encrypt_CreateOwnerKey (HPDF_Encrypt attr) HPDF_BYTE new_key[HPDF_MD5_KEY_LEN]; for (j = 0; j < attr->key_len; j++) - new_key[j] = digest[j] ^ i; + new_key[j] = (HPDF_BYTE)(digest[j] ^ i); HPDF_PTRACE(("@ Algorithm 3.3 step 7 loop %u\n", i)); @@ -429,10 +432,10 @@ HPDF_Encrypt_CreateEncryptionKey (HPDF_Encrypt attr) /* Algorithm3.2 step4 */ HPDF_PTRACE(("@@@ permission =%d\n", attr->permission)); - tmp_flg[0] = attr->permission; - tmp_flg[1] = (attr->permission >> 8); - tmp_flg[2] = (attr->permission >> 16); - tmp_flg[3] = (attr->permission >> 24); + tmp_flg[0] = (HPDF_BYTE)(attr->permission); + tmp_flg[1] = (HPDF_BYTE)(attr->permission >> 8); + tmp_flg[2] = (HPDF_BYTE)(attr->permission >> 16); + tmp_flg[3] = (HPDF_BYTE)(attr->permission >> 24); HPDF_MD5Update(&md5_ctx, tmp_flg, 4); @@ -499,7 +502,7 @@ HPDF_Encrypt_CreateUserKey (HPDF_Encrypt attr) HPDF_PTRACE(("@ Algorithm 3.5 step 5 loop %u\n", i)); for (j = 0; j < attr->key_len; j++) - new_key[j] = attr->encryption_key[j] ^ i; + new_key[j] = (HPDF_BYTE)(attr->encryption_key[j] ^ i); HPDF_MemCpy (digest, digest2, HPDF_MD5_KEY_LEN); @@ -526,7 +529,7 @@ ARC4Init (HPDF_ARC4_Ctx_Rec *ctx, HPDF_PTRACE((" ARC4Init\n")); for (i = 0; i < HPDF_ARC4_BUF_SIZE; i++) - ctx->state[i] = i; + ctx->state[i] = (HPDF_BYTE)i; for (i = 0; i < HPDF_ARC4_BUF_SIZE; i++) tmp_array[i] = key[i % key_len]; @@ -561,8 +564,8 @@ ARC4CryptBuf (HPDF_ARC4_Ctx_Rec *ctx, for (i = 0; i < len; i++) { HPDF_BYTE tmp; - ctx->idx1 = (ctx->idx1 + 1) % 256; - ctx->idx2 = (ctx->idx2 + ctx->state[ctx->idx1]) % 256; + ctx->idx1 = (HPDF_BYTE)((ctx->idx1 + 1) % 256); + ctx->idx2 = (HPDF_BYTE)((ctx->idx2 + ctx->state[ctx->idx1]) % 256); tmp = ctx->state[ctx->idx1]; ctx->state[ctx->idx1] = ctx->state[ctx->idx2]; @@ -571,7 +574,7 @@ ARC4CryptBuf (HPDF_ARC4_Ctx_Rec *ctx, t = (ctx->state[ctx->idx1] + ctx->state[ctx->idx2]) % 256; K = ctx->state[t]; - out[i] = in[i] ^ K; + out[i] = (HPDF_BYTE)(in[i] ^ K); } } @@ -586,11 +589,11 @@ HPDF_Encrypt_InitKey (HPDF_Encrypt attr, HPDF_PTRACE((" HPDF_Encrypt_Init\n")); - attr->encryption_key[attr->key_len] = object_id; - attr->encryption_key[attr->key_len + 1] = (object_id >> 8); - attr->encryption_key[attr->key_len + 2] = (object_id >> 16); - attr->encryption_key[attr->key_len + 3] = gen_no; - attr->encryption_key[attr->key_len + 4] = (gen_no >> 8); + attr->encryption_key[attr->key_len] = (HPDF_BYTE)object_id; + attr->encryption_key[attr->key_len + 1] = (HPDF_BYTE)(object_id >> 8); + attr->encryption_key[attr->key_len + 2] = (HPDF_BYTE)(object_id >> 16); + attr->encryption_key[attr->key_len + 3] = (HPDF_BYTE)gen_no; + attr->encryption_key[attr->key_len + 4] = (HPDF_BYTE)(gen_no >> 8); HPDF_PTRACE(("@@@ OID=%u, gen_no=%u\n", (HPDF_INT)object_id, gen_no)); diff --git a/PDF/src/hpdf_encryptdict.c b/PDF/src/hpdf_encryptdict.c index 35df23f7e..1708d7737 100644 --- a/PDF/src/hpdf_encryptdict.c +++ b/PDF/src/hpdf_encryptdict.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.5 >> -- hpdf_encryptdict.c + * << Haru Free PDF Library >> -- hpdf_encryptdict.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -10,8 +13,7 @@ * in supporting documentation. * It is provided "as is" without express or implied warranty. * - * 2006.09.04 modified. - *---------------------------------------------------------------------------*/ + */ #include #include "hpdf_conf.h" @@ -19,10 +21,9 @@ #include "hpdf_objects.h" #include "hpdf_encryptdict.h" #include "hpdf_info.h" - -/*---------------------------------------------------------------------------*/ -/*------ HPDF_EncryptDict ---------------------------------------------------*/ - +#ifndef HPDF_UNUSED +#define HPDF_UNUSED(a) ((void)(a)) +#endif HPDF_EncryptDict HPDF_EncryptDict_New (HPDF_MMgr mmgr, @@ -67,13 +68,15 @@ HPDF_EncryptDict_CreateID (HPDF_EncryptDict dict, /* use the result of 'time' function to get random value. * when debugging, 'time' value is ignored. */ -#ifndef HPDF_DEBUG +#ifndef LIBHPDF_DEBUG time_t t = HPDF_TIME (NULL); -#endif /* HPDF_DEBUG */ +#endif /* LIBHPDF_DEBUG */ HPDF_MD5Init (&ctx); + HPDF_UNUSED (xref); + HPDF_UNUSED (info); -#ifndef HPDF_DEBUG +#ifndef LIBHPDF_DEBUG HPDF_MD5Update(&ctx, (HPDF_BYTE *)&t, sizeof(t)); /* create File Identifier from elements of Into dictionary. */ diff --git a/PDF/src/hpdf_error.c b/PDF/src/hpdf_error.c index 5f2913f56..7a82f79e1 100644 --- a/PDF/src/hpdf_error.c +++ b/PDF/src/hpdf_error.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_error.c + * << Haru Free PDF Library >> -- hpdf_error.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -16,6 +19,7 @@ #include "hpdf_utils.h" #include "hpdf_error.h" #include "hpdf_consts.h" +#include "hpdf.h" #ifndef HPDF_STDCALL #ifdef HPDF_DLL_MAKE @@ -80,7 +84,7 @@ HPDF_SetError (HPDF_Error error, } -HPDF_STATUS +HPDF_EXPORT(HPDF_STATUS) HPDF_CheckError (HPDF_Error error) { HPDF_PTRACE((" HPDF_CheckError: error_no=0x%04X detail_no=0x%04X\n", diff --git a/PDF/src/hpdf_exdata.c b/PDF/src/hpdf_exdata.c new file mode 100644 index 000000000..d63aab249 --- /dev/null +++ b/PDF/src/hpdf_exdata.c @@ -0,0 +1,69 @@ +/* + * << Haru Free PDF Library >> -- hpdf_annotation.c + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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 "hpdf_conf.h" +#include "hpdf_utils.h" +#include "hpdf_info.h" +#include "hpdf_exdata.h" +#include "hpdf.h" + +/*----------------------------------------------------------------------------*/ +/*------ HPDF_ExData -----------------------------------------------------*/ + + + +HPDF_ExData +HPDF_3DAnnotExData_New(HPDF_MMgr mmgr, + HPDF_Xref xref) +{ + HPDF_ExData exdata; + HPDF_STATUS ret = HPDF_OK; + + + HPDF_PTRACE((" HPDF_ExData_New\n")); + + exdata = HPDF_Dict_New (mmgr); + if (!exdata) + return NULL; + + if (HPDF_Xref_Add (xref, exdata) != HPDF_OK) + return NULL; + + ret += HPDF_Dict_AddName (exdata, "Type", "ExData"); + ret += HPDF_Dict_AddName (exdata, "Subtype", "3DM"); + + if (ret != HPDF_OK) + return NULL; + + return exdata; +} + + + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DAnnotExData_Set3DMeasurement(HPDF_ExData exdata, + HPDF_3DMeasure measure) +{ + HPDF_STATUS ret = HPDF_OK; + + ret = HPDF_Dict_Add (exdata, "M3DREF", measure); + if (ret != HPDF_OK) + return ret; + + return ret; +} + diff --git a/PDF/src/hpdf_ext_gstate.c b/PDF/src/hpdf_ext_gstate.c index 812fb4b40..60347d04e 100644 --- a/PDF/src/hpdf_ext_gstate.c +++ b/PDF/src/hpdf_ext_gstate.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_ext_gstate.c + * << Haru Free PDF Library >> -- hpdf_ext_gstate.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -17,7 +20,7 @@ #include "hpdf_ext_gstate.h" #include "hpdf.h" -const static char *HPDF_BM_NAMES[] = { +static const char * const HPDF_BM_NAMES[] = { "Normal", "Multiply", "Screen", @@ -36,7 +39,7 @@ const static char *HPDF_BM_NAMES[] = { HPDF_BOOL HPDF_ExtGState_Validate (HPDF_ExtGState ext_gstate) { - if (!ext_gstate || (ext_gstate->header.obj_class != + if (!ext_gstate || (ext_gstate->header.obj_class != (HPDF_OSUBCLASS_EXT_GSTATE | HPDF_OCLASS_DICT) && ext_gstate->header.obj_class != (HPDF_OSUBCLASS_EXT_GSTATE_R | HPDF_OCLASS_DICT))) @@ -51,8 +54,8 @@ ExtGState_Check (HPDF_ExtGState ext_gstate) { if (!HPDF_ExtGState_Validate (ext_gstate)) return HPDF_INVALID_OBJECT; - - if (ext_gstate->header.obj_class == + + if (ext_gstate->header.obj_class == (HPDF_OSUBCLASS_EXT_GSTATE_R | HPDF_OCLASS_DICT)) return HPDF_RaiseError (ext_gstate->error, HPDF_EXT_GSTATE_READ_ONLY, 0); @@ -62,7 +65,7 @@ ExtGState_Check (HPDF_ExtGState ext_gstate) HPDF_Dict -HPDF_ExtGState_New (HPDF_MMgr mmgr, +HPDF_ExtGState_New (HPDF_MMgr mmgr, HPDF_Xref xref) { HPDF_Dict obj = HPDF_Dict_New (mmgr); @@ -89,12 +92,12 @@ HPDF_ExtGState_SetAlphaStroke (HPDF_ExtGState ext_gstate, HPDF_REAL value) { HPDF_STATUS ret = ExtGState_Check (ext_gstate); - + if (ret != HPDF_OK) return ret; - + if (value < 0 || value > 1.0f) - return HPDF_RaiseError (ext_gstate->error, + return HPDF_RaiseError (ext_gstate->error, HPDF_EXT_GSTATE_OUT_OF_RANGE, 0); return HPDF_Dict_AddReal (ext_gstate, "CA", value); @@ -106,12 +109,12 @@ HPDF_ExtGState_SetAlphaFill (HPDF_ExtGState ext_gstate, HPDF_REAL value) { HPDF_STATUS ret = ExtGState_Check (ext_gstate); - + if (ret != HPDF_OK) return ret; if (value < 0 || value > 1.0f) - return HPDF_RaiseError (ext_gstate->error, + return HPDF_RaiseError (ext_gstate->error, HPDF_EXT_GSTATE_OUT_OF_RANGE, 0); return HPDF_Dict_AddReal (ext_gstate, "ca", value); @@ -123,12 +126,12 @@ HPDF_ExtGState_SetBlendMode (HPDF_ExtGState ext_gstate, HPDF_BlendMode bmode) { HPDF_STATUS ret = ExtGState_Check (ext_gstate); - + if (ret != HPDF_OK) return ret; if ((int)bmode < 0 || (int)bmode > (int)HPDF_BM_EOF) - return HPDF_RaiseError (ext_gstate->error, + return HPDF_RaiseError (ext_gstate->error, HPDF_EXT_GSTATE_OUT_OF_RANGE, 0); return HPDF_Dict_AddName (ext_gstate, "BM", HPDF_BM_NAMES[(int)bmode]); @@ -140,7 +143,7 @@ HPDF_ExtGState_SetStrokeAdjustment (HPDF_ExtGState ext_gstate, HPDF_BOOL value) { HPDF_STATUS ret = ExtGState_Check (ext_gstate); - + if (ret != HPDF_OK) return ret; diff --git a/PDF/src/hpdf_font.c b/PDF/src/hpdf_font.c index 25a4a0d95..114d8f733 100644 --- a/PDF/src/hpdf_font.c +++ b/PDF/src/hpdf_font.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_font.c + * << Haru Free PDF Library >> -- hpdf_font.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -10,7 +13,6 @@ * in supporting documentation. * It is provided "as is" without express or implied warranty. * - * 2006.07.25 modified. */ #include "hpdf_conf.h" diff --git a/PDF/src/hpdf_font_cid.c b/PDF/src/hpdf_font_cid.c index 7fa32ba25..d1c1a824f 100644 --- a/PDF/src/hpdf_font_cid.c +++ b/PDF/src/hpdf_font_cid.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_font_cid.c + * << Haru Free PDF Library >> -- hpdf_font_cid.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -10,7 +13,6 @@ * in supporting documentation. * It is provided "as is" without express or implied warranty. * - * 2006.08.04 modified MeasureText(). */ #include "hpdf_conf.h" @@ -46,10 +48,16 @@ MeasureText (HPDF_Font font, static char* -UINT16ToHex (char *s, - HPDF_UINT16 val, - char *eptr); +UINT16ToHex (char *s, + HPDF_UINT16 val, + char *eptr, + HPDF_BYTE width); +static char * +CidRangeToHex (char *s, + HPDF_UINT16 from, + HPDF_UINT16 to, + char *eptr); static HPDF_Dict CreateCMap (HPDF_Encoder encoder, @@ -130,12 +138,31 @@ HPDF_Type0Font_New (HPDF_MMgr mmgr, if (fontdef->type == HPDF_FONTDEF_TYPE_CID) { ret += HPDF_Dict_AddName (font, "Encoding", encoder->name); } else { - attr->cmap_stream = CreateCMap (encoder, xref); + /* + * Handle the Unicode encoding, see hpdf_encoding_utf.c For some + * reason, xpdf-based readers cannot deal with our cmap but work + * fine when using the predefined "Identity-H" + * encoding. However, text selection does not work, unless we + * add a ToUnicode cmap. This CMap should also be "Identity", + * but that does not work -- specifying our cmap as a stream however + * does work. Who can understand that ? + */ + if (HPDF_StrCmp(encoder_attr->ordering, "Identity-H") == 0) { + ret += HPDF_Dict_AddName (font, "Encoding", "Identity-H"); + attr->cmap_stream = CreateCMap (encoder, xref); - if (attr->cmap_stream) { - ret += HPDF_Dict_Add (font, "Encoding", attr->cmap_stream); - } else - return NULL; + if (attr->cmap_stream) { + ret += HPDF_Dict_Add (font, "ToUnicode", attr->cmap_stream); + } else + return NULL; + } else { + attr->cmap_stream = CreateCMap (encoder, xref); + + if (attr->cmap_stream) { + ret += HPDF_Dict_Add (font, "Encoding", attr->cmap_stream); + } else + return NULL; + } } if (ret != HPDF_OK) @@ -357,9 +384,9 @@ CIDFontType2_New (HPDF_Font parent, HPDF_Xref xref) if (HPDF_Dict_Add (font, "DW2", array) != HPDF_OK) return NULL; - ret += HPDF_Array_AddNumber (array, fontdef->font_bbox.bottom); - ret += HPDF_Array_AddNumber (array, fontdef->font_bbox.bottom - - fontdef->font_bbox.top); + ret += HPDF_Array_AddNumber (array, (HPDF_INT32)(fontdef->font_bbox.bottom)); + ret += HPDF_Array_AddNumber (array, (HPDF_INT32)(fontdef->font_bbox.bottom - + fontdef->font_bbox.top)); HPDF_MemSet (tmp_map, 0, sizeof(HPDF_UNICODE) * 65536); @@ -370,15 +397,25 @@ CIDFontType2_New (HPDF_Font parent, HPDF_Xref xref) HPDF_UINT j; for (j = 0; j < 256; j++) { - HPDF_UINT16 cid = encoder_attr->cid_map[i][j]; - if (cid != 0) { - HPDF_UNICODE unicode = encoder_attr->unicode_map[i][j]; - HPDF_UINT16 gid = HPDF_TTFontDef_GetGlyphid (fontdef, unicode); - tmp_map[cid] = gid; - if (max < cid) - max = cid; - } - } + if (encoder->to_unicode_fn == HPDF_CMapEncoder_ToUnicode) { + HPDF_UINT16 cid = encoder_attr->cid_map[i][j]; + if (cid != 0) { + HPDF_UNICODE unicode = encoder_attr->unicode_map[i][j]; + HPDF_UINT16 gid = HPDF_TTFontDef_GetGlyphid (fontdef, + unicode); + tmp_map[cid] = gid; + if (max < cid) + max = cid; + } + } else { + HPDF_UNICODE unicode = (i << 8) | j; + HPDF_UINT16 gid = HPDF_TTFontDef_GetGlyphid (fontdef, + unicode); + tmp_map[unicode] = gid; + if (max < unicode) + max = unicode; + } + } } if (max > 0) { @@ -399,14 +436,14 @@ CIDFontType2_New (HPDF_Font parent, HPDF_Xref xref) if (w != dw) { if (!tmp_array) { - if ((ret = HPDF_Array_AddNumber (array, i)) != HPDF_OK) + if (HPDF_Array_AddNumber (array, i) != HPDF_OK) return NULL; tmp_array = HPDF_Array_New (font->mmgr); if (!tmp_array) return NULL; - if ((ret = HPDF_Array_Add (array, tmp_array)) != HPDF_OK) + if (HPDF_Array_Add (array, tmp_array) != HPDF_OK) return NULL; } @@ -422,16 +459,15 @@ CIDFontType2_New (HPDF_Font parent, HPDF_Xref xref) if (!attr->map_stream) return NULL; - if ((ret = HPDF_Dict_Add (font, "CIDToGIDMap", attr->map_stream)) - != HPDF_OK) + if (HPDF_Dict_Add (font, "CIDToGIDMap", attr->map_stream) != HPDF_OK) return NULL; for (i = 0; i < max; i++) { HPDF_BYTE u[2]; HPDF_UINT16 gid = tmp_map[i]; - u[0] = gid >> 8; - u[1] = gid; + u[0] = (HPDF_BYTE)(gid >> 8); + u[1] = (HPDF_BYTE)gid; HPDF_MemCpy ((HPDF_BYTE *)(tmp_map + i), u, 2); } @@ -567,14 +603,14 @@ TextWidth (HPDF_Font font, (HPDF_CIDFontDefAttr)attr->fontdef->attr; dw2 = cid_fontdef_attr->DW2[1]; } else { - dw2 = attr->fontdef->font_bbox.bottom - - attr->fontdef->font_bbox.top; + dw2 = (HPDF_INT)(attr->fontdef->font_bbox.bottom - + attr->fontdef->font_bbox.top); } HPDF_Encoder_SetParseText (encoder, &parse_state, text, len); while (i < len) { - HPDF_ByteType btype = HPDF_CMapEncoder_ByteType (encoder, &parse_state); + HPDF_ByteType btype = (encoder->byte_type_fn)(encoder, &parse_state); HPDF_UINT16 cid; HPDF_UNICODE unicode; HPDF_UINT16 code; @@ -585,7 +621,7 @@ TextWidth (HPDF_Font font, if (btype == HPDF_BYTE_TYPE_LEAD) { code <<= 8; - code += *text; + code = (HPDF_UINT16)(code + *text); } if (btype != HPDF_BYTE_TYPE_TRIAL) { @@ -596,7 +632,7 @@ TextWidth (HPDF_Font font, w = HPDF_CIDFontDef_GetCIDWidth (attr->fontdef, cid); } else { /* unicode-based font */ - unicode = HPDF_CMapEncoder_ToUnicode (encoder, code); + unicode = (encoder->to_unicode_fn)(encoder, code); w = HPDF_TTFontDef_GetCharWidth (attr->fontdef, unicode); } } else { @@ -652,8 +688,8 @@ MeasureText (HPDF_Font font, (HPDF_CIDFontDefAttr)attr->fontdef->attr; dw2 = cid_fontdef_attr->DW2[1]; } else { - dw2 = attr->fontdef->font_bbox.bottom - - attr->fontdef->font_bbox.top; + dw2 = (HPDF_INT)(attr->fontdef->font_bbox.bottom - + attr->fontdef->font_bbox.top); } HPDF_Encoder_SetParseText (encoder, &parse_state, text, len); @@ -668,7 +704,7 @@ MeasureText (HPDF_Font font, if (btype == HPDF_BYTE_TYPE_LEAD) { code <<= 8; - code += b2; + code = (HPDF_UINT16)(code + b2); } if (!wordwrap) { @@ -687,7 +723,8 @@ MeasureText (HPDF_Font font, tmp_len = i + 1; if (real_width) *real_width = w; - } else + } /* else + //Commenting this out fixes problem with HPDF_Text_Rect() splitting the words if (last_btype == HPDF_BYTE_TYPE_TRIAL || (btype == HPDF_BYTE_TYPE_LEAD && last_btype == HPDF_BYTE_TYPE_SINGLE)) { @@ -696,7 +733,7 @@ MeasureText (HPDF_Font font, if (real_width) *real_width = w; } - } + }*/ } if (HPDF_IS_WHITE_SPACE(b)) { @@ -711,19 +748,19 @@ MeasureText (HPDF_Font font, tmp_w = HPDF_CIDFontDef_GetCIDWidth (attr->fontdef, cid); } else { /* unicode-based font */ - unicode = HPDF_CMapEncoder_ToUnicode (encoder, code); + unicode = (encoder->to_unicode_fn)(encoder, code); tmp_w = HPDF_TTFontDef_GetCharWidth (attr->fontdef, unicode); } } else { - tmp_w = -dw2; + tmp_w = (HPDF_UINT16)(-dw2); } if (i > 0) w += char_space; } - w += (HPDF_DOUBLE)tmp_w * font_size / 1000; + w += (HPDF_REAL)((HPDF_DOUBLE)tmp_w * font_size / 1000); /* 2006.08.04 break when it encountered line feed */ if (w > width || b == 0x0A) @@ -743,10 +780,12 @@ MeasureText (HPDF_Font font, } + static char* -UINT16ToHex (char *s, - HPDF_UINT16 val, - char *eptr) +UINT16ToHex (char *s, + HPDF_UINT16 val, + char *eptr, + HPDF_BYTE width) { HPDF_BYTE b[2]; HPDF_UINT16 val2; @@ -763,7 +802,14 @@ UINT16ToHex (char *s, *s++ = '<'; - if (b[0] != 0) { + /* + * In principle a range of <00> - <1F> can now not be + * distinguished from <0000> - <001F>..., this seems something + * that is wrong with CID ranges. For the UCS-2 encoding we need + * to add <0000> - and this cannot be <00> - (or at + * least, that crashes Mac OSX Preview). + */ + if (width == 2) { c = b[0] >> 4; if (c <= 9) c += 0x30; @@ -771,7 +817,7 @@ UINT16ToHex (char *s, c += 0x41 - 10; *s++ = c; - c = b[0] & 0x0f; + c = (char)(b[0] & 0x0f); if (c <= 9) c += 0x30; else @@ -779,14 +825,14 @@ UINT16ToHex (char *s, *s++ = c; } - c = b[1] >> 4; + c = (char)(b[1] >> 4); if (c <= 9) c += 0x30; else c += 0x41 - 10; *s++ = c; - c = b[1] & 0x0f; + c = (char)(b[1] & 0x0f); if (c <= 9) c += 0x30; else @@ -799,6 +845,21 @@ UINT16ToHex (char *s, return s; } +static char* +CidRangeToHex (char *s, + HPDF_UINT16 from, + HPDF_UINT16 to, + char *eptr) +{ + HPDF_BYTE width = (to > 255) ? 2 : 1; + char *pbuf; + + pbuf = UINT16ToHex (s, from, eptr, width); + *pbuf++ = ' '; + pbuf = UINT16ToHex (pbuf, to, eptr, width); + + return pbuf; +} static HPDF_Dict CreateCMap (HPDF_Encoder encoder, @@ -843,17 +904,17 @@ CreateCMap (HPDF_Encoder encoder, ret += HPDF_Stream_WriteStr (cmap->stream, "%%IncludeResource: ProcSet (CIDInit)\r\n"); - pbuf = HPDF_StrCpy (buf, "%%BeginResource: CMap (", eptr); - pbuf = HPDF_StrCpy (pbuf, encoder->name, eptr); + pbuf = (char *)HPDF_StrCpy (buf, "%%BeginResource: CMap (", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, encoder->name, eptr); HPDF_StrCpy (pbuf, ")\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); - pbuf = HPDF_StrCpy (buf, "%%Title: (", eptr); - pbuf = HPDF_StrCpy (pbuf, encoder->name, eptr); + pbuf = (char *)HPDF_StrCpy (buf, "%%Title: (", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, encoder->name, eptr); *pbuf++ = ' '; - pbuf = HPDF_StrCpy (pbuf, attr->registry, eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, attr->registry, eptr); *pbuf++ = ' '; - pbuf = HPDF_StrCpy (pbuf, attr->ordering, eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, attr->ordering, eptr); *pbuf++ = ' '; pbuf = HPDF_IToA (pbuf, attr->suppliment, eptr); HPDF_StrCpy (pbuf, ")\r\n", eptr); @@ -874,24 +935,24 @@ CreateCMap (HPDF_Encoder encoder, ret += HPDF_Stream_WriteStr (cmap->stream, "/CIDSystemInfo 3 dict dup begin\r\n"); - pbuf = HPDF_StrCpy (buf, " /Registry (", eptr); - pbuf = HPDF_StrCpy (pbuf, attr->registry, eptr); + pbuf = (char *)HPDF_StrCpy (buf, " /Registry (", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, attr->registry, eptr); HPDF_StrCpy (pbuf, ") def\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); - pbuf = HPDF_StrCpy (buf, " /Ordering (", eptr); - pbuf = HPDF_StrCpy (pbuf, attr->ordering, eptr); + pbuf = (char *)HPDF_StrCpy (buf, " /Ordering (", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, attr->ordering, eptr); HPDF_StrCpy (pbuf, ") def\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); - pbuf = HPDF_StrCpy (buf, " /Supplement ", eptr); + pbuf = (char *)HPDF_StrCpy (buf, " /Supplement ", eptr); pbuf = HPDF_IToA (pbuf, attr->suppliment, eptr); - pbuf = HPDF_StrCpy (pbuf, " def\r\n", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, " def\r\n", eptr); HPDF_StrCpy (pbuf, "end def\r\n\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); - pbuf = HPDF_StrCpy (buf, "/CMapName /", eptr); - pbuf = HPDF_StrCpy (pbuf, encoder->name, eptr); + pbuf = (char *)HPDF_StrCpy (buf, "/CMapName /", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, encoder->name, eptr); HPDF_StrCpy (pbuf, " def\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); @@ -899,13 +960,13 @@ CreateCMap (HPDF_Encoder encoder, ret += HPDF_Stream_WriteStr (cmap->stream, "/CMapType 1 def\r\n\r\n"); if (attr->uid_offset >= 0) { - pbuf = HPDF_StrCpy (buf, "/UIDOffset ", eptr); + pbuf = (char *)HPDF_StrCpy (buf, "/UIDOffset ", eptr); pbuf = HPDF_IToA (pbuf, attr->uid_offset, eptr); HPDF_StrCpy (pbuf, " def\r\n\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); } - pbuf = HPDF_StrCpy (buf, "/XUID [", eptr); + pbuf = (char *)HPDF_StrCpy (buf, "/XUID [", eptr); pbuf = HPDF_IToA (pbuf, attr->xuid[0], eptr); *pbuf++ = ' '; pbuf = HPDF_IToA (pbuf, attr->xuid[1], eptr); @@ -914,7 +975,7 @@ CreateCMap (HPDF_Encoder encoder, HPDF_StrCpy (pbuf, "] def\r\n\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); - pbuf = HPDF_StrCpy (buf, "/WMode ", eptr); + pbuf = (char *)HPDF_StrCpy (buf, "/WMode ", eptr); pbuf = HPDF_IToA (pbuf, (HPDF_UINT32)attr->writing_mode, eptr); HPDF_StrCpy (pbuf, " def\r\n\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); @@ -928,9 +989,8 @@ CreateCMap (HPDF_Encoder encoder, HPDF_CidRange_Rec *range = HPDF_List_ItemAt (attr->code_space_range, i); - pbuf = UINT16ToHex (buf, range->from, eptr); - *pbuf++ = ' '; - pbuf = UINT16ToHex (pbuf, range->to, eptr); + pbuf = CidRangeToHex(buf, range->from, range->to, eptr); + HPDF_StrCpy (pbuf, "\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); @@ -952,9 +1012,7 @@ CreateCMap (HPDF_Encoder encoder, for (i = 0; i < attr->notdef_range->count; i++) { HPDF_CidRange_Rec *range = HPDF_List_ItemAt (attr->notdef_range, i); - pbuf = UINT16ToHex (buf, range->from, eptr); - *pbuf++ = ' '; - pbuf = UINT16ToHex (pbuf, range->to, eptr); + pbuf = CidRangeToHex(buf, range->from, range->to, eptr); *pbuf++ = ' '; pbuf = HPDF_IToA (pbuf, range->cid, eptr); HPDF_StrCpy (pbuf, "\r\n", eptr); @@ -983,9 +1041,7 @@ CreateCMap (HPDF_Encoder encoder, for (i = 0; i < attr->cmap_range->count; i++) { HPDF_CidRange_Rec *range = HPDF_List_ItemAt (attr->cmap_range, i); - pbuf = UINT16ToHex (buf, range->from, eptr); - *pbuf++ = ' '; - pbuf = UINT16ToHex (pbuf, range->to, eptr); + pbuf = CidRangeToHex(buf, range->from, range->to, eptr); *pbuf++ = ' '; pbuf = HPDF_IToA (pbuf, range->cid, eptr); HPDF_StrCpy (pbuf, "\r\n", eptr); @@ -994,7 +1050,7 @@ CreateCMap (HPDF_Encoder encoder, if ((i + 1) %100 == 0) { phase--; - pbuf = HPDF_StrCpy (buf, "endcidrange\r\n\r\n", eptr); + pbuf = (char *)HPDF_StrCpy (buf, "endcidrange\r\n\r\n", eptr); if (phase > 0) pbuf = HPDF_IToA (pbuf, 100, eptr); @@ -1011,14 +1067,14 @@ CreateCMap (HPDF_Encoder encoder, } if (odd > 0) - pbuf = HPDF_StrCpy (buf, "endcidrange\r\n", eptr); + pbuf = (char *)HPDF_StrCpy (buf, "endcidrange\r\n", eptr); - pbuf = HPDF_StrCpy (pbuf, "endcmap\r\n", eptr); - pbuf = HPDF_StrCpy (pbuf, "CMapName currentdict /CMap " + pbuf = (char *)HPDF_StrCpy (pbuf, "endcmap\r\n", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, "CMapName currentdict /CMap " "defineresource pop\r\n", eptr); - pbuf = HPDF_StrCpy (pbuf, "end\r\n", eptr); - pbuf = HPDF_StrCpy (pbuf, "end\r\n\r\n", eptr); - pbuf = HPDF_StrCpy (pbuf, "%%EndResource\r\n", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, "end\r\n", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, "end\r\n\r\n", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, "%%EndResource\r\n", eptr); HPDF_StrCpy (pbuf, "%%EOF\r\n", eptr); ret += HPDF_Stream_WriteStr (cmap->stream, buf); diff --git a/PDF/src/hpdf_font_tt.c b/PDF/src/hpdf_font_tt.c index 21b936783..8b5512932 100644 --- a/PDF/src/hpdf_font_tt.c +++ b/PDF/src/hpdf_font_tt.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_font_tt.c + * << Haru Free PDF Library >> -- hpdf_font_tt.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -177,6 +180,7 @@ CreateDescriptor (HPDF_Font font) ret += HPDF_Dict_AddName (descriptor, "Type", "FontDescriptor"); ret += HPDF_Dict_AddNumber (descriptor, "Ascent", def->ascent); ret += HPDF_Dict_AddNumber (descriptor, "Descent", def->descent); + ret += HPDF_Dict_AddNumber (descriptor, "CapHeight", def->cap_height); ret += HPDF_Dict_AddNumber (descriptor, "Flags", def->flags); array = HPDF_Box_Array_New (font->mmgr, def->font_bbox); @@ -244,7 +248,7 @@ CharWidth (HPDF_Font font, } -HPDF_TextWidth +static HPDF_TextWidth TextWidth (HPDF_Font font, const HPDF_BYTE *text, HPDF_UINT len) @@ -280,7 +284,7 @@ TextWidth (HPDF_Font font, } -HPDF_UINT +static HPDF_UINT MeasureText (HPDF_Font font, const HPDF_BYTE *text, HPDF_UINT len, @@ -304,14 +308,14 @@ MeasureText (HPDF_Font font, tmp_len = i + 1; if (real_width) - *real_width = w; + *real_width = (HPDF_REAL)w; w += word_space; } else if (!wordwrap) { tmp_len = i; if (real_width) - *real_width = w; + *real_width = (HPDF_REAL)w; } w += (HPDF_DOUBLE)CharWidth (font, b) * font_size / 1000; @@ -326,7 +330,7 @@ MeasureText (HPDF_Font font, /* all of text can be put in the specified width */ if (real_width) - *real_width = w; + *real_width = (HPDF_REAL)w; return len; } @@ -402,5 +406,3 @@ OnFree (HPDF_Dict obj) HPDF_FreeMem (obj->mmgr, attr); } } - - diff --git a/PDF/src/hpdf_font_type1.c b/PDF/src/hpdf_font_type1.c index c4c3a24b9..d1476c4c8 100644 --- a/PDF/src/hpdf_font_type1.c +++ b/PDF/src/hpdf_font_type1.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_font_type1.c + * << Haru Free PDF Library >> -- hpdf_font_type1.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -330,13 +333,13 @@ Type1Font_OnWrite (HPDF_Dict obj, if (!fontdef_attr->is_base14font || encoder_attr->has_differences) { char *pbuf; - pbuf = HPDF_StrCpy (buf, "/FirstChar ", eptr); + 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 = HPDF_StrCpy (buf, "/LastChar ", eptr); + 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) diff --git a/PDF/src/hpdf_fontdef.c b/PDF/src/hpdf_fontdef.c index 6570e351f..13d4a0c2a 100644 --- a/PDF/src/hpdf_fontdef.c +++ b/PDF/src/hpdf_fontdef.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef.c + * << Haru Free PDF Library >> -- hpdf_fontdef.c * - * Copyright (c) 1999-2004 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_fontdef_base14.c b/PDF/src/hpdf_fontdef_base14.c index 561e45a5c..67c230c80 100644 --- a/PDF/src/hpdf_fontdef_base14.c +++ b/PDF/src/hpdf_fontdef_base14.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.1 >> -- HPDF_FontDef_base14.c + * << Haru Free PDF Library >> -- hpdf_fontdef_base14.c * - * Copyright (c) 1999-2004 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -10,7 +13,6 @@ * in supporting documentation. * It is provided "as is" without express or implied warranty. * - * 2006.07.25 modified. */ #include "hpdf_conf.h" diff --git a/PDF/src/hpdf_fontdef_cid.c b/PDF/src/hpdf_fontdef_cid.c index a16c99ede..6745188a2 100644 --- a/PDF/src/hpdf_fontdef_cid.c +++ b/PDF/src/hpdf_fontdef_cid.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_cid.c + * << Haru Free PDF Library >> -- hpdf_fontdef_cid.c * - * Copyright (c) 1999-2004 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_fontdef_cns.c b/PDF/src/hpdf_fontdef_cns.c index 793bbce7c..af9ff3cfb 100644 --- a/PDF/src/hpdf_fontdef_cns.c +++ b/PDF/src/hpdf_fontdef_cns.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_cns.c + * << Haru Free PDF Library >> -- hpdf_fontdef_cns.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_fontdef_cnt.c b/PDF/src/hpdf_fontdef_cnt.c index e8a7c9e5e..717c22514 100644 --- a/PDF/src/hpdf_fontdef_cnt.c +++ b/PDF/src/hpdf_fontdef_cnt.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_cnt.c + * << Haru Free PDF Library >> -- hpdf_fontdef_cnt.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_fontdef_jp.c b/PDF/src/hpdf_fontdef_jp.c index db8459258..7e48af8cf 100644 --- a/PDF/src/hpdf_fontdef_jp.c +++ b/PDF/src/hpdf_fontdef_jp.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_jp.c + * << Haru Free PDF Library >> -- hpdf_fontdef_jp.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -777,7 +780,7 @@ static const HPDF_CID_Width MS_PGothic_W_ARRAY[] = { }; -static const HPDF_CID_Width MS_Mincyo_W_ARRAY[] = { +static const HPDF_CID_Width MS_Mincho_W_ARRAY[] = { {1, 500}, {2, 500}, {3, 500}, @@ -1036,7 +1039,7 @@ static const HPDF_CID_Width MS_Mincyo_W_ARRAY[] = { -static const HPDF_CID_Width MS_PMincyo_W_ARRAY[] = { +static const HPDF_CID_Width MS_PMincho_W_ARRAY[] = { {1, 304}, {2, 304}, {3, 460}, @@ -1542,7 +1545,7 @@ static const HPDF_CID_Width MS_PMincyo_W_ARRAY[] = { /*---------------------------------------------------------------------------*/ -/*----- Mincyo Font ---------------------------------------------------------*/ +/*----- Mincho Font ---------------------------------------------------------*/ static HPDF_STATUS @@ -1668,11 +1671,11 @@ MS_PGothic_BoldItalic_Init (HPDF_FontDef fontdef) static HPDF_STATUS -MS_Mincyo_Init (HPDF_FontDef fontdef) +MS_Mincho_Init (HPDF_FontDef fontdef) { HPDF_STATUS ret; - HPDF_PTRACE ((" HPDF_FontDef_MS_Mincyo_Init\n")); + HPDF_PTRACE ((" HPDF_FontDef_MS_Mincho_Init\n")); fontdef->ascent = 859; fontdef->descent = -140; @@ -1695,9 +1698,9 @@ MS_Mincyo_Init (HPDF_FontDef fontdef) static HPDF_STATUS -MS_Mincyo_Bold_Init (HPDF_FontDef fontdef) +MS_Mincho_Bold_Init (HPDF_FontDef fontdef) { - HPDF_STATUS ret = MS_Mincyo_Init (fontdef); + HPDF_STATUS ret = MS_Mincho_Init (fontdef); if (ret != HPDF_OK) return ret; @@ -1707,9 +1710,9 @@ MS_Mincyo_Bold_Init (HPDF_FontDef fontdef) static HPDF_STATUS -MS_Mincyo_Italic_Init (HPDF_FontDef fontdef) +MS_Mincho_Italic_Init (HPDF_FontDef fontdef) { - HPDF_STATUS ret = MS_Mincyo_Init (fontdef); + HPDF_STATUS ret = MS_Mincho_Init (fontdef); if (ret != HPDF_OK) return ret; @@ -1718,9 +1721,9 @@ MS_Mincyo_Italic_Init (HPDF_FontDef fontdef) } static HPDF_STATUS -MS_Mincyo_BoldItalic_Init (HPDF_FontDef fontdef) +MS_Mincho_BoldItalic_Init (HPDF_FontDef fontdef) { - HPDF_STATUS ret = MS_Mincyo_Init (fontdef); + HPDF_STATUS ret = MS_Mincho_Init (fontdef); if (ret != HPDF_OK) return ret; @@ -1730,11 +1733,11 @@ MS_Mincyo_BoldItalic_Init (HPDF_FontDef fontdef) static HPDF_STATUS -MS_PMincyo_Init (HPDF_FontDef fontdef) +MS_PMincho_Init (HPDF_FontDef fontdef) { HPDF_STATUS ret; - HPDF_PTRACE ((" HPDF_FontDef_MS_PMincyo_Init\n")); + HPDF_PTRACE ((" HPDF_FontDef_MS_PMincho_Init\n")); fontdef->ascent = 859; fontdef->descent = -140; @@ -1756,9 +1759,9 @@ MS_PMincyo_Init (HPDF_FontDef fontdef) static HPDF_STATUS -MS_PMincyo_Bold_Init (HPDF_FontDef fontdef) +MS_PMincho_Bold_Init (HPDF_FontDef fontdef) { - HPDF_STATUS ret = MS_PMincyo_Init (fontdef); + HPDF_STATUS ret = MS_PMincho_Init (fontdef); if (ret != HPDF_OK) return ret; @@ -1768,9 +1771,9 @@ MS_PMincyo_Bold_Init (HPDF_FontDef fontdef) static HPDF_STATUS -MS_PMincyo_Italic_Init (HPDF_FontDef fontdef) +MS_PMincho_Italic_Init (HPDF_FontDef fontdef) { - HPDF_STATUS ret = MS_PMincyo_Init (fontdef); + HPDF_STATUS ret = MS_PMincho_Init (fontdef); if (ret != HPDF_OK) return ret; @@ -1779,9 +1782,9 @@ MS_PMincyo_Italic_Init (HPDF_FontDef fontdef) } static HPDF_STATUS -MS_PMincyo_BoldItalic_Init (HPDF_FontDef fontdef) +MS_PMincho_BoldItalic_Init (HPDF_FontDef fontdef) { - HPDF_STATUS ret = MS_PMincyo_Init (fontdef); + HPDF_STATUS ret = MS_PMincho_Init (fontdef); if (ret != HPDF_OK) return ret; @@ -1849,52 +1852,52 @@ HPDF_UseJPFonts (HPDF_Doc pdf) if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; - /* MS-Mincyo */ - fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincyo", - MS_Mincyo_Init); + /* MS-Mincho */ + fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho", + MS_Mincho_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; - fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincyo,Bold", - MS_Mincyo_Bold_Init); + fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho,Bold", + MS_Mincho_Bold_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; - fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincyo,Italic", - MS_Mincyo_Italic_Init); + fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho,Italic", + MS_Mincho_Italic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; - fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincyo,BoldItalic", - MS_Mincyo_BoldItalic_Init); + fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho,BoldItalic", + MS_Mincho_BoldItalic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; - /* MS-PMincyo */ - fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincyo", - MS_PMincyo_Init); + /* MS-PMincho */ + fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho", + MS_PMincho_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; - fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincyo,Bold", - MS_PMincyo_Bold_Init); + fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho,Bold", + MS_PMincho_Bold_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; - fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincyo,Italic", - MS_PMincyo_Italic_Init); + fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho,Italic", + MS_PMincho_Italic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; - fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincyo,BoldItalic", - MS_PMincyo_BoldItalic_Init); + fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho,BoldItalic", + MS_PMincho_BoldItalic_Init); if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK) return ret; diff --git a/PDF/src/hpdf_fontdef_kr.c b/PDF/src/hpdf_fontdef_kr.c index ba60de386..3651f9da1 100644 --- a/PDF/src/hpdf_fontdef_kr.c +++ b/PDF/src/hpdf_fontdef_kr.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_kr.c + * << Haru Free PDF Library >> -- hpdf_fontdef_kr.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_fontdef_tt.c b/PDF/src/hpdf_fontdef_tt.c index 342cf6e0b..f985d3549 100644 --- a/PDF/src/hpdf_fontdef_tt.c +++ b/PDF/src/hpdf_fontdef_tt.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.4 >> -- hpdf_fontdef_tt.c + * << Haru Free PDF Library >> -- hpdf_fontdef_tt.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -22,7 +25,7 @@ #define HPDF_REQUIRED_TAGS_COUNT 13 -static const char *REQUIRED_TAGS[HPDF_REQUIRED_TAGS_COUNT] = { +static const char * const REQUIRED_TAGS[HPDF_REQUIRED_TAGS_COUNT] = { "OS/2", "cmap", "cvt ", @@ -457,11 +460,11 @@ LoadFontData (HPDF_FontDef fontdef, attr->glyph_tbl.base_offset = tbl->offset; fontdef->cap_height = - HPDF_TTFontDef_GetCharBBox (fontdef, (HPDF_UINT16)'H').top; + (HPDF_UINT16)HPDF_TTFontDef_GetCharBBox (fontdef, (HPDF_UINT16)'H').top; fontdef->x_height = - HPDF_TTFontDef_GetCharBBox (fontdef, (HPDF_UINT16)'x').top; - fontdef->missing_width = (HPDF_UINT32)attr->h_metric[0].advance_width * 1000 / - attr->header.units_per_em; + (HPDF_UINT16)HPDF_TTFontDef_GetCharBBox (fontdef, (HPDF_UINT16)'x').top; + fontdef->missing_width = (HPDF_INT16)((HPDF_UINT32)attr->h_metric[0].advance_width * 1000 / + attr->header.units_per_em); HPDF_PTRACE ((" fontdef->cap_height=%d\n", fontdef->cap_height)); HPDF_PTRACE ((" fontdef->x_height=%d\n", fontdef->x_height)); @@ -501,7 +504,7 @@ LoadFontData2 (HPDF_FontDef fontdef, if ((ret = HPDF_Stream_Read (stream, tag, &size)) != HPDF_OK) return ret; - if (HPDF_MemCmp (tag, "ttcf", 4) != 0) + if (HPDF_MemCmp (tag, (HPDF_BYTE *)"ttcf", 4) != 0) return HPDF_SetError (fontdef->error, HPDF_INVALID_TTC_FILE, 0); if ((ret = HPDF_Stream_Seek (stream, 8, HPDF_SEEK_SET)) != HPDF_OK) @@ -557,16 +560,16 @@ HPDF_TTFontDef_GetCharBBox (HPDF_FontDef fontdef, return bbox; ret += GetINT16 (attr->stream, &i); - bbox.left = (HPDF_INT32)i * 1000 / attr->header.units_per_em; + bbox.left = (HPDF_REAL)((HPDF_INT32)i * 1000 / attr->header.units_per_em); ret += GetINT16 (attr->stream, &i); - bbox.bottom = (HPDF_INT32)i * 1000 / attr->header.units_per_em; + bbox.bottom = (HPDF_REAL)((HPDF_INT32)i * 1000 / attr->header.units_per_em); ret += GetINT16 (attr->stream, &i); - bbox.right = (HPDF_INT32)i * 1000 / attr->header.units_per_em; + bbox.right = (HPDF_REAL)((HPDF_INT32)i * 1000 / attr->header.units_per_em); ret += GetINT16 (attr->stream, &i); - bbox.top = (HPDF_INT32)i * 1000 / attr->header.units_per_em; + bbox.top = (HPDF_REAL)((HPDF_INT32)i * 1000 / attr->header.units_per_em); if (ret != HPDF_OK) return HPDF_ToBox(0, 0, 0, 0); @@ -718,7 +721,7 @@ LoadTTFTable (HPDF_FontDef fontdef) for (i = 0; i < attr->offset_tbl.num_tables; i++) { HPDF_UINT siz = 4; - ret += HPDF_Stream_Read (attr->stream, tbl->tag, &siz); + ret += HPDF_Stream_Read (attr->stream, (HPDF_BYTE *)tbl->tag, &siz); ret += GetUINT32 (attr->stream, &tbl->check_sum); ret += GetUINT32 (attr->stream, &tbl->offset); ret += GetUINT32 (attr->stream, &tbl->length); @@ -782,14 +785,14 @@ ParseHead (HPDF_FontDef fontdef) if (ret != HPDF_OK) return HPDF_Error_GetCode (fontdef->error); - fontdef->font_bbox. left = (HPDF_INT32)attr->header.x_min * 1000 / - attr->header.units_per_em; - fontdef->font_bbox. bottom = (HPDF_INT32)attr->header.y_min * 1000 / - attr->header.units_per_em; - fontdef->font_bbox. right = (HPDF_INT32)attr->header.x_max * 1000 / - attr->header.units_per_em; - fontdef->font_bbox. top = (HPDF_INT32)attr->header.y_max * 1000 / - attr->header.units_per_em; + fontdef->font_bbox. left = (HPDF_REAL)((HPDF_INT32)attr->header.x_min * 1000 / + attr->header.units_per_em); + fontdef->font_bbox. bottom = (HPDF_REAL)((HPDF_INT32)attr->header.y_min * 1000 / + attr->header.units_per_em); + fontdef->font_bbox. right = (HPDF_REAL)((HPDF_INT32)attr->header.x_max * 1000 / + attr->header.units_per_em); + fontdef->font_bbox. top = (HPDF_REAL)((HPDF_INT32)attr->header.y_max * 1000 / + attr->header.units_per_em); return HPDF_OK; } @@ -837,11 +840,11 @@ ParseHhea (HPDF_FontDef fontdef) return ret; ret += GetINT16 (attr->stream, &fontdef->ascent); - fontdef->ascent = (HPDF_INT32)fontdef->ascent * 1000 / - attr->header.units_per_em; + fontdef->ascent = (HPDF_INT16)((HPDF_INT32)fontdef->ascent * 1000 / + attr->header.units_per_em); ret += GetINT16 (attr->stream, &fontdef->descent); - fontdef->descent = (HPDF_INT32)fontdef->descent * 1000 / - attr->header.units_per_em; + fontdef->descent = (HPDF_INT16)((HPDF_INT32)fontdef->descent * 1000 / + attr->header.units_per_em); if (ret != HPDF_OK) return HPDF_Error_GetCode (fontdef->error); @@ -1049,7 +1052,7 @@ ParseCMAP_format4 (HPDF_FontDef fontdef, return HPDF_Error_GetCode (fontdef->error); pend_count = attr->cmap.end_count; - for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++) + for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++) if ((ret = GetUINT16 (attr->stream, pend_count++)) != HPDF_OK) return ret; @@ -1063,7 +1066,7 @@ ParseCMAP_format4 (HPDF_FontDef fontdef, return HPDF_Error_GetCode (fontdef->error); pstart_count = attr->cmap.start_count; - for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++) + for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++) if ((ret = GetUINT16 (attr->stream, pstart_count++)) != HPDF_OK) return ret; @@ -1074,7 +1077,7 @@ ParseCMAP_format4 (HPDF_FontDef fontdef, return HPDF_Error_GetCode (fontdef->error); pid_delta = attr->cmap.id_delta; - for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++) + for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++) if ((ret = GetINT16 (attr->stream, pid_delta++)) != HPDF_OK) return ret; @@ -1085,7 +1088,7 @@ ParseCMAP_format4 (HPDF_FontDef fontdef, return HPDF_Error_GetCode (fontdef->error); pid_range_offset = attr->cmap.id_range_offset; - for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++) + for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++) if ((ret = GetUINT16 (attr->stream, pid_range_offset++)) != HPDF_OK) return ret; @@ -1109,9 +1112,9 @@ ParseCMAP_format4 (HPDF_FontDef fontdef, } else attr->cmap.glyph_id_array = NULL; -#ifdef HPDF_DEBUG +#ifdef LIBHPDF_DEBUG /* print all elements of cmap table */ - for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++) { + for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++) { HPDF_PTRACE((" ParseCMAP_format4[%d] start_count=0x%04X, " "end_count=0x%04X, id_delta=%d, id_range_offset=%u\n", i, attr->cmap.start_count[i], attr->cmap.end_count[i], @@ -1163,7 +1166,7 @@ HPDF_TTFontDef_GetGlyphid (HPDF_FontDef fontdef, " ret=%u\n", i, unicode, unicode + attr->cmap.id_delta[i])); - return unicode + attr->cmap.id_delta[i]; + return (HPDF_UINT16)(unicode + attr->cmap.id_delta[i]); } else { HPDF_UINT idx = attr->cmap.id_range_offset[i] / 2 + (unicode - attr->cmap.start_count[i]) - (seg_count - i); @@ -1173,8 +1176,8 @@ HPDF_TTFontDef_GetGlyphid (HPDF_FontDef fontdef, i, idx, (HPDF_UINT)attr->cmap.glyph_id_array_count)); return 0; } else { - HPDF_UINT16 gid = attr->cmap.glyph_id_array[idx] + - attr->cmap.id_delta[i]; + HPDF_UINT16 gid = (HPDF_UINT16)(attr->cmap.glyph_id_array[idx] + + attr->cmap.id_delta[i]); HPDF_PTRACE((" HPDF_TTFontDef_GetGlyphid idx=%u unicode=0x%04X " "id=%u\n", idx, unicode, gid)); return gid; @@ -1209,8 +1212,8 @@ HPDF_TTFontDef_GetCharWidth (HPDF_FontDef fontdef, CheckCompositGryph (fontdef, gid); } - advance_width = (HPDF_UINT)hmetrics.advance_width * 1000 / - attr->header.units_per_em; + advance_width = (HPDF_UINT16)((HPDF_UINT)hmetrics.advance_width * 1000 / + attr->header.units_per_em); return (HPDF_INT16)advance_width; } @@ -1222,7 +1225,7 @@ CheckCompositGryph (HPDF_FontDef fontdef, { HPDF_TTFontDefAttr attr = (HPDF_TTFontDefAttr)fontdef->attr; HPDF_UINT offset = attr->glyph_tbl.offsets[gid]; - // HPDF_UINT len = attr->glyph_tbl.offsets[gid + 1] - offset; + /* HPDF_UINT len = attr->glyph_tbl.offsets[gid + 1] - offset; */ HPDF_STATUS ret; HPDF_PTRACE ((" CheckCompositGryph\n")); @@ -1320,8 +1323,8 @@ HPDF_TTFontDef_GetGidWidth (HPDF_FontDef fontdef, hmetrics = attr->h_metric[gid]; - advance_width = (HPDF_UINT)hmetrics.advance_width * 1000 / - attr->header.units_per_em; + advance_width = (HPDF_UINT16)((HPDF_UINT)hmetrics.advance_width * 1000 / + attr->header.units_per_em); HPDF_PTRACE((" HPDF_TTFontDef_GetGidWidth gid=%u, width=%u\n", gid, advance_width)); @@ -1453,7 +1456,7 @@ ParseLoca (HPDF_FontDef fontdef) } -#ifdef HPDF_DEBUG +#ifdef LIBHPDF_DEBUG poffset = attr->glyph_tbl.offsets; for (i = 0; i <= attr->num_glyphs; i++) { HPDF_PTRACE((" ParseLOCA offset[%u]=%u\n", i, (HPDF_UINT)*poffset)); @@ -1608,7 +1611,7 @@ ParseName (HPDF_FontDef fontdef) HPDF_SEEK_SET)) != HPDF_OK) return ret; - if ((ret = HPDF_Stream_Read (attr->stream, attr->base_font, &len_id1)) + if ((ret = HPDF_Stream_Read (attr->stream, (HPDF_BYTE *)attr->base_font, &len_id1)) != HPDF_OK) return ret; } else { @@ -1624,7 +1627,7 @@ ParseName (HPDF_FontDef fontdef) != HPDF_OK) return ret; - if ((ret = HPDF_Stream_Read (attr->stream, tmp, &len_id2)) != HPDF_OK) + if ((ret = HPDF_Stream_Read (attr->stream, (HPDF_BYTE *)tmp, &len_id2)) != HPDF_OK) return ret; } else { if ((ret = LoadUnicodeName (attr->stream, offset_id2u, len_id2u, @@ -1639,7 +1642,7 @@ ParseName (HPDF_FontDef fontdef) * if subfamily name is "Bold" or "Italic" or "BoldItalic", set flags * attribute. */ - if (HPDF_MemCmp (tmp, "Regular", 7) != 0) { + if (HPDF_MemCmp ((HPDF_BYTE *)tmp, (HPDF_BYTE *)"Regular", 7) != 0) { char *dst = attr->base_font + len_id1; char *src = tmp; HPDF_UINT j; @@ -1662,8 +1665,7 @@ ParseName (HPDF_FontDef fontdef) fontdef->flags |= HPDF_FONT_ITALIC; } - HPDF_MemCpy (fontdef->base_font, attr->base_font, - HPDF_LIMIT_MAX_NAME_LEN + 1); + HPDF_MemCpy ((HPDF_BYTE *)fontdef->base_font, (HPDF_BYTE *)attr->base_font, HPDF_LIMIT_MAX_NAME_LEN + 1); HPDF_PTRACE((" ParseName() base_font=%s\n", attr->base_font)); @@ -1676,6 +1678,7 @@ ParseOS2 (HPDF_FontDef fontdef) HPDF_TTFontDefAttr attr = (HPDF_TTFontDefAttr)fontdef->attr; HPDF_TTFTable *tbl = FindTable (fontdef, "OS/2"); HPDF_STATUS ret; + HPDF_UINT16 version; HPDF_UINT len; HPDF_PTRACE ((" ParseOS2\n")); @@ -1683,11 +1686,19 @@ ParseOS2 (HPDF_FontDef fontdef) if (!tbl) return HPDF_SetError (fontdef->error, HPDF_TTF_MISSING_TABLE, 0); + /* get the number version. */ + ret = HPDF_Stream_Seek (attr->stream, tbl->offset, HPDF_SEEK_SET); + if (ret != HPDF_OK) + return ret; + + if ((ret = GetUINT16 (attr->stream, &version)) != HPDF_OK) + return ret; + + /* check whether the font is allowed to be embedded. */ ret = HPDF_Stream_Seek (attr->stream, tbl->offset + 8, HPDF_SEEK_SET); if (ret != HPDF_OK) return ret; - /* check whether the font is allowed to be embedded. */ if ((ret = GetUINT16 (attr->stream, &attr->fs_type)) != HPDF_OK) return ret; @@ -1695,32 +1706,59 @@ ParseOS2 (HPDF_FontDef fontdef) return HPDF_SetError (fontdef->error, HPDF_TTF_CANNOT_EMBEDDING_FONT, 0); - if ((ret = HPDF_Stream_Seek (attr->stream, tbl->offset + 20, HPDF_SEEK_SET)) + /* get fields sfamilyclass and panose. */ + if ((ret = HPDF_Stream_Seek (attr->stream, tbl->offset + 30, HPDF_SEEK_SET)) != HPDF_OK) return ret; - len = 12; + len = 2; + if ((ret = HPDF_Stream_Read (attr->stream, attr->sfamilyclass, &len)) != HPDF_OK) + return ret; + + len = 10; if ((ret = HPDF_Stream_Read (attr->stream, attr->panose, &len)) != HPDF_OK) return ret; - HPDF_PTRACE((" ParseOS2 PANOSE=%u-%u " - "%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", + HPDF_PTRACE((" ParseOS2 sFamilyClass=%d-%d " + "Panose=%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n", + attr->sfamilyclass[0], attr->sfamilyclass[1], attr->panose[0], attr->panose[1], attr->panose[2], attr->panose[3], attr->panose[4], attr->panose[5], attr->panose[6], attr->panose[7], - attr->panose[8], attr->panose[9], attr->panose[10], attr->panose[11])); + attr->panose[8], attr->panose[9])); - if (attr->panose[0] == 1 || attr->panose[0] == 4) + /* Class ID = 1 Oldstyle Serifs + Class ID = 2 Transitional Serifs + Class ID = 3 Modern Serifs + Class ID = 4 Clarendon Serifs + Class ID = 5 Slab Serifs + Class ID = 6 (reserved for future use) + Class ID = 7 Freeform Serifs + Class ID = 8 Sans Serif + Class ID = 9 Ornamentals + Class ID = 10 Scripts + Class ID = 11 (reserved for future use) + Class ID = 12 Symbolic */ + if ((attr->sfamilyclass[0] > 0 && attr->sfamilyclass[0] < 6) + || (attr->sfamilyclass[0] == 7)) fontdef->flags = fontdef->flags | HPDF_FONT_SERIF; - /* get ulCodePageRange1 */ - if ((ret = HPDF_Stream_Seek (attr->stream, 78, HPDF_SEEK_CUR)) != HPDF_OK) - return ret; + if (attr->sfamilyclass[0] == 10) + fontdef->flags = fontdef->flags | HPDF_FONT_SCRIPT; - if ((ret = GetUINT32 (attr->stream, &attr->code_page_range1)) != HPDF_OK) - return ret; + if (attr->sfamilyclass[0] == 12) + fontdef->flags = fontdef->flags | HPDF_FONT_SYMBOLIC; - if ((ret = GetUINT32 (attr->stream, &attr->code_page_range2)) != HPDF_OK) - return ret; + /* get fields ulCodePageRange1 and ulCodePageRange2 */ + if(version > 0) { + if ((ret = HPDF_Stream_Seek (attr->stream, 36, HPDF_SEEK_CUR)) != HPDF_OK) + return ret; + + if ((ret = GetUINT32 (attr->stream, &attr->code_page_range1)) != HPDF_OK) + return ret; + + if ((ret = GetUINT32 (attr->stream, &attr->code_page_range2)) != HPDF_OK) + return ret; + } HPDF_PTRACE((" ParseOS2 CodePageRange1=%08X CodePageRange2=%08X\n", (HPDF_UINT)attr->code_page_range1, @@ -1843,11 +1881,11 @@ RecreateName (HPDF_FontDef fontdef, /* add suffix to font-name. */ if (name_rec->name_id == 1 || name_rec->name_id == 4) { if (name_rec->platform_id == 0 || name_rec->platform_id == 3) { - ret += HPDF_Stream_Write (tmp_stream, attr->tag_name2, + ret += HPDF_Stream_Write (tmp_stream, (HPDF_BYTE *)attr->tag_name2, sizeof(attr->tag_name2)); name_len += sizeof(attr->tag_name2); } else { - ret += HPDF_Stream_Write (tmp_stream, attr->tag_name, + ret += HPDF_Stream_Write (tmp_stream, (HPDF_BYTE *)attr->tag_name, sizeof(attr->tag_name)); name_len += sizeof(attr->tag_name); } @@ -1953,10 +1991,13 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef, HPDF_Stream tmp_stream; HPDF_UINT32 *new_offsets; HPDF_UINT i; - HPDF_UINT32 check_sum_ptr; + HPDF_UINT32 check_sum_ptr = 0; HPDF_STATUS ret; HPDF_UINT32 offset_base; HPDF_UINT32 tmp_check_sum = 0xB1B0AFBA; + HPDF_TTFTable emptyTable; + emptyTable.length = 0; + emptyTable.offset = 0; HPDF_PTRACE ((" SaveFontData\n")); @@ -1989,6 +2030,12 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef, HPDF_UINT32 *poffset; HPDF_UINT32 value; + if (!tbl) { + tbl = &emptyTable; + HPDF_MemCpy((HPDF_BYTE *)tbl->tag, + (const HPDF_BYTE *)REQUIRED_TAGS[i], 4); + } + if (!tbl) { ret = HPDF_SetError (fontdef->error, HPDF_TTF_MISSING_TABLE, i); goto Exit; @@ -2001,11 +2048,11 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef, length = tbl->length; new_offset = tmp_stream->size; - if (HPDF_MemCmp (tbl->tag, "head", 4) == 0) { + if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)"head", 4) == 0) { ret = WriteHeader (fontdef, tmp_stream, &check_sum_ptr); - } else if (HPDF_MemCmp (tbl->tag, "glyf", 4) == 0) { + } else if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)"glyf", 4) == 0) { ret = RecreateGLYF (fontdef, new_offsets, tmp_stream); - } else if (HPDF_MemCmp (tbl->tag, "loca", 4) == 0) { + } else if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)"loca", 4) == 0) { HPDF_UINT j; HPDF_MemSet (&value, 0, 4); @@ -2022,7 +2069,7 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef, poffset++; } } - } else if (HPDF_MemCmp (tbl->tag, "name", 4) == 0) { + } else if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)"name", 4) == 0) { ret = RecreateName (fontdef, tmp_stream); } else { HPDF_UINT size = 4; @@ -2081,7 +2128,7 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef, REQUIRED_TAGS[i], (HPDF_UINT)tbl.check_sum, (HPDF_UINT)tbl.offset)); - ret += HPDF_Stream_Write (stream, REQUIRED_TAGS[i], 4); + ret += HPDF_Stream_Write (stream, (HPDF_BYTE *)REQUIRED_TAGS[i], 4); ret += WriteUINT32 (stream, tbl.check_sum); tbl.offset += offset_base; ret += WriteUINT32 (stream, tbl.offset); @@ -2155,7 +2202,7 @@ HPDF_TTFontDef_SetTagName (HPDF_FontDef fontdef, if (HPDF_StrLen (tag, HPDF_LIMIT_MAX_NAME_LEN) != HPDF_TTF_FONT_TAG_LEN) return; - HPDF_MemCpy (attr->tag_name, tag, HPDF_TTF_FONT_TAG_LEN); + HPDF_MemCpy ((HPDF_BYTE *)attr->tag_name, (HPDF_BYTE *)tag, HPDF_TTF_FONT_TAG_LEN); attr->tag_name[HPDF_TTF_FONT_TAG_LEN] = '+'; for (i = 0; i < HPDF_TTF_FONT_TAG_LEN + 1; i++) { @@ -2164,11 +2211,10 @@ HPDF_TTFontDef_SetTagName (HPDF_FontDef fontdef, } HPDF_MemSet (buf, 0, HPDF_LIMIT_MAX_NAME_LEN + 1); - HPDF_MemCpy (buf, attr->tag_name, HPDF_TTF_FONT_TAG_LEN + 1); - HPDF_MemCpy (buf + HPDF_TTF_FONT_TAG_LEN + 1, fontdef->base_font, - HPDF_LIMIT_MAX_NAME_LEN - HPDF_TTF_FONT_TAG_LEN - 1); + HPDF_MemCpy ((HPDF_BYTE *)buf, (HPDF_BYTE *)attr->tag_name, HPDF_TTF_FONT_TAG_LEN + 1); + HPDF_MemCpy ((HPDF_BYTE *)buf + HPDF_TTF_FONT_TAG_LEN + 1, (HPDF_BYTE *)fontdef->base_font, HPDF_LIMIT_MAX_NAME_LEN - HPDF_TTF_FONT_TAG_LEN - 1); - HPDF_MemCpy (attr->base_font, buf, HPDF_LIMIT_MAX_NAME_LEN + 1); + HPDF_MemCpy ((HPDF_BYTE *)attr->base_font, (HPDF_BYTE *)buf, HPDF_LIMIT_MAX_NAME_LEN + 1); } /* @@ -2188,7 +2234,7 @@ FindTable (HPDF_FontDef fontdef, HPDF_UINT i; for (i = 0; i < attr->offset_tbl.num_tables; i++, tbl++) { - if (HPDF_MemCmp (tbl->tag, tag, 4) == 0) { + if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)tag, 4) == 0) { HPDF_PTRACE((" FindTable find table[%c%c%c%c]\n", tbl->tag[0], tbl->tag[1], tbl->tag[2], tbl->tag[3])); return tbl; @@ -2227,4 +2273,3 @@ INT16Swap (HPDF_INT16 *value) HPDF_MemCpy (b, (HPDF_BYTE *)value, 2); *value = (HPDF_INT16)((HPDF_INT16)b[0] << 8 | (HPDF_INT16)b[1]); } - diff --git a/PDF/src/hpdf_fontdef_type1.c b/PDF/src/hpdf_fontdef_type1.c index ca8b80218..499f52146 100644 --- a/PDF/src/hpdf_fontdef_type1.c +++ b/PDF/src/hpdf_fontdef_type1.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_type1.c + * << Haru Free PDF Library >> -- hpdf_fontdef_type1.c * - * Copyright (c) 1999-2004 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -69,15 +72,12 @@ HPDF_Type1FontDef_New (HPDF_MMgr mmgr) if (!fontdef) return NULL; + HPDF_MemSet (fontdef, 0, sizeof (HPDF_FontDef_Rec)); fontdef->sig_bytes = HPDF_FONTDEF_SIG_BYTES; - fontdef->base_font[0] = 0; fontdef->mmgr = mmgr; fontdef->error = mmgr->error; fontdef->type = HPDF_FONTDEF_TYPE_TYPE1; - fontdef->clean_fn = NULL; fontdef->free_fn = FreeFunc; - fontdef->descriptor = NULL; - fontdef->valid = HPDF_FALSE; fontdef_attr = HPDF_GetMem (mmgr, sizeof(HPDF_Type1FontDefAttr_Rec)); if (!fontdef_attr) { @@ -106,7 +106,7 @@ GetKeyword (const char *src, *keyword = 0; - while (len > 0) { + while (len > 1) { if (HPDF_IS_WHITE_SPACE(*src)) { *keyword = 0; @@ -175,7 +175,7 @@ LoadAfm (HPDF_FontDef fontdef, } else if (HPDF_StrCmp (keyword, "ItalicAngle") == 0) { - fontdef->italic_angle = HPDF_AToI (s); + fontdef->italic_angle = (HPDF_INT16)HPDF_AToI (s); if (fontdef->italic_angle != 0) fontdef->flags |= HPDF_FONT_ITALIC; } else @@ -195,35 +195,35 @@ LoadAfm (HPDF_FontDef fontdef, char buf[HPDF_INT_LEN + 1]; s = GetKeyword (s, buf, HPDF_INT_LEN + 1); - fontdef->font_bbox.left = HPDF_AToI (buf); + fontdef->font_bbox.left = (HPDF_REAL)HPDF_AToI (buf); s = GetKeyword (s, buf, HPDF_INT_LEN + 1); - fontdef->font_bbox.bottom = HPDF_AToI (buf); + fontdef->font_bbox.bottom = (HPDF_REAL)HPDF_AToI (buf); s = GetKeyword (s, buf, HPDF_INT_LEN + 1); - fontdef->font_bbox.right = HPDF_AToI (buf); + fontdef->font_bbox.right = (HPDF_REAL)HPDF_AToI (buf); GetKeyword (s, buf, HPDF_INT_LEN + 1); - fontdef->font_bbox.top = HPDF_AToI (buf); + fontdef->font_bbox.top = (HPDF_REAL)HPDF_AToI (buf); } else if (HPDF_StrCmp (keyword, "EncodingScheme") == 0) { HPDF_StrCpy (attr->encoding_scheme, s, attr->encoding_scheme + HPDF_LIMIT_MAX_NAME_LEN); } else if (HPDF_StrCmp (keyword, "CapHeight") == 0) { - fontdef->cap_height = HPDF_AToI (s); + fontdef->cap_height = (HPDF_UINT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "Ascender") == 0) { - fontdef->ascent = HPDF_AToI (s); + fontdef->ascent = (HPDF_INT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "Descender") == 0) { - fontdef->descent = HPDF_AToI (s); + fontdef->descent = (HPDF_INT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "STDHW") == 0) { - fontdef->stemh = HPDF_AToI (s); + fontdef->stemh = (HPDF_UINT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "STDHV") == 0) { - fontdef->stemv = HPDF_AToI (s); + fontdef->stemv = (HPDF_UINT16)HPDF_AToI (s); } else if (HPDF_StrCmp (keyword, "StartCharMetrics") == 0) { attr->widths_count = HPDF_AToI (s); @@ -261,7 +261,7 @@ LoadAfm (HPDF_FontDef fontdef, s = GetKeyword (s, buf2, HPDF_LIMIT_MAX_NAME_LEN + 1); HPDF_AToI (buf2); - cdata->char_cd = HPDF_AToI (buf2); + cdata->char_cd = (HPDF_INT16)HPDF_AToI (buf2); } else return HPDF_SetError (fontdef->error, @@ -278,7 +278,7 @@ LoadAfm (HPDF_FontDef fontdef, if (buf2[0] == 0) return HPDF_SetError (fontdef->error, HPDF_INVALID_WX_DATA, 0); - cdata->width = HPDF_AToI (buf2); + cdata->width = (HPDF_INT16)HPDF_AToI (buf2); /* N PostScript language character name */ s = HPDF_StrStr (s, "N ", 0); @@ -316,14 +316,14 @@ LoadFontData (HPDF_FontDef fontdef, return HPDF_Error_GetCode (fontdef->error); len = 11; - ret = HPDF_Stream_Read (stream, pbuf, &len); + ret = HPDF_Stream_Read (stream, (HPDF_BYTE *)pbuf, &len); if (ret != HPDF_OK) return ret; pbuf += 11; for (;;) { len = HPDF_STREAM_BUF_SIZ - 11; - ret = HPDF_Stream_Read (stream, pbuf, &len); + ret = HPDF_Stream_Read (stream, (HPDF_BYTE *)pbuf, &len); if (ret == HPDF_STREAM_EOF) { end_flg = HPDF_TRUE; } else if (ret != HPDF_OK) @@ -354,16 +354,16 @@ LoadFontData (HPDF_FontDef fontdef, } if (end_flg) { - if ((ret = HPDF_Stream_Write (attr->font_data, buf, len + 11)) != + if ((ret = HPDF_Stream_Write (attr->font_data, (HPDF_BYTE *)buf, len + 11)) != HPDF_OK) return ret; break; } else { - if ((ret = HPDF_Stream_Write (attr->font_data, buf, len)) != + if ((ret = HPDF_Stream_Write (attr->font_data, (HPDF_BYTE *)buf, len)) != HPDF_OK) return ret; - HPDF_MemCpy (buf, buf + len, 11); + HPDF_MemCpy ((HPDF_BYTE *)buf, (HPDF_BYTE *)buf + len, 11); pbuf = buf + 11; } } @@ -401,7 +401,7 @@ HPDF_Type1FontDef_Load (HPDF_MMgr mmgr, return NULL; } - /* if font-data is specified, the font data is embedded */ + /* if font-data is specified, the font data is embeded */ if (font_data) { ret = LoadFontData (fontdef, font_data); if (ret != HPDF_OK) { @@ -424,8 +424,8 @@ HPDF_Type1FontDef_Duplicate (HPDF_MMgr mmgr, fontdef->type = src->type; fontdef->valid = src->valid; - // copy data of attr,widths - // attention to charset + /* copy data of attr,widths + attention to charset */ return NULL; } diff --git a/PDF/src/hpdf_gstate.c b/PDF/src/hpdf_gstate.c index 37860612c..c203c4d7f 100644 --- a/PDF/src/hpdf_gstate.c +++ b/PDF/src/hpdf_gstate.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_gstate.c + * << Haru Free PDF Library >> -- hpdf_gstate.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -59,6 +62,7 @@ HPDF_GState_New (HPDF_MMgr mmgr, gstate->font = current->font; gstate->font_size = current->font_size; + gstate->writing_mode = current->writing_mode; gstate->prev = current; gstate->depth = current->depth + 1; diff --git a/PDF/src/hpdf_image.c b/PDF/src/hpdf_image.c index 1e551eb79..eeec7c288 100644 --- a/PDF/src/hpdf_image.c +++ b/PDF/src/hpdf_image.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_image.c + * << Haru Free PDF Library >> -- hpdf_image.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -10,7 +13,6 @@ * in supporting documentation. * It is provided "as is" without express or implied warranty. * - * 2006.08.12 modified. */ #include "hpdf_conf.h" @@ -219,6 +221,36 @@ HPDF_Image_LoadJpegImage (HPDF_MMgr mmgr, return image; } +HPDF_Image +HPDF_Image_LoadJpegImageFromMem (HPDF_MMgr mmgr, + const HPDF_BYTE *buf, + HPDF_UINT size, + HPDF_Xref xref) +{ + HPDF_Stream jpeg_data; + HPDF_Image image; + + HPDF_PTRACE ((" HPDF_Image_LoadJpegImageFromMem\n")); + + jpeg_data = HPDF_MemStream_New(mmgr,size); + if (!HPDF_Stream_Validate (jpeg_data)) { + HPDF_RaiseError (mmgr->error, HPDF_INVALID_STREAM, 0); + return NULL; + } + + if (HPDF_Stream_Write (jpeg_data, buf, size) != HPDF_OK) { + HPDF_Stream_Free (jpeg_data); + return NULL; + } + + image = HPDF_Image_LoadJpegImage(mmgr,jpeg_data,xref); + + /* destroy file stream */ + HPDF_Stream_Free (jpeg_data); + + return image; +} + HPDF_Image HPDF_Image_LoadRawImage (HPDF_MMgr mmgr, @@ -297,12 +329,13 @@ HPDF_Image_LoadRawImageFromMem (HPDF_MMgr mmgr, { HPDF_Dict image; HPDF_STATUS ret = HPDF_OK; - HPDF_UINT size; + HPDF_UINT size=0; HPDF_PTRACE ((" HPDF_Image_LoadRawImageFromMem\n")); if (color_space != HPDF_CS_DEVICE_GRAY && - color_space != HPDF_CS_DEVICE_RGB) { + color_space != HPDF_CS_DEVICE_RGB && + color_space != HPDF_CS_DEVICE_CMYK) { HPDF_SetError (mmgr->error, HPDF_INVALID_COLOR_SPACE, 0); return NULL; } @@ -323,13 +356,22 @@ HPDF_Image_LoadRawImageFromMem (HPDF_MMgr mmgr, if (ret != HPDF_OK) return NULL; - if (color_space == HPDF_CS_DEVICE_GRAY) { - size = (HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876; - ret = HPDF_Dict_AddName (image, "ColorSpace", COL_GRAY); - } else { - size = (HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876; - size *= 3; - ret = HPDF_Dict_AddName (image, "ColorSpace", COL_RGB); + switch (color_space) { + case HPDF_CS_DEVICE_GRAY: + size = (HPDF_UINT)((HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876); + ret = HPDF_Dict_AddName (image, "ColorSpace", COL_GRAY); + break; + case HPDF_CS_DEVICE_RGB: + size = (HPDF_UINT)((HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876); + size *= 3; + ret = HPDF_Dict_AddName (image, "ColorSpace", COL_RGB); + break; + case HPDF_CS_DEVICE_CMYK: + size = (HPDF_UINT)((HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876); + size *= 4; + ret = HPDF_Dict_AddName (image, "ColorSpace", COL_CMYK); + break; + default:; } if (ret != HPDF_OK) @@ -394,8 +436,8 @@ HPDF_Image_GetSize (HPDF_Image image) height = HPDF_Dict_GetItem (image, "Height", HPDF_OCLASS_NUMBER); if (width && height) { - ret.x = width->value; - ret.y = height->value; + ret.x = (HPDF_REAL)width->value; + ret.y = (HPDF_REAL)height->value; } return ret; @@ -418,8 +460,8 @@ HPDF_Image_GetSize2 (HPDF_Image image, HPDF_Point *size) height = HPDF_Dict_GetItem (image, "Height", HPDF_OCLASS_NUMBER); if (width && height) { - size->x = width->value; - size->y = height->value; + size->x = (HPDF_REAL)width->value; + size->y = (HPDF_REAL)height->value; } return HPDF_OK; @@ -446,30 +488,42 @@ HPDF_Image_GetBitsPerComponent (HPDF_Image image) HPDF_EXPORT(const char*) HPDF_Image_GetColorSpace (HPDF_Image image) { - HPDF_Name n; + HPDF_Name n; - HPDF_PTRACE ((" HPDF_Image_GetColorSpace\n")); + HPDF_PTRACE ((" HPDF_Image_GetColorSpace\n")); - n = HPDF_Dict_GetItem (image, "ColorSpace", HPDF_OCLASS_NAME); + n = HPDF_Dict_GetItem (image, "ColorSpace", HPDF_OCLASS_NAME); - if (!n) { - HPDF_CheckError (image->error); - return NULL; - } + if (!n) { + HPDF_Array a; - return n->value; + HPDF_Error_Reset(image->error); + + a = HPDF_Dict_GetItem (image, "ColorSpace", HPDF_OCLASS_ARRAY); + + if (a) { + n = HPDF_Array_GetItem (a, 0, HPDF_OCLASS_NAME); + } + } + + if (!n) { + HPDF_CheckError (image->error); + return NULL; + } + + return n->value; } HPDF_EXPORT(HPDF_UINT) HPDF_Image_GetWidth (HPDF_Image image) { - return HPDF_Image_GetSize (image).x; + return (HPDF_UINT)HPDF_Image_GetSize (image).x; } HPDF_EXPORT(HPDF_UINT) HPDF_Image_GetHeight (HPDF_Image image) { - return HPDF_Image_GetSize (image).y; + return (HPDF_UINT)HPDF_Image_GetSize (image).y; } HPDF_STATUS @@ -565,4 +619,46 @@ HPDF_Image_SetColorMask (HPDF_Image image, return HPDF_OK; } +HPDF_EXPORT(HPDF_STATUS) +HPDF_Image_AddSMask (HPDF_Image image, + HPDF_Image smask) +{ + + const char *name; + + if (!HPDF_Image_Validate (image)) + return HPDF_INVALID_IMAGE; + if (!HPDF_Image_Validate (smask)) + return HPDF_INVALID_IMAGE; + + if (HPDF_Dict_GetItem (image, "SMask", HPDF_OCLASS_BOOLEAN)) + return HPDF_RaiseError (image->error, HPDF_INVALID_OPERATION, 0); + + name = HPDF_Image_GetColorSpace (smask); + if (!name || HPDF_StrCmp (COL_GRAY, name) != 0) + return HPDF_RaiseError (smask->error, HPDF_INVALID_COLOR_SPACE, 0); + + return HPDF_Dict_Add (image, "SMask", smask); +} + +HPDF_STATUS +HPDF_Image_SetColorSpace (HPDF_Image image, + HPDF_Array colorspace) +{ + if (!HPDF_Image_Validate (image)) + return HPDF_INVALID_IMAGE; + + return HPDF_Dict_Add (image, "ColorSpace", colorspace); +} + + +HPDF_STATUS +HPDF_Image_SetRenderingIntent (HPDF_Image image, + const char* intent) +{ + if (!HPDF_Image_Validate (image)) + return HPDF_INVALID_IMAGE; + + return HPDF_Dict_AddName (image, "Intent", intent); +} diff --git a/PDF/src/hpdf_image_ccitt.c b/PDF/src/hpdf_image_ccitt.c new file mode 100644 index 000000000..86727637d --- /dev/null +++ b/PDF/src/hpdf_image_ccitt.c @@ -0,0 +1,797 @@ +/* + * << Haru Free PDF Library >> -- hpdf_image.c + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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 "hpdf_conf.h" +#include "hpdf_utils.h" +#include "hpdf.h" +#include +#include + +#define G3CODES +#include "t4.h" + +typedef unsigned int uint32; +typedef int int32; +typedef unsigned short uint16; +typedef int32 tsize_t; /* i/o size in bytes */ +/* + * Typedefs for ``method pointers'' used internally. + */ +typedef unsigned char tidataval_t; /* internal image data value type */ +typedef tidataval_t* tidata_t; /* reference to internal image data */ + +/* + * Compression+decompression state blocks are + * derived from this ``base state'' block. + */ +typedef struct { + /* int rw_mode; */ /* O_RDONLY for decode, else encode */ + int mode; /* operating mode */ + uint32 rowbytes; /* bytes in a decoded scanline */ + uint32 rowpixels; /* pixels in a scanline */ + + uint16 cleanfaxdata; /* CleanFaxData tag */ + uint32 badfaxrun; /* BadFaxRun tag */ + uint32 badfaxlines; /* BadFaxLines tag */ + uint32 groupoptions; /* Group 3/4 options tag */ + uint32 recvparams; /* encoded Class 2 session params */ + char* subaddress; /* subaddress string */ + uint32 recvtime; /* time spent receiving (secs) */ + char* faxdcs; /* Table 2/T.30 encoded session params */ +} HPDF_Fax3BaseState; + +typedef struct { + HPDF_Fax3BaseState b; + + /* Decoder state info */ + const unsigned char* bitmap; /* bit reversal table */ + uint32 data; /* current i/o byte/word */ + int bit; /* current i/o bit in byte */ + int EOLcnt; /* count of EOL codes recognized */ + /* TIFFFaxFillFunc fill;*/ /* fill routine */ + uint32* runs; /* b&w runs for current/previous row */ + uint32* refruns; /* runs for reference line */ + uint32* curruns; /* runs for current line */ + + /* Encoder state info */ + /* Ttag tag; */ /* encoding state */ + unsigned char* refline; /* reference line for 2d decoding */ + int k; /* #rows left that can be 2d encoded */ + int maxk; /* max #rows that can be 2d encoded */ + + int line; +} HPDF_Fax3CodecState; + +#define Fax3State(tif) (&(tif)->tif_data->b) +#define EncoderState(tif) ((tif)->tif_data) +#define isAligned(p,t) ((((unsigned long)(p)) & (sizeof (t)-1)) == 0) + +/* NB: the uint32 casts are to silence certain ANSI-C compilers */ +#define TIFFhowmany(x, y) ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y))) +#define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3) +#define TIFFroundup(x, y) (TIFFhowmany(x,y)*(y)) + + +/* +struct _HPDF_CCITT_Encoder { +} HPDF_CCITT_Encoder; +*/ + +struct _HPDF_CCITT_Data { + HPDF_Fax3CodecState *tif_data; + + HPDF_Stream dst; + + tsize_t tif_rawdatasize;/* # of bytes in raw data buffer */ + tsize_t tif_rawcc; /* bytes unread from raw buffer */ + tidata_t tif_rawcp; /* current spot in raw buffer */ + tidata_t tif_rawdata; /* raw data buffer */ + +} HPDF_CCITT_Data; + +static HPDF_STATUS HPDF_InitCCITTFax3(struct _HPDF_CCITT_Data *pData) +{ + HPDF_Fax3BaseState* sp; + HPDF_Fax3CodecState* esp; + + /* + * Allocate state block so tag methods have storage to record values. + */ + pData->tif_data = (HPDF_Fax3CodecState *) + malloc(sizeof (HPDF_Fax3CodecState)); + + if (pData->tif_data == NULL) { + return 1; + } + + sp = Fax3State(pData); + /* sp->rw_mode = pData->tif_mode; */ + + /* + * Override parent get/set field methods. + */ + sp->groupoptions = 0; + sp->recvparams = 0; + sp->subaddress = NULL; + sp->faxdcs = NULL; + + esp = EncoderState(pData); + esp->refline = NULL; + esp->runs = NULL; + + return HPDF_OK; +} + +static HPDF_STATUS HPDF_FreeCCITTFax3(struct _HPDF_CCITT_Data *pData) +{ + if(pData->tif_data!=NULL) { + HPDF_Fax3CodecState* esp=pData->tif_data; + if(esp->refline!=NULL) { + free(esp->refline); + esp->refline=NULL; + } + if(esp->runs!=NULL) { + free(esp->runs); + esp->runs=NULL; + } + free(pData->tif_data); + pData->tif_data=NULL; + } + if(pData->tif_rawdata!=NULL) { + free(pData->tif_rawdata); + pData->tif_rawdata=NULL; + } + return HPDF_OK; +} + + +/* + * Setup G3/G4-related compression/decompression state + * before data is processed. This routine is called once + * per image -- it sets up different state based on whether + * or not decoding or encoding is being done and whether + * 1D- or 2D-encoded data is involved. + */ +static int +HPDF_Fax3SetupState(struct _HPDF_CCITT_Data *pData, HPDF_UINT width, + HPDF_UINT height, + HPDF_UINT line_width) +{ + HPDF_Fax3BaseState* sp = Fax3State(pData); + HPDF_Fax3CodecState* esp = EncoderState(pData); + uint32 rowbytes, rowpixels, nruns; + + HPDF_UNUSED (height); + + rowbytes = line_width; + rowpixels = width; + + sp->rowbytes = (uint32) rowbytes; + sp->rowpixels = (uint32) rowpixels; + + nruns = 2*TIFFroundup(rowpixels,32); + nruns += 3; + esp->runs = (uint32*) malloc(2*nruns * sizeof (uint32)); + if (esp->runs == NULL) + return 1; + esp->curruns = esp->runs; + esp->refruns = esp->runs + nruns; + + /* + * 2d encoding requires a scanline + * buffer for the ``reference line''; the + * scanline against which delta encoding + * is referenced. The reference line must + * be initialized to be ``white'' (done elsewhere). + */ + esp->refline = (unsigned char*) malloc(rowbytes); + if (esp->refline == NULL) { + return 1; + } + + return HPDF_OK; +} + +/* + * Reset encoding state at the start of a strip. + */ +static HPDF_STATUS +HPDF_Fax3PreEncode(struct _HPDF_CCITT_Data *pData/*, tsample_t s*/) +{ + HPDF_Fax3CodecState* sp = EncoderState(pData); + + /* assert(sp != NULL); */ + sp->bit = 8; + sp->data = 0; + /* sp->tag = G3_1D; */ + /* + * This is necessary for Group 4; otherwise it isn't + * needed because the first scanline of each strip ends + * up being copied into the refline. + */ + if (sp->refline) + memset(sp->refline, 0x00, sp->b.rowbytes); + sp->k = sp->maxk = 0; + sp->line = 0; + return HPDF_OK; +} + +static HPDF_STATUS +HPDF_CCITT_AppendToStream(HPDF_Stream dst, + tidata_t tif_rawdata, + tsize_t tif_rawcc) +{ + if(HPDF_Stream_Write(dst, tif_rawdata, tif_rawcc)!=HPDF_OK) + return 1; + return HPDF_OK; +} + +/* + * Internal version of TIFFFlushData that can be + * called by ``encodestrip routines'' w/o concern + * for infinite recursion. + */ +static HPDF_STATUS +HPDF_CCITT_FlushData(struct _HPDF_CCITT_Data *pData) +{ + if (pData->tif_rawcc > 0) { + /*if (!isFillOrder(tif, tif->tif_dir.td_fillorder) && + (tif->tif_flags & TIFF_NOBITREV) == 0) + TIFFReverseBits((unsigned char *pData->tif_rawdata, + pData->tif_rawcc);*/ + if (HPDF_CCITT_AppendToStream(pData->dst, + pData->tif_rawdata, pData->tif_rawcc)!=HPDF_OK) + return 1; + pData->tif_rawcc = 0; + pData->tif_rawcp = pData->tif_rawdata; + } + return HPDF_OK; +} + +#define HPDF_Fax3FlushBits(tif, sp) { \ + if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \ + (void) HPDF_CCITT_FlushData(tif); \ + *(tif)->tif_rawcp++ = (tidataval_t) (sp)->data; \ + (tif)->tif_rawcc++; \ + (sp)->data = 0, (sp)->bit = 8; \ +} +#define _FlushBits(tif) { \ + if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \ + (void) HPDF_CCITT_FlushData(tif); \ + *(tif)->tif_rawcp++ = (tidataval_t) data; \ + (tif)->tif_rawcc++; \ + data = 0, bit = 8; \ +} +static const int _msbmask[9] = + { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; +#define _PutBits(tif, bits, length) { \ + while (length > bit) { \ + data |= bits >> (length - bit); \ + length -= bit; \ + _FlushBits(tif); \ + } \ + data |= (bits & _msbmask[length]) << (bit - length); \ + bit -= length; \ + if (bit == 0) \ + _FlushBits(tif); \ +} + +/* + * Write a variable-length bit-value to + * the output stream. Values are + * assumed to be at most 16 bits. + */ +static void +HPDF_Fax3PutBits(struct _HPDF_CCITT_Data *pData, unsigned int bits, unsigned int length) +{ + HPDF_Fax3CodecState* sp = EncoderState(pData); + unsigned int bit = sp->bit; + int data = sp->data; + + _PutBits(pData, bits, length); + + sp->data = data; + sp->bit = bit; +} + +/* + * Write a code to the output stream. + */ +#define putcode(tif, te) HPDF_Fax3PutBits(tif, (te)->code, (te)->length) + + +/* + * Write the sequence of codes that describes + * the specified span of zero's or one's. The + * appropriate table that holds the make-up and + * terminating codes is supplied. + */ +static void +putspan(struct _HPDF_CCITT_Data *pData, int32 span, const tableentry* tab) +{ + HPDF_Fax3CodecState* sp = EncoderState(pData); + unsigned int bit = sp->bit; + int data = sp->data; + unsigned int code, length; + + while (span >= 2624) { + const tableentry* te = &tab[63 + (2560>>6)]; + code = te->code, length = te->length; +#ifdef FAX3_DEBUG + DEBUG_PRINT("MakeUp", te->runlen); +#endif + _PutBits(pData, code, length); + span -= te->runlen; + } + if (span >= 64) { + const tableentry* te = &tab[63 + (span>>6)]; + assert(te->runlen == 64*(span>>6)); + code = te->code, length = te->length; +#ifdef FAX3_DEBUG + DEBUG_PRINT("MakeUp", te->runlen); +#endif + _PutBits(pData, code, length); + span -= te->runlen; + } + code = tab[span].code, length = tab[span].length; +#ifdef FAX3_DEBUG + DEBUG_PRINT(" Term", tab[span].runlen); +#endif + _PutBits(pData, code, length); + + sp->data = data; + sp->bit = bit; +} + +static const unsigned char zeroruns[256] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, /* 0x00 - 0x0f */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0x10 - 0x1f */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x20 - 0x2f */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x30 - 0x3f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x50 - 0x5f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x70 - 0x7f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 - 0xaf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 - 0xbf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 - 0xcf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 - 0xdf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 - 0xef */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xf0 - 0xff */ +}; +static const unsigned char oneruns[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 - 0x0f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 - 0x2f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30 - 0x3f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x4f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x80 - 0x8f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x90 - 0x9f */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xa0 - 0xaf */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xb0 - 0xbf */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xc0 - 0xcf */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xd0 - 0xdf */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xe0 - 0xef */ + 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8, /* 0xf0 - 0xff */ +}; + +/* + * Find a span of ones or zeros using the supplied + * table. The ``base'' of the bit string is supplied + * along with the start+end bit indices. + */ +static /*inline*/ int32 find0span(unsigned char* bp, int32 bs, int32 be) +{ + int32 bits = be - bs; + int32 n, span; + + bp += bs>>3; + /* + * Check partial byte on lhs. + */ + if (bits > 0 && (n = (bs & 7))) { + span = zeroruns[(*bp << n) & 0xff]; + if (span > 8-n) /* table value too generous */ + span = 8-n; + if (span > bits) /* constrain span to bit range */ + span = bits; + if (n+span < 8) /* doesn't extend to edge of byte */ + return (span); + bits -= span; + bp++; + } else + span = 0; + if (bits >= (int32)(2 * 8 * sizeof(long))) { + long* lp; + /* + * Align to longword boundary and check longwords. + */ + while (!isAligned(bp, long)) { + if (*bp != 0x00) + return (span + zeroruns[*bp]); + span += 8, bits -= 8; + bp++; + } + lp = (long*) bp; + while ((bits >= (int32)(8 * sizeof(long))) && (0 == *lp)) { + span += 8*sizeof (long), bits -= 8*sizeof (long); + lp++; + } + bp = (unsigned char*) lp; + } + /* + * Scan full bytes for all 0's. + */ + while (bits >= 8) { + if (*bp != 0x00) /* end of run */ + return (span + zeroruns[*bp]); + span += 8, bits -= 8; + bp++; + } + /* + * Check partial byte on rhs. + */ + if (bits > 0) { + n = zeroruns[*bp]; + span += (n > bits ? bits : n); + } + return (span); +} + +static /*inline*/ int32 +find1span(unsigned char* bp, int32 bs, int32 be) +{ + int32 bits = be - bs; + int32 n, span; + + bp += bs>>3; + /* + * Check partial byte on lhs. + */ + if (bits > 0 && (n = (bs & 7))) { + span = oneruns[(*bp << n) & 0xff]; + if (span > 8-n) /* table value too generous */ + span = 8-n; + if (span > bits) /* constrain span to bit range */ + span = bits; + if (n+span < 8) /* doesn't extend to edge of byte */ + return (span); + bits -= span; + bp++; + } else + span = 0; + if (bits >= (int32)(2 * 8 * sizeof(long))) { + long* lp; + /* + * Align to longword boundary and check longwords. + */ + while (!isAligned(bp, long)) { + if (*bp != 0xff) + return (span + oneruns[*bp]); + span += 8, bits -= 8; + bp++; + } + lp = (long*) bp; + while ((bits >= (int32)(8 * sizeof(long))) && (~0 == *lp)) { + span += 8*sizeof (long), bits -= 8*sizeof (long); + lp++; + } + bp = (unsigned char*) lp; + } + /* + * Scan full bytes for all 1's. + */ + while (bits >= 8) { + if (*bp != 0xff) /* end of run */ + return (span + oneruns[*bp]); + span += 8, bits -= 8; + bp++; + } + /* + * Check partial byte on rhs. + */ + if (bits > 0) { + n = oneruns[*bp]; + span += (n > bits ? bits : n); + } + return (span); +} + +/* + * Return the offset of the next bit in the range + * [bs..be] that is different from the specified + * color. The end, be, is returned if no such bit + * exists. + */ +#define finddiff(_cp, _bs, _be, _color) \ + (_bs + (_color ? find1span(_cp,_bs,_be) : find0span(_cp,_bs,_be))) +/* + * Like finddiff, but also check the starting bit + * against the end in case start > end. + */ +#define finddiff2(_cp, _bs, _be, _color) \ + (_bs < _be ? finddiff(_cp,_bs,_be,_color) : _be) + + +/* +void +HPDF_Fax3PostEncode(struct _HPDF_CCITT_Data *pData) +{ + HPDF_Fax3CodecState* sp = EncoderState(pData); + + if (sp->bit != 8) + HPDF_Fax3FlushBits(pData, sp); +} +*/ + +static const tableentry horizcode = + { 3, 0x1, 0 }; /* 001 */ +static const tableentry passcode = + { 4, 0x1, 0 }; /* 0001 */ +static const tableentry vcodes[7] = { + { 7, 0x03, 0 }, /* 0000 011 */ + { 6, 0x03, 0 }, /* 0000 11 */ + { 3, 0x03, 0 }, /* 011 */ + { 1, 0x1, 0 }, /* 1 */ + { 3, 0x2, 0 }, /* 010 */ + { 6, 0x02, 0 }, /* 0000 10 */ + { 7, 0x02, 0 } /* 0000 010 */ +}; + +/* + * 2d-encode a row of pixels. Consult the CCITT + * documentation for the algorithm. + */ +static HPDF_STATUS +HPDF_Fax3Encode2DRow(struct _HPDF_CCITT_Data *pData, unsigned char* bp, unsigned char* rp, uint32 bits) +{ +#define PIXEL(buf,ix) ((((buf)[(ix)>>3]) >> (7-((ix)&7))) & 1) + uint32 a0 = 0; + uint32 a1 = (PIXEL(bp, 0) != 0 ? 0 : finddiff(bp, 0, bits, 0)); + uint32 b1 = (PIXEL(rp, 0) != 0 ? 0 : finddiff(rp, 0, bits, 0)); + uint32 a2, b2; + + for (;;) { + b2 = finddiff2(rp, b1, bits, PIXEL(rp,b1)); + if (b2 >= a1) { + int32 d = b1 - a1; + if (!(-3 <= d && d <= 3)) { /* horizontal mode */ + a2 = finddiff2(bp, a1, bits, PIXEL(bp,a1)); + putcode(pData, &horizcode); + if (a0+a1 == 0 || PIXEL(bp, a0) == 0) { + putspan(pData, a1-a0, TIFFFaxWhiteCodes); + putspan(pData, a2-a1, TIFFFaxBlackCodes); + } else { + putspan(pData, a1-a0, TIFFFaxBlackCodes); + putspan(pData, a2-a1, TIFFFaxWhiteCodes); + } + a0 = a2; + } else { /* vertical mode */ + putcode(pData, &vcodes[d+3]); + a0 = a1; + } + } else { /* pass mode */ + putcode(pData, &passcode); + a0 = b2; + } + if (a0 >= bits) + break; + a1 = finddiff(bp, a0, bits, PIXEL(bp,a0)); + b1 = finddiff(rp, a0, bits, !PIXEL(bp,a0)); + b1 = finddiff(rp, b1, bits, PIXEL(bp,a0)); + } + return HPDF_OK; +#undef PIXEL +} + +/* + * Encode the requested amount of data. + */ +static HPDF_STATUS +HPDF_Fax4Encode(struct _HPDF_CCITT_Data *pData, tidata_t bp, tsize_t cc/*, tsample_t s*/) +{ + HPDF_Fax3CodecState *sp = EncoderState(pData); + + /* (void) s; */ + while ((long)cc > 0) { + if (HPDF_Fax3Encode2DRow(pData, bp, sp->refline, sp->b.rowpixels)!=HPDF_OK) + return 1; + memcpy(sp->refline, bp, sp->b.rowbytes); + bp += sp->b.rowbytes; + cc -= sp->b.rowbytes; + } + return HPDF_OK; +} + +static void +HPDF_Fax4PostEncode(struct _HPDF_CCITT_Data *pData) +{ + /* HPDF_Fax3CodecState *sp = EncoderState(pData); */ + + /* terminate strip w/ EOFB */ + HPDF_Fax3PutBits(pData, EOL, 12); + HPDF_Fax3PutBits(pData, EOL, 12); + /*if (sp->bit != 8) + HPDF_Fax3FlushBits(pData, sp); + */ + HPDF_CCITT_FlushData(pData); +} + + + +HPDF_STATUS +HPDF_Stream_CcittToStream( const HPDF_BYTE *buf, + HPDF_Stream dst, + HPDF_Encrypt e, + HPDF_UINT width, + HPDF_UINT height, + HPDF_UINT line_width, + HPDF_BOOL top_is_first) +{ + const HPDF_BYTE *pBufPos; + const HPDF_BYTE *pBufEnd; /* end marker */ + int lineIncrement; + struct _HPDF_CCITT_Data data; + + HPDF_UNUSED (e); + + if(height==0) return 1; + if(top_is_first) { + pBufPos = buf; + pBufEnd=buf+(line_width*height); + lineIncrement = line_width; + } else { + pBufPos = buf+(line_width*(height-1)); + pBufEnd= buf-line_width; + lineIncrement = -((int)line_width); + } + + memset(&data, 0, sizeof(struct _HPDF_CCITT_Data)); + data.dst = dst; + data.tif_rawdata = (tidata_t) malloc( 16384 ); /* 16 kb buffer */ + data.tif_rawdatasize = 16384; + data.tif_rawcc = 0; + data.tif_rawcp = data.tif_rawdata; + + if(HPDF_InitCCITTFax3(&data)!=HPDF_OK) + return 1; + + if(HPDF_Fax3SetupState(&data, width, height, line_width)!=HPDF_OK) + { + HPDF_FreeCCITTFax3(&data); + return 1; + } + + if(HPDF_Fax3PreEncode(&data)!=HPDF_OK) + { + HPDF_FreeCCITTFax3(&data); + return 1; + } + + /* encode data */ + while(pBufEnd!=pBufPos) + { + HPDF_Fax4Encode(&data, (tidata_t)pBufPos, line_width); + pBufPos+=lineIncrement; + } + + HPDF_Fax4PostEncode(&data); + + HPDF_FreeCCITTFax3(&data); + + return HPDF_OK; +} + +HPDF_Image +HPDF_Image_Load1BitImageFromMem (HPDF_MMgr mmgr, + const HPDF_BYTE *buf, + HPDF_Xref xref, + HPDF_UINT width, + HPDF_UINT height, + HPDF_UINT line_width, + HPDF_BOOL top_is_first + ) +{ + HPDF_Dict image; + HPDF_STATUS ret = HPDF_OK; + /* HPDF_UINT size; */ + + HPDF_PTRACE ((" HPDF_Image_Load1BitImage\n")); + + image = HPDF_DictStream_New (mmgr, xref); + if (!image) + return NULL; + + image->header.obj_class |= HPDF_OSUBCLASS_XOBJECT; + ret += HPDF_Dict_AddName (image, "Type", "XObject"); + ret += HPDF_Dict_AddName (image, "Subtype", "Image"); + if (ret != HPDF_OK) + return NULL; + + /* size = width * height; */ + ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray"); + if (ret != HPDF_OK) + return NULL; + + if (HPDF_Dict_AddNumber (image, "Width", width) != HPDF_OK) + return NULL; + + if (HPDF_Dict_AddNumber (image, "Height", height) != HPDF_OK) + return NULL; + + if (HPDF_Dict_AddNumber (image, "BitsPerComponent", 1) != HPDF_OK) + return NULL; + + if (HPDF_Stream_CcittToStream (buf, image->stream, NULL, width, height, line_width, top_is_first) != HPDF_OK) + return NULL; + + return image; +} + +/* + * Load image from buffer + * line_width - width of the line in bytes + * top_is_first - image orientation: + * TRUE if image is oriented TOP-BOTTOM; + * FALSE if image is oriented BOTTOM-TOP + */ +HPDF_EXPORT(HPDF_Image) +HPDF_Image_LoadRaw1BitImageFromMem (HPDF_Doc pdf, + const HPDF_BYTE *buf, + HPDF_UINT width, + HPDF_UINT height, + HPDF_UINT line_width, + HPDF_BOOL black_is1, + HPDF_BOOL top_is_first) +{ + HPDF_Image image; + + HPDF_PTRACE ((" HPDF_Image_Load1BitImageFromMem\n")); + + if (!HPDF_HasDoc (pdf)) + return NULL; + + image = HPDF_Image_Load1BitImageFromMem(pdf->mmgr, buf, pdf->xref, width, + height, line_width, top_is_first); + + if (!image) + HPDF_CheckError (&pdf->error); + + if (pdf->compression_mode & HPDF_COMP_IMAGE) + { + image->filter = HPDF_STREAM_FILTER_CCITT_DECODE; + image->filterParams = HPDF_Dict_New(pdf->mmgr); + if(image->filterParams==NULL) { + return NULL; + } + + /* pure 2D encoding, default is 0 */ + HPDF_Dict_AddNumber (image->filterParams, "K", -1); + /* default is 1728 */ + HPDF_Dict_AddNumber (image->filterParams, "Columns", width); + /* default is 0 */ + HPDF_Dict_AddNumber (image->filterParams, "Rows", height); + HPDF_Dict_AddBoolean (image->filterParams, "BlackIs1", black_is1); + } + + return image; +} diff --git a/PDF/src/hpdf_image_png.c b/PDF/src/hpdf_image_png.c index 151e82978..3a35f5c3c 100644 --- a/PDF/src/hpdf_image_png.c +++ b/PDF/src/hpdf_image_png.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_image.c + * << Haru Free PDF Library >> -- hpdf_image.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -16,8 +19,9 @@ #include "hpdf_utils.h" #include "hpdf_image.h" -#ifndef HPDF_NOPNGLIB +#ifndef LIBHPDF_HAVE_NOPNGLIB #include +#include static void PngErrorFunc (png_structp png_ptr, @@ -38,6 +42,7 @@ PngReadFunc (png_structp png_ptr, static HPDF_STATUS LoadPngData (HPDF_Dict image, + HPDF_Xref xref, HPDF_Stream png_data, HPDF_BOOL delayed_loading); @@ -105,14 +110,15 @@ ReadPngData_Interlaced (HPDF_Dict image, png_infop info_ptr) { png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr); + png_uint_32 height = png_get_image_height(png_ptr, info_ptr); png_bytep* row_pointers = HPDF_GetMem (image->mmgr, - info_ptr->height * sizeof (png_bytep)); + height * sizeof (png_bytep)); if (row_pointers) { HPDF_UINT i; - HPDF_MemSet (row_pointers, 0, info_ptr->height * sizeof (png_bytep)); - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) { + HPDF_MemSet (row_pointers, 0, height * sizeof (png_bytep)); + for (i = 0; i < (HPDF_UINT)height; i++) { row_pointers[i] = HPDF_GetMem (image->mmgr, len); if (image->error->error_no != HPDF_OK) @@ -120,11 +126,9 @@ ReadPngData_Interlaced (HPDF_Dict image, } if (image->error->error_no == HPDF_OK) { -/* } else { remove this line */ png_read_image(png_ptr, row_pointers); -/* if (image->error->error_no != HPDF_OK) { remove this line */ if (image->error->error_no == HPDF_OK) { /* add this line */ - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) { + for (i = 0; i < (HPDF_UINT)height; i++) { if (HPDF_Stream_Write (image->stream, row_pointers[i], len) != HPDF_OK) break; @@ -133,9 +137,8 @@ ReadPngData_Interlaced (HPDF_Dict image, } /* clean up */ - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) { + for (i = 0; i < (HPDF_UINT)height; i++) { HPDF_FreeMem (image->mmgr, row_pointers[i]); -/* i-- remove this line */ } HPDF_FreeMem (image->mmgr, row_pointers); @@ -150,12 +153,13 @@ ReadPngData (HPDF_Dict image, png_infop info_ptr) { png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr); + png_uint_32 height = png_get_image_height(png_ptr, info_ptr); png_bytep buf_ptr = HPDF_GetMem (image->mmgr, len); if (buf_ptr) { HPDF_UINT i; - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) { + for (i = 0; i < (HPDF_UINT)height; i++) { png_read_rows(png_ptr, (png_byte**)&buf_ptr, NULL, 1); if (image->error->error_no != HPDF_OK) break; @@ -170,6 +174,152 @@ ReadPngData (HPDF_Dict image, return image->error->error_no; } +static HPDF_STATUS +ReadTransparentPaletteData (HPDF_Dict image, + png_structp png_ptr, + png_infop info_ptr, + png_bytep smask_data, + png_bytep trans, + int num_trans) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_UINT i, j; + png_bytep *row_ptr; + png_uint_32 height = png_get_image_height(png_ptr, info_ptr); + png_uint_32 width = png_get_image_width(png_ptr, info_ptr); + + row_ptr = HPDF_GetMem (image->mmgr, height * sizeof(png_bytep)); + if (!row_ptr) { + return HPDF_FAILD_TO_ALLOC_MEM; + } else { + png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr); + + for (i = 0; i < (HPDF_UINT)height; i++) { + row_ptr[i] = HPDF_GetMem(image->mmgr, len); + if (!row_ptr[i]) { + for (; i > 0; i--) { + HPDF_FreeMem (image->mmgr, row_ptr[i]); + } + HPDF_FreeMem (image->mmgr, row_ptr); + return HPDF_FAILD_TO_ALLOC_MEM; + } + } + } + + png_read_image(png_ptr, row_ptr); + if (image->error->error_no != HPDF_OK) { + ret = HPDF_INVALID_PNG_IMAGE; + goto Error; + } + + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + smask_data[width * j + i] = (row_ptr[j][i] < num_trans) ? trans[row_ptr[j][i]] : 0xFF; + } + + if (HPDF_Stream_Write (image->stream, row_ptr[j], width) != HPDF_OK) { + ret = HPDF_FILE_IO_ERROR; + goto Error; + } + } + +Error: + for (i = 0; i < (HPDF_UINT)height; i++) { + HPDF_FreeMem (image->mmgr, row_ptr[i]); + } + + HPDF_FreeMem (image->mmgr, row_ptr); + return ret; +} + +static HPDF_STATUS +ReadTransparentPngData (HPDF_Dict image, + png_structp png_ptr, + png_infop info_ptr, + png_bytep smask_data) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_INT row_len; + HPDF_UINT i, j; + png_bytep *row_ptr, row; + png_byte color_type; + png_uint_32 height = png_get_image_height(png_ptr, info_ptr); + png_uint_32 width = png_get_image_width(png_ptr, info_ptr); + + color_type = png_get_color_type(png_ptr, info_ptr); + + if (!(color_type & PNG_COLOR_MASK_ALPHA)) { + return HPDF_INVALID_PNG_IMAGE; + } + + row_ptr = HPDF_GetMem (image->mmgr, height * sizeof(png_bytep)); + if (!row_ptr) { + return HPDF_FAILD_TO_ALLOC_MEM; + } else { + png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr); + + for (i = 0; i < (HPDF_UINT)height; i++) { + row_ptr[i] = HPDF_GetMem(image->mmgr, len); + if (!row_ptr[i]) { + for (; i > 0; i--) { + HPDF_FreeMem (image->mmgr, row_ptr[i]); + } + HPDF_FreeMem (image->mmgr, row_ptr); + return HPDF_FAILD_TO_ALLOC_MEM; + } + } + } + + png_read_image(png_ptr, row_ptr); + if (image->error->error_no != HPDF_OK) { + ret = HPDF_INVALID_PNG_IMAGE; + goto Error; + } + + switch (color_type) { + case PNG_COLOR_TYPE_RGB_ALPHA: + row_len = 3 * width * sizeof(png_byte); + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + row = row_ptr[j]; + memmove(row + (3 * i), row + (4*i), 3); + smask_data[width * j + i] = row[4 * i + 3]; + } + + if (HPDF_Stream_Write (image->stream, row, row_len) != HPDF_OK) { + ret = HPDF_FILE_IO_ERROR; + goto Error; + } + } + break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + row_len = width * sizeof(png_byte); + for (j = 0; j < height; j++) { + for (i = 0; i < width; i++) { + row = row_ptr[j]; + row[i] = row[2 * i]; + smask_data[width * j + i] = row[2 * i + 1]; + } + + if (HPDF_Stream_Write (image->stream, row, row_len) != HPDF_OK) { + ret = HPDF_FILE_IO_ERROR; + goto Error; + } + } + break; + default: + ret = HPDF_INVALID_PNG_IMAGE; + goto Error; + } + +Error: + for (i = 0; i < (HPDF_UINT)height; i++) { + HPDF_FreeMem (image->mmgr, row_ptr[i]); + } + + HPDF_FreeMem (image->mmgr, row_ptr); + return ret; +} static HPDF_STATUS CreatePallet (HPDF_Dict image, @@ -257,7 +407,7 @@ HPDF_Image_LoadPngImage (HPDF_MMgr mmgr, if (ret != HPDF_OK) return NULL; - if (LoadPngData (image, png_data, delayed_loading) != HPDF_OK) + if (LoadPngData (image, xref, png_data, delayed_loading) != HPDF_OK) return NULL; return image; @@ -266,106 +416,241 @@ HPDF_Image_LoadPngImage (HPDF_MMgr mmgr, static HPDF_STATUS LoadPngData (HPDF_Dict image, + HPDF_Xref xref, HPDF_Stream png_data, HPDF_BOOL delayed_loading) { - HPDF_STATUS ret; - png_structp png_ptr = NULL; - png_infop info_ptr = NULL; + HPDF_STATUS ret = HPDF_OK; + png_uint_32 width, height; + int bit_depth, color_type; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; - HPDF_PTRACE ((" HPDF_Image_LoadPngImage\n")); + HPDF_PTRACE ((" HPDF_Image_LoadPngImage\n")); - /* create read_struct. */ - png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, - image->error, PngErrorFunc, PngErrorFunc); + /* create read_struct. */ + png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, + image->error, PngErrorFunc, PngErrorFunc); - if (png_ptr == NULL) { - HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0); - return HPDF_FAILD_TO_ALLOC_MEM; - } + if (png_ptr == NULL) { + HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0); + return HPDF_FAILD_TO_ALLOC_MEM; + } - /* create info-struct */ - info_ptr = png_create_info_struct (png_ptr); + /* create info-struct */ + info_ptr = png_create_info_struct (png_ptr); - if (info_ptr == NULL) { - HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0); - goto Exit; - } + if (info_ptr == NULL) { + HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0); + goto Exit; + } - png_set_sig_bytes (png_ptr, HPDF_PNG_BYTES_TO_CHECK); - png_set_read_fn (png_ptr, (void *)png_data, (png_rw_ptr)&PngReadFunc); + png_set_sig_bytes (png_ptr, HPDF_PNG_BYTES_TO_CHECK); + png_set_read_fn (png_ptr, (void *)png_data, (png_rw_ptr)&PngReadFunc); - /* reading info structure. */ - png_read_info(png_ptr, info_ptr); - if (image->error->error_no != HPDF_OK) - goto Exit; + /* reading info structure. */ + png_read_info(png_ptr, info_ptr); + if (image->error->error_no != HPDF_OK) { + goto Exit; + } - /* 16bit image and alpha color type are not supported. */ - if (info_ptr->bit_depth == 16) - png_set_strip_16(png_ptr); + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL); - if (PNG_COLOR_MASK_ALPHA & info_ptr->color_type) { - /* png image with alpha chanel is not supported. */ - png_set_strip_alpha(png_ptr); - } + /* 16bit images are not supported. */ + if (bit_depth == 16) { + png_set_strip_16(png_ptr); + } - png_read_update_info(png_ptr, info_ptr); - if (image->error->error_no != HPDF_OK) - goto Exit; + png_read_update_info(png_ptr, info_ptr); + if (image->error->error_no != HPDF_OK) { + goto Exit; + } - /* if the image has color palette, copy the pallet of the image to - * create color map. - */ - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) - ret = CreatePallet(image, png_ptr, info_ptr); - else if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) - ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray"); - else - ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB"); + /* check palette-based images for transparent areas and load them immediately if found */ + if (xref && PNG_COLOR_TYPE_PALETTE & color_type) { + png_bytep trans; + int num_trans; + HPDF_Dict smask; + png_bytep smask_data; - if (ret != HPDF_OK) - goto Exit; + if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) || + !png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL)) { + goto no_transparent_color_in_palette; + } - /* read image-data - * if the image is interlaced, read whole image at once. - * if delayed_loading is HPDF_TRUE, the data does not load this phase. - */ - if (delayed_loading) { - image->before_write_fn = PngBeforeWrite; - image->after_write_fn = PngAfterWrite; - } else { - if (png_get_interlace_type(png_ptr, info_ptr) != PNG_INTERLACE_NONE) - ret = ReadPngData_Interlaced(image, png_ptr, info_ptr); - else - ret = ReadPngData(image, png_ptr, info_ptr); + smask = HPDF_DictStream_New (image->mmgr, xref); + if (!smask) { + ret = HPDF_FAILD_TO_ALLOC_MEM; + goto Exit; + } - if (ret != HPDF_OK) - goto Exit; - } + smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT; + ret = HPDF_Dict_AddName (smask, "Type", "XObject"); + ret += HPDF_Dict_AddName (smask, "Subtype", "Image"); + ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width); + ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height); + ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray"); + ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth); - /* setting the info of the image. */ - if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)info_ptr->width) - != HPDF_OK) - goto Exit; + if (ret != HPDF_OK) { + HPDF_Dict_Free(smask); + ret = HPDF_INVALID_PNG_IMAGE; + goto Exit; + } - if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)info_ptr->height) - != HPDF_OK) - goto Exit; + smask_data = HPDF_GetMem(image->mmgr, width * height); + if (!smask_data) { + HPDF_Dict_Free(smask); + ret = HPDF_FAILD_TO_ALLOC_MEM; + goto Exit; + } - if (HPDF_Dict_AddNumber (image, "BitsPerComponent", - (HPDF_UINT)info_ptr->bit_depth) != HPDF_OK) - goto Exit; + if (ReadTransparentPaletteData(image, png_ptr, info_ptr, smask_data, trans, num_trans) != HPDF_OK) { + HPDF_FreeMem(image->mmgr, smask_data); + HPDF_Dict_Free(smask); + ret = HPDF_INVALID_PNG_IMAGE; + goto Exit; + } - /* clean up */ - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) { + HPDF_FreeMem(image->mmgr, smask_data); + HPDF_Dict_Free(smask); + ret = HPDF_FILE_IO_ERROR; + goto Exit; + } + HPDF_FreeMem(image->mmgr, smask_data); - return HPDF_OK; + + ret += CreatePallet(image, png_ptr, info_ptr); + ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width); + ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height); + ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth); + ret += HPDF_Dict_Add (image, "SMask", smask); + + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return HPDF_OK; + } + +no_transparent_color_in_palette: + + /* read images with alpha channel right away + we have to do this because image transparent mask must be added to the Xref */ + if (xref && PNG_COLOR_MASK_ALPHA & color_type) { + HPDF_Dict smask; + png_bytep smask_data; + + smask = HPDF_DictStream_New (image->mmgr, xref); + if (!smask) { + ret = HPDF_FAILD_TO_ALLOC_MEM; + goto Exit; + } + + smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT; + ret = HPDF_Dict_AddName (smask, "Type", "XObject"); + ret += HPDF_Dict_AddName (smask, "Subtype", "Image"); + ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width); + ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height); + ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray"); + ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth); + + if (ret != HPDF_OK) { + HPDF_Dict_Free(smask); + ret = HPDF_INVALID_PNG_IMAGE; + goto Exit; + } + + smask_data = HPDF_GetMem(image->mmgr, width * height); + if (!smask_data) { + HPDF_Dict_Free(smask); + ret = HPDF_FAILD_TO_ALLOC_MEM; + goto Exit; + } + + if (ReadTransparentPngData(image, png_ptr, info_ptr, smask_data) != HPDF_OK) { + HPDF_FreeMem(image->mmgr, smask_data); + HPDF_Dict_Free(smask); + ret = HPDF_INVALID_PNG_IMAGE; + goto Exit; + } + + if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) { + HPDF_FreeMem(image->mmgr, smask_data); + HPDF_Dict_Free(smask); + ret = HPDF_FILE_IO_ERROR; + goto Exit; + } + HPDF_FreeMem(image->mmgr, smask_data); + + if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { + ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray"); + } else { + ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB"); + } + ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width); + ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height); + ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth); + ret += HPDF_Dict_Add (image, "SMask", smask); + + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return HPDF_OK; + } + + /* if the image has color palette, copy the pallet of the image to + * create color map. + */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + ret = CreatePallet(image, png_ptr, info_ptr); + else if (color_type == PNG_COLOR_TYPE_GRAY) + ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray"); + else + ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB"); + + if (ret != HPDF_OK) + goto Exit; + + /* read image-data + * if the image is interlaced, read whole image at once. + * if delayed_loading is HPDF_TRUE, the data does not load this phase. + */ + if (delayed_loading) { + image->before_write_fn = PngBeforeWrite; + image->after_write_fn = PngAfterWrite; + } else { + if (png_get_interlace_type(png_ptr, info_ptr) != PNG_INTERLACE_NONE) + ret = ReadPngData_Interlaced(image, png_ptr, info_ptr); + else + ret = ReadPngData(image, png_ptr, info_ptr); + + if (ret != HPDF_OK) + goto Exit; + } + + /* setting the info of the image. */ + if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width) + != HPDF_OK) + goto Exit; + + if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height) + != HPDF_OK) + goto Exit; + + if (HPDF_Dict_AddNumber (image, "BitsPerComponent", + (HPDF_UINT)bit_depth) != HPDF_OK) + goto Exit; + + /* clean up */ + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + + return HPDF_OK; Exit: - png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); - return image->error->error_no; + if (ret != HPDF_OK) { + return ret; + } + return image->error->error_no; } @@ -386,7 +671,7 @@ PngBeforeWrite (HPDF_Dict obj) if (!s) return HPDF_SetError (obj->error, HPDF_MISSING_FILE_NAME_ENTRY, 0); - png_data = HPDF_FileReader_New (obj->mmgr, s->value); + png_data = HPDF_FileReader_New (obj->mmgr, (const char *)(s->value)); if (!HPDF_Stream_Validate (png_data)) return obj->error->error_no; @@ -398,7 +683,7 @@ PngBeforeWrite (HPDF_Dict obj) return HPDF_SetError (obj->error, HPDF_INVALID_PNG_IMAGE, 0); } - if ((ret = LoadPngData (obj, png_data, HPDF_FALSE)) != HPDF_OK) { + if ((ret = LoadPngData (obj, NULL, png_data, HPDF_FALSE)) != HPDF_OK) { HPDF_Stream_Free(png_data); return ret; } @@ -420,5 +705,5 @@ PngAfterWrite (HPDF_Dict obj) } -#endif /* HPDF_NOPNGLIB */ +#endif /* LIBHPDF_HAVE_NOPNGLIB */ diff --git a/PDF/src/hpdf_info.c b/PDF/src/hpdf_info.c index 5fac8a012..5fb601add 100644 --- a/PDF/src/hpdf_info.c +++ b/PDF/src/hpdf_info.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_info.c + * << Haru Free PDF Library >> -- hpdf_info.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -16,7 +19,7 @@ #include "hpdf_utils.h" #include "hpdf_info.h" -static const char *HPDF_INFO_ATTR_NAMES[] = { +static const char * const HPDF_INFO_ATTR_NAMES[] = { "CreationDate", "ModDate", "Author", @@ -25,6 +28,8 @@ static const char *HPDF_INFO_ATTR_NAMES[] = { "Title", "Subject", "Keywords", + "Trapped", + "GTS_PDFXVersion", NULL }; @@ -57,6 +62,9 @@ HPDF_Info_SetInfoAttr (HPDF_Dict info, if (type <= HPDF_INFO_MOD_DATE) return HPDF_SetError (info->error, HPDF_INVALID_PARAMETER, 0); + if (type == HPDF_INFO_TRAPPED) + return HPDF_Dict_AddName(info, name, value); + return HPDF_Dict_Add (info, name, HPDF_String_New (info->mmgr, value, encoder)); } @@ -79,7 +87,7 @@ HPDF_Info_GetInfoAttr (HPDF_Dict info, if (!s) return NULL; else - return s->value; + return (const char *)(s->value); } @@ -141,7 +149,7 @@ HPDF_Info_SetInfoDateAttr (HPDF_Dict info, return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0); } - ptmp = HPDF_MemCpy (tmp, "D:", 2); + ptmp = (char *)HPDF_MemCpy ((HPDF_BYTE *)tmp, (HPDF_BYTE *)"D:", 2); ptmp = HPDF_IToA2 (ptmp, value.year, 5); ptmp = HPDF_IToA2 (ptmp, value.month, 3); ptmp = HPDF_IToA2 (ptmp, value.day, 3); diff --git a/PDF/src/hpdf_list.c b/PDF/src/hpdf_list.c index 1f26303d7..b90bf1bbe 100644 --- a/PDF/src/hpdf_list.c +++ b/PDF/src/hpdf_list.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_list.c + * << Haru Free PDF Library >> -- hpdf_list.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -272,7 +275,7 @@ HPDF_List_Clear (HPDF_List list) * */ -HPDF_STATUS +static HPDF_STATUS Resize (HPDF_List list, HPDF_UINT count) { diff --git a/PDF/src/hpdf_mmgr.c b/PDF/src/hpdf_mmgr.c index 90f4a9549..3069a0552 100644 --- a/PDF/src/hpdf_mmgr.c +++ b/PDF/src/hpdf_mmgr.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_mmgr.c + * << Haru Free PDF Library >> -- hpdf_mmgr.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -104,11 +107,15 @@ HPDF_MMgr_New (HPDF_Error error, } #ifdef HPDF_MEM_DEBUG - mmgr->alloc_cnt += 1; + if (mmgr) { + mmgr->alloc_cnt += 1; + } #endif } - mmgr->buf_size = buf_size; + if (mmgr) { + mmgr->buf_size = buf_size; + } } else HPDF_SetError(error, HPDF_FAILD_TO_ALLOC_MEM, HPDF_NOERROR); diff --git a/PDF/src/hpdf_name.c b/PDF/src/hpdf_name.c index 0c9074895..9c27fb0d6 100644 --- a/PDF/src/hpdf_name.c +++ b/PDF/src/hpdf_name.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_name.c + * << Haru Free PDF Library >> -- hpdf_name.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_namedict.c b/PDF/src/hpdf_namedict.c new file mode 100644 index 000000000..e259a3a42 --- /dev/null +++ b/PDF/src/hpdf_namedict.c @@ -0,0 +1,237 @@ +/* + * << Haru Free PDF Library >> -- hpdf_namedict.c + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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 "hpdf_conf.h" +#include "hpdf_utils.h" +#include "hpdf_consts.h" +#include "hpdf_namedict.h" + +#ifndef HPDF_UNUSED +#define HPDF_UNUSED(a) ((void)(a)) +#endif + +static const char * const HPDF_NAMEDICT_KEYS[] = { + "EmbeddedFiles" + }; + +HPDF_NameDict +HPDF_NameDict_New (HPDF_MMgr mmgr, + HPDF_Xref xref) +{ + HPDF_NameDict ndict; + + HPDF_PTRACE((" HPDF_NameDict_New\n")); + + ndict = HPDF_Dict_New (mmgr); + if (!ndict) + return NULL; + + if (HPDF_Xref_Add (xref, ndict) != HPDF_OK) + return NULL; + + ndict->header.obj_class |= HPDF_OSUBCLASS_NAMEDICT; + + return ndict; +} + +HPDF_NameTree +HPDF_NameDict_GetNameTree (HPDF_NameDict namedict, + HPDF_NameDictKey key) +{ + if (!namedict) + return NULL; + return HPDF_Dict_GetItem (namedict, HPDF_NAMEDICT_KEYS[key], HPDF_OCLASS_DICT); +} + +HPDF_STATUS +HPDF_NameDict_SetNameTree (HPDF_NameDict namedict, + HPDF_NameDictKey key, + HPDF_NameTree ntree) +{ + return HPDF_Dict_Add (namedict, HPDF_NAMEDICT_KEYS[key], ntree); +} + +HPDF_BOOL +HPDF_NameDict_Validate (HPDF_NameDict namedict) +{ + if (!namedict) + return HPDF_FALSE; + + if (namedict->header.obj_class != (HPDF_OSUBCLASS_NAMEDICT | + HPDF_OCLASS_DICT)) { + HPDF_SetError (namedict->error, HPDF_INVALID_OBJECT, 0); + return HPDF_FALSE; + } + + return HPDF_TRUE; +} + + +/*------- NameTree -------*/ + +HPDF_NameTree +HPDF_NameTree_New (HPDF_MMgr mmgr, + HPDF_Xref xref) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_NameTree ntree; + HPDF_Array items; + + HPDF_PTRACE((" HPDF_NameTree_New\n")); + + ntree = HPDF_Dict_New (mmgr); + if (!ntree) + return NULL; + + if (HPDF_Xref_Add (xref, ntree) != HPDF_OK) + return NULL; + + ntree->header.obj_class |= HPDF_OSUBCLASS_NAMETREE; + + items = HPDF_Array_New (mmgr); + if (!ntree) + return NULL; + + ret += HPDF_Dict_Add (ntree, "Names", items); + if (ret != HPDF_OK) + return NULL; + + return ntree; +} + +HPDF_STATUS +HPDF_NameTree_Add (HPDF_NameTree tree, + HPDF_String name, + void *obj) +{ + HPDF_Array items; + HPDF_INT32 i, icount; + + if (!tree || !name) + return HPDF_INVALID_PARAMETER; + + items = HPDF_Dict_GetItem (tree, "Names", HPDF_OCLASS_ARRAY); + if (!items) + return HPDF_INVALID_OBJECT; + + /* "The keys shall be sorted in lexical order" -- 7.9.6, Name Trees. + * Since we store keys sorted, it's best to do a linear insertion sort + * Find the first element larger than 'key', and insert 'key' and then + * 'obj' into the items. */ + + icount = HPDF_Array_Items(items); + + /* If we're larger than the last element, append */ + if (icount) { + HPDF_String last = HPDF_Array_GetItem(items, icount - 2, HPDF_OCLASS_STRING); + + if (HPDF_String_Cmp(name, last) > 0) { + HPDF_Array_Add(items, name); + HPDF_Array_Add(items, obj); + return HPDF_OK; + } + } + + /* Walk backwards through the list until we're smaller than an element= + * That's the element to insert in front of. */ + for (i = icount - 4; i >= 0; i -= 2) { + HPDF_String elem = HPDF_Array_GetItem(items, i, HPDF_OCLASS_STRING); + + if (i == 0 || HPDF_String_Cmp(name, elem) < 0) { + HPDF_Array_Insert(items, elem, name); + HPDF_Array_Insert(items, elem, obj); + return HPDF_OK; + } + } + + /* Items list is empty */ + HPDF_Array_Add(items, name); + HPDF_Array_Add(items, obj); + return HPDF_OK; +} + +HPDF_BOOL +HPDF_NameTree_Validate (HPDF_NameTree nametree) +{ + if (!nametree) + return HPDF_FALSE; + + if (nametree->header.obj_class != (HPDF_OSUBCLASS_NAMETREE | + HPDF_OCLASS_DICT)) { + HPDF_SetError (nametree->error, HPDF_INVALID_OBJECT, 0); + return HPDF_FALSE; + } + + return HPDF_TRUE; +} + + +/*------- EmbeddedFile -------*/ + +HPDF_EmbeddedFile +HPDF_EmbeddedFile_New (HPDF_MMgr mmgr, + HPDF_Xref xref, + const char *file) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_Dict ef; /* the dictionary for the embedded file: /Type /EF */ + HPDF_String name; /* the name of the file: /F (name) */ + HPDF_Dict eff; /* ef has an /EF <> key - this is it */ + HPDF_Dict filestream; /* the stream that /EF <> refers to */ + HPDF_Stream stream; + + ef = HPDF_Dict_New (mmgr); + if (!ef) + return NULL; + if (HPDF_Xref_Add (xref, ef) != HPDF_OK) + return NULL; + + filestream = HPDF_DictStream_New (mmgr, xref); + if (!filestream) + return NULL; + stream = HPDF_FileReader_New (mmgr, file); + if (!stream) + return NULL; + HPDF_Stream_Free(filestream->stream); + filestream->stream = stream; + filestream->filter = HPDF_STREAM_FILTER_FLATE_DECODE; + + eff = HPDF_Dict_New (mmgr); + if (!eff) + return NULL; + + name = HPDF_String_New (mmgr, file, NULL); + if (!name) + return NULL; + + ret += HPDF_Dict_AddName (ef, "Type", "F"); + ret += HPDF_Dict_Add (ef, "F", name); + ret += HPDF_Dict_Add (ef, "EF", eff); + ret += HPDF_Dict_Add (eff, "F", filestream); + + if (ret != HPDF_OK) + return NULL; + + return ef; +} + +HPDF_BOOL +HPDF_EmbeddedFile_Validate (HPDF_EmbeddedFile emfile) +{ + HPDF_UNUSED (emfile); + return HPDF_TRUE; +} diff --git a/PDF/src/hpdf_null.c b/PDF/src/hpdf_null.c index e088f4fd7..d9f5d29d4 100644 --- a/PDF/src/hpdf_null.c +++ b/PDF/src/hpdf_null.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_null.c + * << Haru Free PDF Library >> -- hpdf_null.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_number.c b/PDF/src/hpdf_number.c index 6f24aa320..ce8b3e17c 100644 --- a/PDF/src/hpdf_number.c +++ b/PDF/src/hpdf_number.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_number.c + * << Haru Free PDF Library >> -- hpdf_number.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_objects.c b/PDF/src/hpdf_objects.c index 094a24fe6..59b19588b 100644 --- a/PDF/src/hpdf_objects.c +++ b/PDF/src/hpdf_objects.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- HPDF_objects.c + * << Haru Free PDF Library >> -- hpdf_objects.c * - * Copyright (c) 1999-2004 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_outline.c b/PDF/src/hpdf_outline.c index 71857ef86..56ce5e38b 100644 --- a/PDF/src/hpdf_outline.c +++ b/PDF/src/hpdf_outline.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_outline.c + * << Haru Free PDF Library >> -- hpdf_outline.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -64,7 +67,7 @@ HPDF_OutlineRoot_New (HPDF_MMgr mmgr, open_flg->header.obj_id |= HPDF_OTYPE_HIDDEN; ret += HPDF_Dict_Add (outline, "_OPENED", open_flg); - ret += HPDF_Dict_AddName (outline, "Type", "Outline"); + ret += HPDF_Dict_AddName (outline, "Type", "Outlines"); if (ret != HPDF_OK) return NULL; @@ -114,7 +117,7 @@ HPDF_Outline_New (HPDF_MMgr mmgr, open_flg->header.obj_id |= HPDF_OTYPE_HIDDEN; ret += HPDF_Dict_Add (outline, "_OPENED", open_flg); - ret += HPDF_Dict_AddName (outline, "Type", "Outline"); + ret += HPDF_Dict_AddName (outline, "Type", "Outlines"); ret += AddChild (parent, outline); if (ret != HPDF_OK) @@ -232,7 +235,7 @@ BeforeWrite (HPDF_Dict obj) return HPDF_Dict_RemoveElement (obj, "Count"); if (!HPDF_Outline_GetOpened ((HPDF_Outline)obj)) - count *= -1; + count = count * -1; if (n) n->value = count; @@ -325,5 +328,3 @@ HPDF_Outline_SetOpened (HPDF_Outline outline, return HPDF_OK; } - - diff --git a/PDF/src/hpdf_page_label.c b/PDF/src/hpdf_page_label.c index 7df16a17e..125a4d8e9 100644 --- a/PDF/src/hpdf_page_label.c +++ b/PDF/src/hpdf_page_label.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_page_label.c + * << Haru Free PDF Library >> -- hpdf_page_label.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_page_operator.c b/PDF/src/hpdf_page_operator.c index cafe51c24..23f592077 100644 --- a/PDF/src/hpdf_page_operator.c +++ b/PDF/src/hpdf_page_operator.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_page_operator.c + * << Haru Free PDF Library >> -- hpdf_page_operator.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -10,7 +13,6 @@ * in supporting documentation. * It is provided "as is" without express or implied warranty. * - * 2006.07.29 modified */ #include "hpdf_conf.h" @@ -65,12 +67,10 @@ HPDF_Page_SetLineWidth (HPDF_Page page, if (line_width < 0) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0); - if ((ret = HPDF_Stream_WriteReal (attr->stream, - line_width)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, line_width) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, - " w\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " w\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->line_width = line_width; @@ -92,7 +92,7 @@ HPDF_Page_SetLineCap (HPDF_Page page, if (ret != HPDF_OK) return ret; - if (line_cap < 0 || line_cap >= HPDF_LINECAP_EOF) + if (line_cap >= HPDF_LINECAP_EOF) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, (HPDF_STATUS)line_cap); @@ -125,18 +125,16 @@ HPDF_Page_SetLineJoin (HPDF_Page page, if (ret != HPDF_OK) return ret; - if (line_join < 0 || line_join >= HPDF_LINEJOIN_EOF) + if (line_join >= HPDF_LINEJOIN_EOF) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, (HPDF_STATUS)line_join); attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteInt (attr->stream, - (HPDF_UINT)line_join)) != HPDF_OK) + if (HPDF_Stream_WriteInt (attr->stream, (HPDF_UINT)line_join) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, - " j\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " j\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->line_join = line_join; @@ -163,10 +161,10 @@ HPDF_Page_SetMiterLimit (HPDF_Page page, if (miter_limit < 1) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0); - if ((ret = HPDF_Stream_WriteReal (attr->stream, miter_limit)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, miter_limit) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " M\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " M\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->miter_limit = miter_limit; @@ -265,12 +263,10 @@ HPDF_Page_SetFlat (HPDF_Page page, if (flatness > 100 || flatness < 0) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0); - if ((ret = HPDF_Stream_WriteReal (attr->stream, - flatness)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, flatness) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, - " i\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " i\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->flatness = flatness; @@ -304,11 +300,10 @@ HPDF_Page_SetExtGState (HPDF_Page page, if (!local_name) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteEscapeName (attr->stream, local_name)) != - HPDF_OK) + if (HPDF_Stream_WriteEscapeName (attr->stream, local_name) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " gs\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " gs\012") != HPDF_OK) return HPDF_CheckError (page->error); /* change objct class to read only. */ @@ -339,7 +334,7 @@ HPDF_Page_GSave (HPDF_Page page) if (!new_gstate) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, "q\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "q\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate = new_gstate; @@ -370,7 +365,7 @@ HPDF_Page_GRestore (HPDF_Page page) attr->gstate = new_gstate; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "Q\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "Q\012") != HPDF_OK) return HPDF_CheckError (page->error); return ret; @@ -415,7 +410,7 @@ HPDF_Page_Concat (HPDF_Page page, pbuf = HPDF_FToA (pbuf, y, eptr); HPDF_StrCpy (pbuf, " cm\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); tm = attr->gstate->trans_matrix; @@ -459,7 +454,7 @@ HPDF_Page_MoveTo (HPDF_Page page, pbuf = HPDF_FToA (pbuf, y, eptr); HPDF_StrCpy (pbuf, " m\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->cur_pos.x = x; @@ -496,7 +491,7 @@ HPDF_Page_LineTo (HPDF_Page page, pbuf = HPDF_FToA (pbuf, y, eptr); HPDF_StrCpy (pbuf, " l\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->cur_pos.x = x; @@ -543,7 +538,7 @@ HPDF_Page_CurveTo (HPDF_Page page, pbuf = HPDF_FToA (pbuf, y3, eptr); HPDF_StrCpy (pbuf, " c\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->cur_pos.x = x3; @@ -584,7 +579,7 @@ HPDF_Page_CurveTo2 (HPDF_Page page, pbuf = HPDF_FToA (pbuf, y3, eptr); HPDF_StrCpy (pbuf, " v\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->cur_pos.x = x3; @@ -625,7 +620,7 @@ HPDF_Page_CurveTo3 (HPDF_Page page, pbuf = HPDF_FToA (pbuf, y3, eptr); HPDF_StrCpy (pbuf, " y\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->cur_pos.x = x3; @@ -648,7 +643,7 @@ HPDF_Page_ClosePath (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "h\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "h\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->cur_pos = attr->str_pos; @@ -689,7 +684,7 @@ HPDF_Page_Rectangle (HPDF_Page page, pbuf = HPDF_FToA (pbuf, height, eptr); HPDF_StrCpy (pbuf, " re\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->cur_pos.x = x; @@ -718,7 +713,7 @@ HPDF_Page_Stroke (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "S\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "S\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; @@ -742,7 +737,7 @@ HPDF_Page_ClosePathStroke (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "s\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "s\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; @@ -766,7 +761,7 @@ HPDF_Page_Fill (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "f\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "f\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; @@ -790,7 +785,7 @@ HPDF_Page_Eofill (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "f*\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "f*\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; @@ -814,7 +809,7 @@ HPDF_Page_FillStroke (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "B\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "B\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; @@ -838,7 +833,7 @@ HPDF_Page_EofillStroke (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "B*\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "B*\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; @@ -861,7 +856,7 @@ HPDF_Page_ClosePathFillStroke (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "b\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "b\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; @@ -885,7 +880,7 @@ HPDF_Page_ClosePathEofillStroke (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "b*\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "b*\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; @@ -909,7 +904,7 @@ HPDF_Page_EndPath (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "n\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "n\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_PAGE_DESCRIPTION; @@ -935,7 +930,7 @@ HPDF_Page_Clip (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "W\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "W\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_CLIPPING_PATH; @@ -957,7 +952,7 @@ HPDF_Page_Eoclip (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "W*\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "W*\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_CLIPPING_PATH; @@ -983,7 +978,7 @@ HPDF_Page_BeginText (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "BT\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "BT\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gmode = HPDF_GMODE_TEXT_OBJECT; @@ -1007,7 +1002,7 @@ HPDF_Page_EndText (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "ET\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "ET\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->text_pos = INIT_POS; @@ -1037,10 +1032,10 @@ HPDF_Page_SetCharSpace (HPDF_Page page, if (value < HPDF_MIN_CHARSPACE || value > HPDF_MAX_CHARSPACE) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0); - if ((ret = HPDF_Stream_WriteReal (attr->stream, value)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, value) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " Tc\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " Tc\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->char_space = value; @@ -1067,10 +1062,10 @@ HPDF_Page_SetWordSpace (HPDF_Page page, if (value < HPDF_MIN_WORDSPACE || value > HPDF_MAX_WORDSPACE) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0); - if ((ret = HPDF_Stream_WriteReal (attr->stream, value)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, value) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " Tw\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " Tw\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->word_space = value; @@ -1098,10 +1093,10 @@ HPDF_Page_SetHorizontalScalling (HPDF_Page page, value > HPDF_MAX_HORIZONTALSCALING) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0); - if ((ret = HPDF_Stream_WriteReal (attr->stream, value)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, value) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " Tz\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " Tz\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->h_scalling = value; @@ -1125,10 +1120,10 @@ HPDF_Page_SetTextLeading (HPDF_Page page, attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteReal (attr->stream, value)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, value) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " TL\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " TL\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->text_leading = value; @@ -1160,7 +1155,7 @@ HPDF_Page_SetFontAndSize (HPDF_Page page, return HPDF_RaiseError (page->error, HPDF_PAGE_INVALID_FONT, 0); if (size <= 0 || size > HPDF_MAX_FONTSIZE) - return HPDF_RaiseError (page->error, HPDF_PAGE_INVALID_FONT_SIZE, 0); + return HPDF_RaiseError (page->error, HPDF_PAGE_INVALID_FONT_SIZE, size); if (page->mmgr != font->mmgr) return HPDF_RaiseError (page->error, HPDF_PAGE_INVALID_FONT, 0); @@ -1171,8 +1166,7 @@ HPDF_Page_SetFontAndSize (HPDF_Page page, if (!local_name) return HPDF_RaiseError (page->error, HPDF_PAGE_INVALID_FONT, 0); - if ((ret = HPDF_Stream_WriteEscapeName (attr->stream, local_name)) != - HPDF_OK) + if (HPDF_Stream_WriteEscapeName (attr->stream, local_name) != HPDF_OK) return HPDF_CheckError (page->error); HPDF_MemSet (buf, 0, HPDF_TMP_BUF_SIZ); @@ -1180,7 +1174,7 @@ HPDF_Page_SetFontAndSize (HPDF_Page page, pbuf = HPDF_FToA (pbuf, size, eptr); HPDF_StrCpy (pbuf, " Tf\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->font = font; @@ -1204,16 +1198,16 @@ HPDF_Page_SetTextRenderingMode (HPDF_Page page, if (ret != HPDF_OK) return ret; - if (mode < 0 || mode >= HPDF_RENDERING_MODE_EOF) + if (mode >= HPDF_RENDERING_MODE_EOF) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, (HPDF_STATUS)mode); attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteInt (attr->stream, (HPDF_INT)mode)) != HPDF_OK) + if (HPDF_Stream_WriteInt (attr->stream, (HPDF_INT)mode) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " Tr\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " Tr\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->rendering_mode = mode; @@ -1245,10 +1239,10 @@ HPDF_Page_SetTextRise (HPDF_Page page, attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteReal (attr->stream, value)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, value) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " Ts\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " Ts\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->text_rise = value; @@ -1285,7 +1279,7 @@ HPDF_Page_MoveTextPos (HPDF_Page page, pbuf = HPDF_FToA (pbuf, y, eptr); HPDF_StrCpy (pbuf, " Td\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->text_matrix.x += x * attr->text_matrix.a + y * attr->text_matrix.c; @@ -1322,7 +1316,7 @@ HPDF_Page_MoveTextPos2 (HPDF_Page page, pbuf = HPDF_FToA (pbuf, y, eptr); HPDF_StrCpy (pbuf, " TD\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->text_matrix.x += x * attr->text_matrix.a + y * attr->text_matrix.c; @@ -1375,7 +1369,7 @@ HPDF_Page_SetTextMatrix (HPDF_Page page, pbuf = HPDF_FToA (pbuf, y, eptr); HPDF_StrCpy (pbuf, " Tm\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->text_matrix.a = a; @@ -1405,7 +1399,7 @@ HPDF_Page_MoveToNextLine (HPDF_Page page) attr = (HPDF_PageAttr)page->attr; - if ((ret = HPDF_Stream_WriteStr (attr->stream, "T*\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, "T*\012") != HPDF_OK) return HPDF_CheckError (page->error); /* calculate the reference point of text */ @@ -1444,10 +1438,10 @@ HPDF_Page_ShowText (HPDF_Page page, if (!tw) return ret; - if ((ret = InternalWriteText (attr, text)) != HPDF_OK) + if (InternalWriteText (attr, text) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " Tj\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " Tj\012") != HPDF_OK) return HPDF_CheckError (page->error); /* calculate the reference point of text */ @@ -1486,10 +1480,10 @@ HPDF_Page_ShowTextNextLine (HPDF_Page page, if (text == NULL || text[0] == 0) return HPDF_Page_MoveToNextLine(page); - if ((ret = InternalWriteText (attr, text)) != HPDF_OK) + if (InternalWriteText (attr, text) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " \'\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " \'\012") != HPDF_OK) return HPDF_CheckError (page->error); tw = HPDF_Page_TextWidth (page, text); @@ -1552,13 +1546,13 @@ HPDF_Page_ShowTextNextLineEx (HPDF_Page page, pbuf = HPDF_FToA (pbuf, char_space, eptr); *pbuf = ' '; - if ((ret = InternalWriteText (attr, buf)) != HPDF_OK) + if (InternalWriteText (attr, buf) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = InternalWriteText (attr, text)) != HPDF_OK) + if (InternalWriteText (attr, text) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " \"\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " \"\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->word_space = word_space; @@ -1614,10 +1608,10 @@ HPDF_Page_SetGrayFill (HPDF_Page page, if (gray < 0 || gray > 1) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0); - if ((ret = HPDF_Stream_WriteReal (attr->stream, gray)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, gray) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " g\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " g\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->gray_fill = gray; @@ -1645,10 +1639,10 @@ HPDF_Page_SetGrayStroke (HPDF_Page page, if (gray < 0 || gray > 1) return HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0); - if ((ret = HPDF_Stream_WriteReal (attr->stream, gray)) != HPDF_OK) + if (HPDF_Stream_WriteReal (attr->stream, gray) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " G\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " G\012") != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->gray_stroke = gray; @@ -1690,7 +1684,7 @@ HPDF_Page_SetRGBFill (HPDF_Page page, pbuf = HPDF_FToA (pbuf, b, eptr); HPDF_StrCpy (pbuf, " rg\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->rgb_fill.r = r; @@ -1734,7 +1728,7 @@ HPDF_Page_SetRGBStroke (HPDF_Page page, pbuf = HPDF_FToA (pbuf, b, eptr); HPDF_StrCpy (pbuf, " RG\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->rgb_stroke.r = r; @@ -1781,7 +1775,7 @@ HPDF_Page_SetCMYKFill (HPDF_Page page, pbuf = HPDF_FToA (pbuf, k, eptr); HPDF_StrCpy (pbuf, " k\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->cmyk_fill.c = c; @@ -1829,7 +1823,7 @@ HPDF_Page_SetCMYKStroke (HPDF_Page page, pbuf = HPDF_FToA (pbuf, k, eptr); HPDF_StrCpy (pbuf, " K\012", eptr); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->gstate->cmyk_stroke.c = c; @@ -1880,11 +1874,10 @@ HPDF_Page_ExecuteXObject (HPDF_Page page, if (!local_name) return HPDF_RaiseError (page->error, HPDF_PAGE_INVALID_XOBJECT, 0); - if ((ret = HPDF_Stream_WriteEscapeName (attr->stream, local_name)) != - HPDF_OK) + if (HPDF_Stream_WriteEscapeName (attr->stream, local_name) != HPDF_OK) return HPDF_CheckError (page->error); - if ((ret = HPDF_Stream_WriteStr (attr->stream, " Do\012")) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, " Do\012") != HPDF_OK) return HPDF_CheckError (page->error); return ret; @@ -1926,7 +1919,7 @@ QuarterCircleA (char *pbuf, pbuf = HPDF_FToA (pbuf, x, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y + ray, eptr); - return HPDF_StrCpy (pbuf, " c\012", eptr); + return (char *)HPDF_StrCpy (pbuf, " c\012", eptr); } static char* @@ -1947,7 +1940,7 @@ QuarterCircleB (char *pbuf, pbuf = HPDF_FToA (pbuf, x + ray, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y, eptr); - return HPDF_StrCpy (pbuf, " c\012", eptr); + return (char *)HPDF_StrCpy (pbuf, " c\012", eptr); } static char* @@ -1968,7 +1961,7 @@ QuarterCircleC (char *pbuf, pbuf = HPDF_FToA (pbuf, x, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y - ray, eptr); - return HPDF_StrCpy (pbuf, " c\012", eptr); + return (char *)HPDF_StrCpy (pbuf, " c\012", eptr); } static char* @@ -1989,7 +1982,7 @@ QuarterCircleD (char *pbuf, pbuf = HPDF_FToA (pbuf, x - ray, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y, eptr); - return HPDF_StrCpy (pbuf, " c\012", eptr); + return (char *)HPDF_StrCpy (pbuf, " c\012", eptr); } HPDF_EXPORT(HPDF_STATUS) @@ -2017,14 +2010,14 @@ HPDF_Page_Circle (HPDF_Page page, pbuf = HPDF_FToA (pbuf, x - ray, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y, eptr); - pbuf = HPDF_StrCpy (pbuf, " m\012", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, " m\012", eptr); pbuf = QuarterCircleA (pbuf, eptr, x, y, ray); pbuf = QuarterCircleB (pbuf, eptr, x, y, ray); pbuf = QuarterCircleC (pbuf, eptr, x, y, ray); QuarterCircleD (pbuf, eptr, x, y, ray); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->cur_pos.x = x - ray; @@ -2055,7 +2048,7 @@ QuarterEllipseA (char *pbuf, pbuf = HPDF_FToA (pbuf, x, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y + yray, eptr); - return HPDF_StrCpy (pbuf, " c\012", eptr); + return (char *)HPDF_StrCpy (pbuf, " c\012", eptr); } static char* @@ -2077,7 +2070,7 @@ QuarterEllipseB (char *pbuf, pbuf = HPDF_FToA (pbuf, x + xray, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y, eptr); - return HPDF_StrCpy (pbuf, " c\012", eptr); + return (char *)HPDF_StrCpy (pbuf, " c\012", eptr); } static char* @@ -2099,7 +2092,7 @@ QuarterEllipseC (char *pbuf, pbuf = HPDF_FToA (pbuf, x, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y - yray, eptr); - return HPDF_StrCpy (pbuf, " c\012", eptr); + return (char *)HPDF_StrCpy (pbuf, " c\012", eptr); } static char* @@ -2121,7 +2114,7 @@ QuarterEllipseD (char *pbuf, pbuf = HPDF_FToA (pbuf, x - xray, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y, eptr); - return HPDF_StrCpy (pbuf, " c\012", eptr); + return (char *)HPDF_StrCpy (pbuf, " c\012", eptr); } HPDF_EXPORT(HPDF_STATUS) @@ -2150,14 +2143,14 @@ HPDF_Page_Ellipse (HPDF_Page page, pbuf = HPDF_FToA (pbuf, x - xray, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, y, eptr); - pbuf = HPDF_StrCpy (pbuf, " m\012", eptr); + pbuf = (char *)HPDF_StrCpy (pbuf, " m\012", eptr); pbuf = QuarterEllipseA (pbuf, eptr, x, y, xray, yray); pbuf = QuarterEllipseB (pbuf, eptr, x, y, xray, yray); pbuf = QuarterEllipseC (pbuf, eptr, x, y, xray, yray); QuarterEllipseD (pbuf, eptr, x, y, xray, yray); - if ((ret = HPDF_Stream_WriteStr (attr->stream, buf)) != HPDF_OK) + if (HPDF_Stream_WriteStr (attr->stream, buf) != HPDF_OK) return HPDF_CheckError (page->error); attr->cur_pos.x = x - xray; @@ -2190,7 +2183,7 @@ HPDF_Page_Arc (HPDF_Page page, HPDF_PTRACE ((" HPDF_Page_Arc\n")); - if (ang1 >= ang2 || (ang2 - ang1) >= 360) + if (fabs(ang2 - ang1) >= 360) HPDF_RaiseError (page->error, HPDF_PAGE_OUT_OF_RANGE, 0); if (ret != HPDF_OK) @@ -2203,10 +2196,10 @@ HPDF_Page_Arc (HPDF_Page page, for (;;) { - if (ang2 - ang1 <= 90) + if (fabs(ang2 - ang1) <= 90) return InternalArc (page, x, y, ray, ang1, ang2, cont_flg); else { - HPDF_REAL tmp_ang = ang1 + 90; + HPDF_REAL tmp_ang = (ang2 > ang1 ? ang1 + 90 : ang1 - 90); if ((ret = InternalArc (page, x, y, ray, ang1, tmp_ang, cont_flg)) != HPDF_OK) @@ -2215,7 +2208,7 @@ HPDF_Page_Arc (HPDF_Page page, ang1 = tmp_ang; } - if (ang1 >= ang2) + if (fabs(ang1 - ang2) < 0.1) break; cont_flg = HPDF_TRUE; @@ -2278,7 +2271,11 @@ InternalArc (HPDF_Page page, pbuf = HPDF_FToA (pbuf, (HPDF_REAL)x0, eptr); *pbuf++ = ' '; pbuf = HPDF_FToA (pbuf, (HPDF_REAL)y0, eptr); - pbuf = HPDF_StrCpy (pbuf, " m\012", eptr); + + if (attr->gmode == HPDF_GMODE_PATH_OBJECT) + pbuf = (char *)HPDF_StrCpy (pbuf, " l\012", eptr); + else + pbuf = (char *)HPDF_StrCpy (pbuf, " m\012", eptr); } pbuf = HPDF_FToA (pbuf, (HPDF_REAL)x1, eptr); @@ -2340,13 +2337,34 @@ InternalWriteText (HPDF_PageAttr attr, if (font_attr->type == HPDF_FONT_TYPE0_TT || font_attr->type == HPDF_FONT_TYPE0_CID) { + HPDF_Encoder encoder; + HPDF_UINT len; + if ((ret = HPDF_Stream_WriteStr (attr->stream, "<")) != HPDF_OK) return ret; - if ((ret = HPDF_Stream_WriteBinary (attr->stream, text, - HPDF_StrLen (text, HPDF_LIMIT_MAX_STRING_LEN), NULL)) - != HPDF_OK) - return ret; + encoder = font_attr->encoder; + len = HPDF_StrLen (text, HPDF_LIMIT_MAX_STRING_LEN); + + if (encoder->encode_text_fn == NULL) { + if ((ret = HPDF_Stream_WriteBinary (attr->stream, (HPDF_BYTE *)text, + len, NULL)) + != HPDF_OK) + return ret; + } else { + char *encoded; + HPDF_UINT length; + + encoded = (encoder->encode_text_fn)(encoder, text, len, &length); + + ret = HPDF_Stream_WriteBinary (attr->stream, (HPDF_BYTE *)encoded, + length, NULL); + + free(encoded); + + if (ret != HPDF_OK) + return ret; + } return HPDF_Stream_WriteStr (attr->stream, ">"); } @@ -2355,6 +2373,33 @@ InternalWriteText (HPDF_PageAttr attr, } +/* + * Convert a user space text position from absolute to relative coordinates. + * Absolute values are passed in xAbs and yAbs, relative values are returned + * to xRel and yRel. The latter two must not be NULL. + */ +static void +TextPos_AbsToRel (HPDF_TransMatrix text_matrix, + HPDF_REAL xAbs, + HPDF_REAL yAbs, + HPDF_REAL *xRel, + HPDF_REAL *yRel) +{ + if (text_matrix.a == 0) { + *xRel = (yAbs - text_matrix.y - (xAbs - text_matrix.x) * + text_matrix.d / text_matrix.c) / text_matrix.b; + *yRel = (xAbs - text_matrix.x) / text_matrix.c; + } else { + HPDF_REAL y = (yAbs - text_matrix.y - (xAbs - text_matrix.x) * + text_matrix.b / text_matrix.a) / (text_matrix.d - + text_matrix.c * text_matrix.b / text_matrix.a); + *xRel = (xAbs - text_matrix.x - y * text_matrix.c) / + text_matrix.a; + *yRel = y; + } +} + + HPDF_EXPORT(HPDF_STATUS) HPDF_Page_TextOut (HPDF_Page page, HPDF_REAL xpos, @@ -2372,18 +2417,7 @@ HPDF_Page_TextOut (HPDF_Page page, return ret; attr = (HPDF_PageAttr)page->attr; - - if (attr->text_matrix.a == 0) { - y = (xpos - attr->text_matrix.x) / attr->text_matrix.c; - x = (ypos - attr->text_matrix.y - (xpos - attr->text_matrix.x) * attr->text_matrix.d / attr->text_matrix.c) / attr->text_matrix.b; - } else { - y = (ypos - attr->text_matrix.y - (xpos - attr->text_matrix.x) * - attr->text_matrix.b / attr->text_matrix.a) / (attr->text_matrix.d - - attr->text_matrix.c * attr->text_matrix.b / attr->text_matrix.a); - x = (xpos - attr->text_matrix.x - y * attr->text_matrix.c) / - attr->text_matrix.a; - } - + TextPos_AbsToRel (attr->text_matrix, xpos, ypos, &x, &y); if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK) return ret; @@ -2403,17 +2437,16 @@ HPDF_Page_TextRect (HPDF_Page page, ) { HPDF_STATUS ret = HPDF_Page_CheckState (page, HPDF_GMODE_TEXT_OBJECT); - HPDF_REAL x; - HPDF_REAL y; HPDF_PageAttr attr; const char *ptr = text; + HPDF_BOOL pos_initialized = HPDF_FALSE; HPDF_REAL save_char_space = 0; HPDF_BOOL is_insufficient_space = HPDF_FALSE; HPDF_UINT num_rest; HPDF_Box bbox; HPDF_BOOL char_space_changed = HPDF_FALSE; - HPDF_PTRACE ((" HPDF_Page_TextOutEx\n")); + HPDF_PTRACE ((" HPDF_Page_TextRect\n")); if (ret != HPDF_OK) return ret; @@ -2444,120 +2477,112 @@ HPDF_Page_TextRect (HPDF_Page page, attr->gstate->text_leading; bottom = bottom - bbox.bottom / 1000 * attr->gstate->font_size; - if (attr->text_matrix.a == 0) { - y = (left - attr->text_matrix.x) / attr->text_matrix.c; - x = (top - attr->text_matrix.y - (left - attr->text_matrix.x) * attr->text_matrix.d / attr->text_matrix.c) / attr->text_matrix.b; - } else { - y = (top - attr->text_matrix.y - (left - attr->text_matrix.x) * - attr->text_matrix.b / attr->text_matrix.a) / (attr->text_matrix.d - - attr->text_matrix.c * attr->text_matrix.b / attr->text_matrix.a); - x = (left - attr->text_matrix.x - y * attr->text_matrix.c) / - attr->text_matrix.a; - } - - if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK) - return ret; - if (align == HPDF_TALIGN_JUSTIFY) { save_char_space = attr->gstate->char_space; attr->gstate->char_space = 0; } for (;;) { - HPDF_UINT tmp_len; + HPDF_REAL x, y; + HPDF_UINT line_len, tmp_len; HPDF_REAL rw; - HPDF_REAL x_adjust; - const char *tmp_ptr; - HPDF_UINT num_char; - HPDF_ParseText_Rec state; - HPDF_Encoder encoder; - HPDF_UINT i; + HPDF_BOOL LineBreak; - tmp_len = HPDF_Page_MeasureText (page, ptr, right - left, HPDF_TRUE, &rw); - if (tmp_len == 0) { + attr->gstate->char_space = 0; + line_len = tmp_len = HPDF_Page_MeasureText (page, ptr, right - left, HPDF_TRUE, &rw); + if (line_len == 0) { is_insufficient_space = HPDF_TRUE; break; } if (len) - *len += tmp_len; + *len += line_len; + num_rest -= line_len; + + /* Shorten tmp_len by trailing whitespace and control characters. */ + LineBreak = HPDF_FALSE; + while (tmp_len > 0 && HPDF_IS_WHITE_SPACE(ptr[tmp_len - 1])) { + tmp_len--; + if (ptr[tmp_len] == 0x0A || ptr[tmp_len] == 0x0D) { + LineBreak = HPDF_TRUE; + } + } switch (align) { + case HPDF_TALIGN_RIGHT: - x_adjust = right - left - rw; - if ((ret = HPDF_Page_MoveTextPos (page, x_adjust, 0)) != HPDF_OK) - return ret; - - if ((ret = InternalShowTextNextLine (page, ptr, tmp_len)) - != HPDF_OK) - return HPDF_CheckError (page->error); - - if ((ret = HPDF_Page_MoveTextPos (page, -x_adjust, 0)) != HPDF_OK) + TextPos_AbsToRel (attr->text_matrix, right - rw, top, &x, &y); + if (!pos_initialized) { + pos_initialized = HPDF_TRUE; + } else { + y = 0; + } + if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK) return ret; break; + case HPDF_TALIGN_CENTER: - x_adjust = (right - left - rw) / 2; - if ((ret = HPDF_Page_MoveTextPos (page, x_adjust, 0)) != HPDF_OK) - return ret; - - if ((ret = InternalShowTextNextLine (page, ptr, tmp_len)) - != HPDF_OK) - return HPDF_CheckError (page->error); - - if ((ret = HPDF_Page_MoveTextPos (page, -x_adjust, 0)) != HPDF_OK) + TextPos_AbsToRel (attr->text_matrix, left + (right - left - rw) / 2, top, &x, &y); + if (!pos_initialized) { + pos_initialized = HPDF_TRUE; + } else { + y = 0; + } + if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK) return ret; break; + case HPDF_TALIGN_JUSTIFY: - num_char = 0; - encoder = ((HPDF_FontAttr)attr->gstate->font->attr)->encoder; - tmp_ptr = ptr; - HPDF_Encoder_SetParseText (encoder, &state, tmp_ptr, tmp_len); - i = 0; - while (*tmp_ptr) { - HPDF_ByteType btype = HPDF_Encoder_ByteType (encoder, &state); - if (btype != HPDF_BYTE_TYPE_TRIAL) - num_char++; - - i++; - if (i >= tmp_len) - break; - - tmp_ptr++; + if (!pos_initialized) { + pos_initialized = HPDF_TRUE; + TextPos_AbsToRel (attr->text_matrix, left, top, &x, &y); + if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK) + return ret; } - if (HPDF_IS_WHITE_SPACE(*tmp_ptr)) - num_char--; - - if (num_char > 1) - x_adjust = (right - left - rw) / (num_char - 1); - else - x_adjust = 0; - - if (num_rest == tmp_len) { + /* Do not justify last line of paragraph or text. */ + if (LineBreak || num_rest <= 0) { if ((ret = HPDF_Page_SetCharSpace (page, save_char_space)) != HPDF_OK) return ret; char_space_changed = HPDF_FALSE; } else { - if ((ret = HPDF_Page_SetCharSpace (page, x_adjust)) - != HPDF_OK) + HPDF_REAL x_adjust; + HPDF_ParseText_Rec state; + HPDF_UINT i = 0; + HPDF_UINT num_char = 0; + HPDF_Encoder encoder = ((HPDF_FontAttr)attr->gstate->font->attr)->encoder; + const char *tmp_ptr = ptr; + HPDF_Encoder_SetParseText (encoder, &state, (HPDF_BYTE *)tmp_ptr, tmp_len); + while (*tmp_ptr) { + HPDF_ByteType btype = HPDF_Encoder_ByteType (encoder, &state); + if (btype != HPDF_BYTE_TYPE_TRIAL) + num_char++; + i++; + if (i >= tmp_len) + break; + tmp_ptr++; + } + + x_adjust = num_char == 0 ? 0 : (right - left - rw) / (num_char - 1); + if ((ret = HPDF_Page_SetCharSpace (page, x_adjust)) != HPDF_OK) return ret; char_space_changed = HPDF_TRUE; } - - if ((ret = InternalShowTextNextLine (page, ptr, tmp_len)) - != HPDF_OK) - return HPDF_CheckError (page->error); - - attr->gstate->char_space = 0; break; + default: - if ((ret = InternalShowTextNextLine (page, ptr, tmp_len)) - != HPDF_OK) - return HPDF_CheckError (page->error); + if (!pos_initialized) { + pos_initialized = HPDF_TRUE; + TextPos_AbsToRel (attr->text_matrix, left, top, &x, &y); + if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK) + return ret; + } } - num_rest -= tmp_len; + if (InternalShowTextNextLine (page, ptr, tmp_len) != HPDF_OK) + return HPDF_CheckError (page->error); + if (num_rest <= 0) break; @@ -2566,10 +2591,10 @@ HPDF_Page_TextRect (HPDF_Page page, break; } - ptr += tmp_len; + ptr += line_len; } - if (char_space_changed) { + if (char_space_changed && save_char_space != attr->gstate->char_space) { if ((ret = HPDF_Page_SetCharSpace (page, save_char_space)) != HPDF_OK) return ret; } @@ -2598,12 +2623,28 @@ InternalShowTextNextLine (HPDF_Page page, if (font_attr->type == HPDF_FONT_TYPE0_TT || font_attr->type == HPDF_FONT_TYPE0_CID) { + HPDF_Encoder encoder = font_attr->encoder; + if ((ret = HPDF_Stream_WriteStr (attr->stream, "<")) != HPDF_OK) return ret; - if ((ret = HPDF_Stream_WriteBinary (attr->stream, text, len, NULL)) - != HPDF_OK) - return ret; + if (encoder->encode_text_fn == NULL) { + if ((ret = HPDF_Stream_WriteBinary (attr->stream, (HPDF_BYTE *)text, + len, NULL)) + != HPDF_OK) + return ret; + } else { + char *encoded; + HPDF_UINT length; + + encoded = (encoder->encode_text_fn)(encoder, text, len, &length); + ret = HPDF_Stream_WriteBinary (attr->stream, (HPDF_BYTE *)encoded, + length, NULL); + free(encoded); + + if (ret != HPDF_OK) + return ret; + } if ((ret = HPDF_Stream_WriteStr (attr->stream, ">")) != HPDF_OK) return ret; @@ -2665,11 +2706,10 @@ HPDF_Page_SetSlideShow (HPDF_Page page, if (!dict) return HPDF_Error_GetCode (page->error); - if ((ret = HPDF_Dict_AddName (dict, "Type", "Trans")) != HPDF_OK) + if (HPDF_Dict_AddName (dict, "Type", "Trans") != HPDF_OK) goto Fail; - if ((ret = HPDF_Dict_AddReal (dict, "D", trans_time)) != - HPDF_OK) + if (HPDF_Dict_AddReal (dict, "D", trans_time) != HPDF_OK) goto Fail; switch (type) { @@ -2744,13 +2784,13 @@ HPDF_Page_SetSlideShow (HPDF_Page page, ret += HPDF_Dict_AddName (dict, "S", "R"); break; default: - ret = HPDF_INVALID_PAGE_SLIDESHOW_TYPE; + ret += HPDF_SetError(page->error, HPDF_INVALID_PAGE_SLIDESHOW_TYPE, 0); } if (ret != HPDF_OK) goto Fail; - if ((ret = HPDF_Dict_AddReal (page, "Dur", disp_time)) != HPDF_OK) + if (HPDF_Dict_AddReal (page, "Dur", disp_time) != HPDF_OK) goto Fail; if ((ret = HPDF_Dict_Add (page, "Trans", dict)) != HPDF_OK) @@ -2762,3 +2802,100 @@ Fail: HPDF_Dict_Free (dict); return HPDF_Error_GetCode (page->error); } + + +/* + * This function is contributed by Finn Arildsen. + */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Page_New_Content_Stream (HPDF_Page page, + HPDF_Dict* new_stream) +{ + /* Call this function to start a new content stream on a page. The + handle is returned to new_stream. + new_stream can later be used on other pages as a shared content stream; + insert using HPDF_Page_Insert_Shared_Content_Stream */ + + HPDF_STATUS ret = HPDF_Page_CheckState (page, HPDF_GMODE_PAGE_DESCRIPTION | + HPDF_GMODE_TEXT_OBJECT); + HPDF_PageAttr attr; + HPDF_UINT filter; + HPDF_Array contents_array; + + HPDF_PTRACE((" HPDF_Page_New_Content_Stream\n")); + + attr = (HPDF_PageAttr)page->attr; + filter = attr->contents->filter; + + /* check if there is already an array of contents */ + contents_array = (HPDF_Array) HPDF_Dict_GetItem(page,"Contents", HPDF_OCLASS_ARRAY); + if (!contents_array) { + HPDF_Error_Reset (page->error); + /* no contents_array already -- create one + and replace current single contents item */ + contents_array = HPDF_Array_New(page->mmgr); + if (!contents_array) + return HPDF_Error_GetCode (page->error); + ret += HPDF_Array_Add(contents_array,attr->contents); + ret += HPDF_Dict_Add (page, "Contents", contents_array); + } + + /* create new contents stream and add it to the page's contents array */ + attr->contents = HPDF_DictStream_New (page->mmgr, attr->xref); + attr->contents->filter = filter; + attr->stream = attr->contents->stream; + + if (!attr->contents) + return HPDF_Error_GetCode (page->error); + + ret += HPDF_Array_Add (contents_array,attr->contents); + + /* return the value of the new stream, so that + the application can use it as a shared contents stream */ + if (ret == HPDF_OK && new_stream != NULL) + *new_stream = attr->contents; + + return ret; +} + + +/* + * This function is contributed by Finn Arildsen. + */ + +HPDF_EXPORT(HPDF_STATUS) +HPDF_Page_Insert_Shared_Content_Stream (HPDF_Page page, + HPDF_Dict shared_stream) +{ + /* Call this function to insert a previously (with HPDF_New_Content_Stream) created content stream + as a shared content stream on this page */ + + HPDF_STATUS ret = HPDF_Page_CheckState (page, HPDF_GMODE_PAGE_DESCRIPTION | + HPDF_GMODE_TEXT_OBJECT); + HPDF_Array contents_array; + + HPDF_PTRACE((" HPDF_Page_Insert_Shared_Content_Stream\n")); + + /* check if there is already an array of contents */ + contents_array = (HPDF_Array) HPDF_Dict_GetItem(page,"Contents", HPDF_OCLASS_ARRAY); + if (!contents_array) { + HPDF_PageAttr attr; + HPDF_Error_Reset (page->error); + /* no contents_array already -- create one + and replace current single contents item */ + contents_array = HPDF_Array_New(page->mmgr); + if (!contents_array) + return HPDF_Error_GetCode (page->error); + attr = (HPDF_PageAttr)page->attr; + ret += HPDF_Array_Add(contents_array,attr->contents); + ret += HPDF_Dict_Add (page, "Contents", contents_array); + } + + ret += HPDF_Array_Add (contents_array,shared_stream); + + /* Continue with a new stream */ + ret += HPDF_Page_New_Content_Stream (page, NULL); + + return ret; +} diff --git a/PDF/src/hpdf_pages.c b/PDF/src/hpdf_pages.c index 885008c1a..fcc9b5cc4 100644 --- a/PDF/src/hpdf_pages.c +++ b/PDF/src/hpdf_pages.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_pages.c + * << Haru Free PDF Library >> -- hpdf_pages.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -17,6 +20,9 @@ #include "hpdf.h" #include "hpdf_annotation.h" #include "hpdf_destination.h" +#include "hpdf_3dmeasure.h" +#include "hpdf_exdata.h" +#include "hpdf_u3d.h" /*----------------------------------------------------------------------------*/ @@ -25,14 +31,14 @@ typedef struct _HPDF_PageSizeValue { HPDF_REAL y; } HPDF_PageSizeValue; -static HPDF_PageSizeValue HPDF_PREDEFINED_PAGE_SIZES[] = { +static const HPDF_PageSizeValue HPDF_PREDEFINED_PAGE_SIZES[] = { {612, 792}, /* HPDF_PAGE_SIZE_LETTER */ {612, 1008}, /* HPDF_PAGE_SIZE_LEGAL */ - {841.89, 1199.551}, /* HPDF_PAGE_SIZE_A3 */ - {595.276, 841.89}, /* HPDF_PAGE_SIZE_A4 */ - {419.528, 595.276}, /* HPDF_PAGE_SIZE_A5 */ - {708.661, 1000.63}, /* HPDF_PAGE_SIZE_B4 */ - {498.898, 708.661}, /* HPDF_PAGE_SIZE_B5 */ + {(HPDF_REAL)841.89, (HPDF_REAL)1190.551}, /* HPDF_PAGE_SIZE_A3 */ + {(HPDF_REAL)595.276, (HPDF_REAL)841.89}, /* HPDF_PAGE_SIZE_A4 */ + {(HPDF_REAL)419.528, (HPDF_REAL)595.276}, /* HPDF_PAGE_SIZE_A5 */ + {(HPDF_REAL)708.661, (HPDF_REAL)1000.63}, /* HPDF_PAGE_SIZE_B4 */ + {(HPDF_REAL)498.898, (HPDF_REAL)708.661}, /* HPDF_PAGE_SIZE_B5 */ {522, 756}, /* HPDF_PAGE_SIZE_EXECUTIVE */ {288, 432}, /* HPDF_PAGE_SIZE_US4x6 */ {288, 576}, /* HPDF_PAGE_SIZE_US4x8 */ @@ -71,7 +77,7 @@ AddAnnotation (HPDF_Page page, static HPDF_UINT GetPageCount (HPDF_Dict pages); -static const char *HPDF_INHERITABLE_ENTRIES[5] = { +static const char * const HPDF_INHERITABLE_ENTRIES[5] = { "Resources", "MediaBox", "CropBox", @@ -159,11 +165,14 @@ HPDF_Page_InsertBefore (HPDF_Page page, HPDF_PTRACE((" HPDF_Page_InsertBefore\n")); + if (!target) + return HPDF_INVALID_PARAMETER; + attr = (HPDF_PageAttr )target->attr; parent = attr->parent; if (!parent) - return HPDF_SetError (parent->error, HPDF_PAGE_CANNOT_SET_PARENT, 0); + return HPDF_PAGE_CANNOT_SET_PARENT; if (HPDF_Dict_GetItem (page, "Parent", HPDF_OCLASS_DICT)) return HPDF_SetError (parent->error, HPDF_PAGE_CANNOT_SET_PARENT, 0); @@ -337,7 +346,7 @@ HPDF_Page_New (HPDF_MMgr mmgr, /* add requiered elements */ ret += HPDF_Dict_AddName (page, "Type", "Page"); ret += HPDF_Dict_Add (page, "MediaBox", HPDF_Box_Array_New (page->mmgr, - HPDF_ToBox (0, 0, HPDF_DEF_PAGE_WIDTH, HPDF_DEF_PAGE_HEIGHT))); + HPDF_ToBox (0, 0, (HPDF_INT16)(HPDF_DEF_PAGE_WIDTH), (HPDF_INT16)(HPDF_DEF_PAGE_HEIGHT)))); ret += HPDF_Dict_Add (page, "Contents", attr->contents); ret += AddResource (page); @@ -454,14 +463,19 @@ AddResource (HPDF_Page page) if (!procset) return HPDF_Error_GetCode (page->error); - ret += HPDF_Dict_Add (resource, "ProcSet", procset); + if (HPDF_Dict_Add (resource, "ProcSet", procset) != HPDF_OK) + return HPDF_Error_GetCode (resource->error); + ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "PDF")); ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "Text")); ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "ImageB")); ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "ImageC")); ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "ImageI")); - return ret; + if (ret != HPDF_OK) + return HPDF_Error_GetCode (procset->error); + + return HPDF_OK; } @@ -507,7 +521,7 @@ HPDF_Page_GetLocalFontName (HPDF_Page page, char *ptr; char *end_ptr = fontName + HPDF_LIMIT_MAX_NAME_LEN; - ptr = HPDF_StrCpy (fontName, "F", end_ptr); + ptr = (char *)HPDF_StrCpy (fontName, "F", end_ptr); HPDF_IToA (ptr, attr->fonts->list->count + 1, end_ptr); if (HPDF_Dict_Add (attr->fonts, fontName, font) != HPDF_OK) @@ -596,7 +610,7 @@ HPDF_Page_GetXObjectName (HPDF_Page page, char *ptr; char *end_ptr = xobj_name + HPDF_LIMIT_MAX_NAME_LEN; - ptr = HPDF_StrCpy (xobj_name, "X", end_ptr); + ptr = (char *)HPDF_StrCpy (xobj_name, "X", end_ptr); HPDF_IToA (ptr, attr->xobjects->list->count + 1, end_ptr); if (HPDF_Dict_Add (attr->xobjects, xobj_name, xobj) != HPDF_OK) @@ -647,7 +661,7 @@ HPDF_Page_GetExtGStateName (HPDF_Page page, char *ptr; char *end_ptr = ext_gstate_name + HPDF_LIMIT_MAX_NAME_LEN; - ptr = HPDF_StrCpy (ext_gstate_name, "E", end_ptr); + ptr = (char *)HPDF_StrCpy (ext_gstate_name, "E", end_ptr); HPDF_IToA (ptr, attr->ext_gstates->list->count + 1, end_ptr); if (HPDF_Dict_Add (attr->ext_gstates, ext_gstate_name, state) != HPDF_OK) @@ -665,7 +679,7 @@ AddAnnotation (HPDF_Page page, HPDF_Annotation annot) { HPDF_Array array; - HPDF_STATUS ret; + HPDF_STATUS ret = HPDF_OK; HPDF_PTRACE((" HPDF_Pages\n")); @@ -681,8 +695,14 @@ AddAnnotation (HPDF_Page page, if (ret != HPDF_OK) return ret; } + + if ((ret = HPDF_Array_Add (array, annot)) != HPDF_OK) + return ret; - return HPDF_Array_Add (array, annot); + /* Add Parent to the annotation */ + ret = HPDF_Dict_Add( annot, "P", page); + + return ret; } @@ -708,7 +728,7 @@ HPDF_Page_TextWidth (HPDF_Page page, return 0; } - tw = HPDF_Font_TextWidth (attr->gstate->font, text, len); + tw = HPDF_Font_TextWidth (attr->gstate->font, (HPDF_BYTE *)text, len); ret += attr->gstate->word_space * tw.numspace; ret += tw.width * attr->gstate->font_size / 1000; @@ -744,7 +764,7 @@ HPDF_Page_MeasureText (HPDF_Page page, return 0; } - ret = HPDF_Font_MeasureText (attr->gstate->font, text, len, width, + ret = HPDF_Font_MeasureText (attr->gstate->font, (HPDF_BYTE *)text, len, width, attr->gstate->font_size, attr->gstate->char_space, attr->gstate->word_space, wordwrap, real_width); @@ -971,7 +991,7 @@ HPDF_Page_GetTextRenderingMode (HPDF_Page page) HPDF_EXPORT(HPDF_REAL) HPDF_Page_GetTextRaise (HPDF_Page page) { - return HPDF_Page_GetTextRise (page); + return HPDF_Page_GetTextRise (page); } HPDF_EXPORT(HPDF_REAL) @@ -1205,7 +1225,7 @@ HPDF_Page_GetCurrentTextPos (HPDF_Page page) if (attr->gmode & HPDF_GMODE_TEXT_OBJECT) pos = attr->text_pos; } - + return pos; } @@ -1259,7 +1279,6 @@ HPDF_Page_SetBoxValue (HPDF_Page page, return HPDF_OK; } - HPDF_EXPORT(HPDF_STATUS) HPDF_Page_SetRotate (HPDF_Page page, HPDF_UINT16 angle) @@ -1286,6 +1305,25 @@ HPDF_Page_SetRotate (HPDF_Page page, return ret; } +HPDF_EXPORT(HPDF_STATUS) +HPDF_Page_SetZoom (HPDF_Page page, + HPDF_REAL zoom) +{ + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE((" HPDF_Page_SetZoom\n")); + + if (!HPDF_Page_Validate (page)) { + return HPDF_INVALID_PAGE; + } + + if (zoom < 0.08 || zoom > 32) { + return HPDF_RaiseError (page->error, HPDF_INVALID_PARAMETER, 0); + } + + ret = HPDF_Dict_AddReal (page, "PZ", zoom); + return ret; +} HPDF_EXPORT(HPDF_STATUS) HPDF_Page_SetWidth (HPDF_Page page, @@ -1394,6 +1432,33 @@ HPDF_Page_CreateDestination (HPDF_Page page) } +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_Create3DAnnot (HPDF_Page page, + HPDF_Rect rect, + HPDF_U3D u3d) +{ + HPDF_PageAttr attr; + HPDF_Annotation annot; + + HPDF_PTRACE((" HPDF_Page_Create3DAnnot\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + annot = HPDF_3DAnnot_New (page->mmgr, attr->xref, rect, u3d); + if (annot) { + if (AddAnnotation (page, annot) != HPDF_OK) { + HPDF_CheckError (page->error); + annot = NULL; + } + } else + HPDF_CheckError (page->error); + + return annot; +} + HPDF_EXPORT(HPDF_Annotation) HPDF_Page_CreateTextAnnot (HPDF_Page page, HPDF_Rect rect, @@ -1415,7 +1480,7 @@ HPDF_Page_CreateTextAnnot (HPDF_Page page, return NULL; } - annot = HPDF_TextAnnot_New (page->mmgr, attr->xref, rect, text, encoder); + annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_TEXT_NOTES); if (annot) { if (AddAnnotation (page, annot) != HPDF_OK) { HPDF_CheckError (page->error); @@ -1427,6 +1492,71 @@ HPDF_Page_CreateTextAnnot (HPDF_Page page, return annot; } +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateFreeTextAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder) +{ + HPDF_PageAttr attr; + HPDF_Annotation annot; + + HPDF_PTRACE((" HPDF_Page_CreateFreeTextAnnot\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + if (encoder && !HPDF_Encoder_Validate (encoder)) { + HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0); + return NULL; + } + + annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_FREE_TEXT); + if (annot) { + if (AddAnnotation (page, annot) != HPDF_OK) { + HPDF_CheckError (page->error); + annot = NULL; + } + } else + HPDF_CheckError (page->error); + + return annot; +} + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateLineAnnot (HPDF_Page page, + const char *text, + HPDF_Encoder encoder) +{ + HPDF_PageAttr attr; + HPDF_Annotation annot; + HPDF_Rect rect = {0,0,0,0}; + + HPDF_PTRACE((" HPDF_Page_CreateLineAnnot\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + if (encoder && !HPDF_Encoder_Validate (encoder)) { + HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0); + return NULL; + } + + annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_LINE); + if (annot) { + if (AddAnnotation (page, annot) != HPDF_OK) { + HPDF_CheckError (page->error); + annot = NULL; + } + } else + HPDF_CheckError (page->error); + + return annot; +} HPDF_EXPORT(HPDF_Annotation) HPDF_Page_CreateLinkAnnot (HPDF_Page page, @@ -1493,6 +1623,343 @@ HPDF_Page_CreateURILinkAnnot (HPDF_Page page, return annot; } +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateCircleAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder) +{ + HPDF_PageAttr attr; + HPDF_Annotation annot; + + HPDF_PTRACE((" HPDF_Page_CreateCircleAnnot\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + if (encoder && !HPDF_Encoder_Validate (encoder)) { + HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0); + return NULL; + } + + annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_CIRCLE); + if (annot) { + if (AddAnnotation (page, annot) != HPDF_OK) { + HPDF_CheckError (page->error); + annot = NULL; + } + } else + HPDF_CheckError (page->error); + + return annot; +} + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateSquareAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder) +{ + HPDF_PageAttr attr; + HPDF_Annotation annot; + + HPDF_PTRACE((" HPDF_Page_CreateCircleAnnot\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + if (encoder && !HPDF_Encoder_Validate (encoder)) { + HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0); + return NULL; + } + + annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_SQUARE); + if (annot) { + if (AddAnnotation (page, annot) != HPDF_OK) { + HPDF_CheckError (page->error); + annot = NULL; + } + } else + HPDF_CheckError (page->error); + + return annot; +} + +HPDF_EXPORT(HPDF_Dict) +HPDF_Page_Create3DView (HPDF_Page page, + HPDF_U3D u3d, + HPDF_Annotation annot3d, + const char *name) +{ + HPDF_PageAttr attr; + HPDF_Dict view; + + HPDF_PTRACE((" HPDF_Page_Create3DView\n")); + HPDF_UNUSED(annot3d); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + view = HPDF_3DView_New( page->mmgr, attr->xref, u3d, name); + if (!view) { + HPDF_CheckError (page->error); + } + return view; +} + +HPDF_Annotation +HPDF_Page_CreateTextMarkupAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder, + HPDF_AnnotType subType) +{ + HPDF_PageAttr attr; + HPDF_Annotation annot; + + HPDF_PTRACE((" HPDF_Page_CreateTextMarkupAnnot\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + if (encoder && !HPDF_Encoder_Validate (encoder)) { + HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0); + return NULL; + } + + annot = HPDF_MarkupAnnot_New ( page->mmgr, attr->xref, rect, text, encoder, subType); + if (annot) { + if (AddAnnotation (page, annot) != HPDF_OK) { + HPDF_CheckError (page->error); + annot = NULL; + } + } else + HPDF_CheckError (page->error); + + return annot; +} + + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateHighlightAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder) +{ + HPDF_PTRACE((" HPDF_Page_CreateHighlightAnnot\n")); + + return HPDF_Page_CreateTextMarkupAnnot( page, rect, text, encoder, HPDF_ANNOT_HIGHTLIGHT); +} + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateSquigglyAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder) +{ + HPDF_PTRACE((" HPDF_Page_CreateSquigglyAnnot\n")); + + return HPDF_Page_CreateTextMarkupAnnot( page, rect, text, encoder, HPDF_ANNOT_SQUIGGLY); +} + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateUnderlineAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder) +{ + HPDF_PTRACE((" HPDF_Page_CreateUnderlineAnnot\n")); + + return HPDF_Page_CreateTextMarkupAnnot( page, rect, text, encoder, HPDF_ANNOT_UNDERLINE); +} + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateStrikeOutAnnot (HPDF_Page page, + HPDF_Rect rect, + const char *text, + HPDF_Encoder encoder) +{ + HPDF_PTRACE((" HPDF_Page_CreateStrikeOutAnnot\n")); + + return HPDF_Page_CreateTextMarkupAnnot( page, rect, text, encoder, HPDF_ANNOT_STRIKE_OUT); +} + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreatePopupAnnot ( HPDF_Page page, + HPDF_Rect rect, + HPDF_Annotation parent) +{ + HPDF_PageAttr attr; + HPDF_Annotation annot; + + HPDF_PTRACE((" HPDF_Page_CreatePopupAnnot\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + annot = HPDF_PopupAnnot_New ( page->mmgr, attr->xref, rect, parent); + if (annot) { + if (AddAnnotation (page, annot) != HPDF_OK) { + HPDF_CheckError (page->error); + annot = NULL; + } + } else + HPDF_CheckError (page->error); + + return annot; +} + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateStampAnnot ( HPDF_Page page, + HPDF_Rect rect, + HPDF_StampAnnotName name, + const char* text, + HPDF_Encoder encoder) +{ + HPDF_PageAttr attr; + HPDF_Annotation annot; + + HPDF_PTRACE((" HPDF_Page_CreateStampAnnot\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + annot = HPDF_StampAnnot_New ( page->mmgr, attr->xref, rect, name, text, encoder); + if (annot) { + if (AddAnnotation (page, annot) != HPDF_OK) { + HPDF_CheckError (page->error); + annot = NULL; + } + } else + HPDF_CheckError (page->error); + + return annot; +} + +HPDF_EXPORT(HPDF_Annotation) +HPDF_Page_CreateProjectionAnnot(HPDF_Page page, + HPDF_Rect rect, + const char* text, + HPDF_Encoder encoder) +{ + HPDF_PageAttr attr; + HPDF_Annotation annot; + + HPDF_PTRACE((" HPDF_Page_CreateProjectionAnnot\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + annot = HPDF_ProjectionAnnot_New (page->mmgr, attr->xref, rect, text, encoder); + if (annot) { + if (AddAnnotation (page, annot) != HPDF_OK) { + HPDF_CheckError (page->error); + annot = NULL; + } + } else + HPDF_CheckError (page->error); + + return annot; +} + + +HPDF_EXPORT(HPDF_3DMeasure) +HPDF_Page_Create3DC3DMeasure(HPDF_Page page, + HPDF_Point3D firstanchorpoint, + HPDF_Point3D textanchorpoint) +{ + HPDF_PageAttr attr; + HPDF_Annotation measure; + + HPDF_PTRACE((" HPDF_Page_Create3DC3DMeasure\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + measure = HPDF_3DC3DMeasure_New(page->mmgr, attr->xref, firstanchorpoint, textanchorpoint); + if ( !measure) + HPDF_CheckError (page->error); + + return measure; +} + +HPDF_EXPORT(HPDF_3DMeasure) +HPDF_Page_CreatePD33DMeasure(HPDF_Page page, + HPDF_Point3D annotationPlaneNormal, + HPDF_Point3D firstAnchorPoint, + HPDF_Point3D secondAnchorPoint, + HPDF_Point3D leaderLinesDirection, + HPDF_Point3D measurementValuePoint, + HPDF_Point3D textYDirection, + HPDF_REAL value, + const char* unitsString + ) +{ + HPDF_PageAttr attr; + HPDF_Annotation measure; + + HPDF_PTRACE((" HPDF_Page_CreatePD33DMeasure\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + measure = HPDF_PD33DMeasure_New(page->mmgr, + attr->xref, + annotationPlaneNormal, + firstAnchorPoint, + secondAnchorPoint, + leaderLinesDirection, + measurementValuePoint, + textYDirection, + value, + unitsString + ); + if ( !measure) + HPDF_CheckError (page->error); + + return measure; +} + + +HPDF_EXPORT(HPDF_ExData) +HPDF_Page_Create3DAnnotExData(HPDF_Page page) +{ + HPDF_PageAttr attr; + HPDF_Annotation exData; + + HPDF_PTRACE((" HPDF_Page_Create3DAnnotExData\n")); + + if (!HPDF_Page_Validate (page)) + return NULL; + + attr = (HPDF_PageAttr)page->attr; + + exData = HPDF_3DAnnotExData_New(page->mmgr, attr->xref); + if ( !exData) + HPDF_CheckError (page->error); + + return exData; +} + + void HPDF_Page_SetFilter (HPDF_Page page, diff --git a/PDF/src/hpdf_pdfa.c b/PDF/src/hpdf_pdfa.c new file mode 100644 index 000000000..df06d1c13 --- /dev/null +++ b/PDF/src/hpdf_pdfa.c @@ -0,0 +1,386 @@ +/* + * << Haru Free PDF Library >> -- hpdf_pdfa.c + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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. + * + */ +/* This is used to avoid warnings on 'ctime' when compiling in MSVC 9 */ +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include +#include "hpdf_utils.h" +#include "hpdf.h" +#include + + +#define HEADER "" +#define DC_HEADER "" +#define DC_TITLE_STARTTAG "" +#define DC_TITLE_ENDTAG "" +#define DC_CREATOR_STARTTAG "" +#define DC_CREATOR_ENDTAG "" +#define DC_DESCRIPTION_STARTTAG "" +#define DC_DESCRIPTION_ENDTAG "" +#define DC_FOOTER "" +#define XMP_HEADER "" +#define XMP_CREATORTOOL_STARTTAG "" +#define XMP_CREATORTOOL_ENDTAG "" +#define XMP_CREATE_DATE_STARTTAG "" +#define XMP_CREATE_DATE_ENDTAG "" +#define XMP_MOD_DATE_STARTTAG "" +#define XMP_MOD_DATE_ENDTAG "" +#define XMP_FOOTER "" +#define PDF_HEADER "" +#define PDF_KEYWORDS_STARTTAG "" +#define PDF_KEYWORDS_ENDTAG "" +#define PDF_PRODUCER_STARTTAG "" +#define PDF_PRODUCER_ENDTAG "" +#define PDF_FOOTER "" +#define PDFAID_PDFA1A "" +#define PDFAID_PDFA1B "" +#define FOOTER "" + + +/* + * Convert date in PDF specific format: D:YYYYMMDDHHmmSS + * to XMP value in format YYYY-MM-DDTHH:mm:SS+offH:offMin + */ +HPDF_STATUS ConvertDateToXMDate(HPDF_Stream stream, const char *pDate) +{ + HPDF_STATUS ret; + + if(pDate==NULL) return HPDF_INVALID_PARAMETER; + if(strlen(pDate)<16) return HPDF_INVALID_PARAMETER; + if(pDate[0]!='D'|| + pDate[1]!=':') return HPDF_INVALID_PARAMETER; + pDate+=2; + /* Copy YYYY */ + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 4); + if (ret != HPDF_OK) + return ret; + pDate+=4; + /* Write -MM */ + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)"-", 1); + if (ret != HPDF_OK) + return ret; + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2); + if (ret != HPDF_OK) + return ret; + pDate+=2; + /* Write -DD */ + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)"-", 1); + if (ret != HPDF_OK) + return ret; + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2); + if (ret != HPDF_OK) + return ret; + pDate+=2; + /* Write THH */ + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)"T", 1); + if (ret != HPDF_OK) + return ret; + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2); + if (ret != HPDF_OK) + return ret; + pDate+=2; + /* Write :mm */ + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)":", 1); + if (ret != HPDF_OK) + return ret; + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2); + if (ret != HPDF_OK) + return ret; + pDate+=2; + /* Write :SS */ + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)":", 1); + if (ret != HPDF_OK) + return ret; + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2); + if (ret != HPDF_OK) + return ret; + pDate+=2; + /* Write +... */ + if(pDate[0]==0) { + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)"Z", 1); + return ret; + } + if(pDate[0]=='+'||pDate[0]=='-') { + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 3); + if (ret != HPDF_OK) + return ret; + pDate+=4; + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)":", 1); + if (ret != HPDF_OK) + return ret; + ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2); + if (ret != HPDF_OK) + return ret; + return ret; + } + return HPDF_SetError (stream->error, HPDF_INVALID_PARAMETER, 0); +} + +/* Write XMP Metadata for PDF/A */ + +HPDF_STATUS +HPDF_PDFA_SetPDFAConformance (HPDF_Doc pdf,HPDF_PDFAType pdfatype) +{ + HPDF_OutputIntent xmp; + HPDF_STATUS ret; + + const char *dc_title = NULL; + const char *dc_creator = NULL; + const char *dc_description = NULL; + + const char *xmp_CreatorTool = NULL; + const char *xmp_CreateDate = NULL; + const char *xmp_ModifyDate = NULL; + + const char *pdf_Keywords = NULL; + const char *pdf_Producer = NULL; + + const char *info = NULL; + + if (!HPDF_HasDoc(pdf)) { + return HPDF_INVALID_DOCUMENT; + } + + dc_title = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_TITLE); + dc_creator = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_AUTHOR); + dc_description = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_SUBJECT); + + xmp_CreateDate = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_CREATION_DATE); + xmp_ModifyDate = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_MOD_DATE); + xmp_CreatorTool = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_CREATOR); + + pdf_Keywords = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_KEYWORDS); + pdf_Producer = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_PRODUCER); + + if((dc_title != NULL) || (dc_creator != NULL) || (dc_description != NULL) + || (xmp_CreateDate != NULL) || (xmp_ModifyDate != NULL) || (xmp_CreatorTool != NULL) + || (pdf_Keywords != NULL)) { + + xmp = HPDF_DictStream_New(pdf->mmgr,pdf->xref); + if (!xmp) { + return HPDF_INVALID_STREAM; + } + + /* Update the PDF number version */ + pdf->pdf_version = HPDF_VER_14; + + HPDF_Dict_AddName(xmp,"Type","Metadata"); + HPDF_Dict_AddName(xmp,"SubType","XML"); + + ret = HPDF_OK; + ret += HPDF_Stream_WriteStr(xmp->stream, HEADER); + + /* Add the dc block */ + if((dc_title != NULL) || (dc_creator != NULL) || (dc_description != NULL)) { + ret += HPDF_Stream_WriteStr(xmp->stream, DC_HEADER); + + if(dc_title != NULL) { + ret += HPDF_Stream_WriteStr(xmp->stream, DC_TITLE_STARTTAG); + ret += HPDF_Stream_WriteStr(xmp->stream, dc_title); + ret += HPDF_Stream_WriteStr(xmp->stream, DC_TITLE_ENDTAG); + } + + if(dc_creator != NULL) { + ret += HPDF_Stream_WriteStr(xmp->stream, DC_CREATOR_STARTTAG); + ret += HPDF_Stream_WriteStr(xmp->stream, dc_creator); + ret += HPDF_Stream_WriteStr(xmp->stream, DC_CREATOR_ENDTAG); + } + + if(dc_description != NULL) { + ret += HPDF_Stream_WriteStr(xmp->stream, DC_DESCRIPTION_STARTTAG); + ret += HPDF_Stream_WriteStr(xmp->stream, dc_description); + ret += HPDF_Stream_WriteStr(xmp->stream, DC_DESCRIPTION_ENDTAG); + } + + ret += HPDF_Stream_WriteStr(xmp->stream, DC_FOOTER); + } + + /* Add the xmp block */ + if((xmp_CreateDate != NULL) || (xmp_ModifyDate != NULL) || (xmp_CreatorTool != NULL)) { + ret += HPDF_Stream_WriteStr(xmp->stream, XMP_HEADER); + + /* Add CreateDate, ModifyDate, and CreatorTool */ + if(xmp_CreatorTool != NULL) { + ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATORTOOL_STARTTAG); + ret += HPDF_Stream_WriteStr(xmp->stream, xmp_CreatorTool); + ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATORTOOL_ENDTAG); + } + + if(xmp_CreateDate != NULL) { + ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATE_DATE_STARTTAG); + /* Convert date to XMP compatible format */ + ret += ConvertDateToXMDate(xmp->stream, xmp_CreateDate); + ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATE_DATE_ENDTAG); + } + + if(xmp_ModifyDate != NULL) { + ret += HPDF_Stream_WriteStr(xmp->stream, XMP_MOD_DATE_STARTTAG); + ret += ConvertDateToXMDate(xmp->stream, xmp_ModifyDate); + ret += HPDF_Stream_WriteStr(xmp->stream, XMP_MOD_DATE_ENDTAG); + } + + ret += HPDF_Stream_WriteStr(xmp->stream, XMP_FOOTER); + } + + /* Add the pdf block */ + if((pdf_Keywords != NULL) || (pdf_Producer != NULL)) { + ret += HPDF_Stream_WriteStr(xmp->stream, PDF_HEADER); + + if(pdf_Keywords != NULL) { + ret += HPDF_Stream_WriteStr(xmp->stream, PDF_KEYWORDS_STARTTAG); + ret += HPDF_Stream_WriteStr(xmp->stream, pdf_Keywords); + ret += HPDF_Stream_WriteStr(xmp->stream, PDF_KEYWORDS_ENDTAG); + } + + if(pdf_Producer != NULL) { + ret += HPDF_Stream_WriteStr(xmp->stream, PDF_PRODUCER_STARTTAG); + ret += HPDF_Stream_WriteStr(xmp->stream, pdf_Producer); + ret += HPDF_Stream_WriteStr(xmp->stream, PDF_PRODUCER_ENDTAG); + } + + ret += HPDF_Stream_WriteStr(xmp->stream, PDF_FOOTER); + } + + /* Add the pdfaid block */ + switch(pdfatype) { + case HPDF_PDFA_1A: + ret += HPDF_Stream_WriteStr(xmp->stream, PDFAID_PDFA1A); + break; + case HPDF_PDFA_1B: + ret += HPDF_Stream_WriteStr(xmp->stream, PDFAID_PDFA1B); + break; + } + + ret += HPDF_Stream_WriteStr(xmp->stream, 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); + } + + return HPDF_OK; +} + +/* Generate an ID for the trailer dict, PDF/A needs this. + TODO: Better algorithm for generate unique ID. +*/ +HPDF_STATUS +HPDF_PDFA_GenerateID(HPDF_Doc pdf) +{ + HPDF_Array id; + HPDF_BYTE *currentTime; + HPDF_BYTE idkey[HPDF_MD5_KEY_LEN]; + HPDF_MD5_CTX md5_ctx; + time_t ltime; + + ltime = time(NULL); + currentTime = (HPDF_BYTE *)ctime(<ime); + + id = HPDF_Dict_GetItem(pdf->trailer, "ID", HPDF_OCLASS_ARRAY); + if (!id) { + id = HPDF_Array_New(pdf->mmgr); + + if (!id || HPDF_Dict_Add(pdf->trailer, "ID", id) != HPDF_OK) + return pdf->error.error_no; + + HPDF_MD5Init(&md5_ctx); + HPDF_MD5Update(&md5_ctx, (HPDF_BYTE *) "libHaru", sizeof("libHaru") - 1); + HPDF_MD5Update(&md5_ctx, currentTime, HPDF_StrLen((const char *)currentTime, -1)); + HPDF_MD5Final(idkey, &md5_ctx); + + if (HPDF_Array_Add (id, HPDF_Binary_New (pdf->mmgr, idkey, HPDF_MD5_KEY_LEN)) != HPDF_OK) + return pdf->error.error_no; + + if (HPDF_Array_Add (id, HPDF_Binary_New (pdf->mmgr,idkey,HPDF_MD5_KEY_LEN)) != HPDF_OK) + return pdf->error.error_no; + + return HPDF_OK; + } + + return HPDF_OK; +} + +/* Function to add one outputintents to the PDF + * iccname - name of default ICC profile + * iccdict - dictionary containing number of components + * and stream with ICC profile + * + * How to use: + * 1. Create dictionary with ICC profile + * HPDF_Dict icc = HPDF_DictStream_New (pDoc->mmgr, pDoc->xref); + * if(icc==NULL) return false; + * HPDF_Dict_AddNumber (icc, "N", 3); + * HPDF_STATUS ret = HPDF_Stream_Write (icc->stream, (const HPDF_BYTE *)pICCData, dwICCSize); + * if(ret!=HPDF_OK) { + * HPDF_Dict_Free(icc); + * return false; + * } + * + * 2. Call this function + */ + +HPDF_STATUS +HPDF_PDFA_AppendOutputIntents(HPDF_Doc pdf, const char *iccname, HPDF_Dict iccdict) +{ + HPDF_Array intents; + HPDF_Dict intent; + HPDF_STATUS ret; + if (!HPDF_HasDoc (pdf)) + return HPDF_INVALID_DOCUMENT; + + /* prepare intent */ + intent = HPDF_Dict_New (pdf->mmgr); + ret = HPDF_Xref_Add (pdf->xref, intent); + if ( ret != HPDF_OK) { + HPDF_Dict_Free(intent); + return ret; + } + ret += HPDF_Dict_AddName (intent, "Type", "OutputIntent"); + ret += HPDF_Dict_AddName (intent, "S", "GTS_PDFA1"); + ret += HPDF_Dict_Add (intent, "OutputConditionIdentifier", HPDF_String_New (pdf->mmgr, iccname, NULL)); + ret += HPDF_Dict_Add (intent, "OutputCondition", HPDF_String_New (pdf->mmgr, iccname,NULL)); + ret += HPDF_Dict_Add (intent, "Info", HPDF_String_New (pdf->mmgr, iccname, NULL)); + ret += HPDF_Dict_Add (intent, "DestOutputProfile ", iccdict); + if ( ret != HPDF_OK) { + HPDF_Dict_Free(intent); + return ret; + } + + /* Copied from HPDF_AddIntent - not public function */ + intents = HPDF_Dict_GetItem (pdf->catalog, "OutputIntents", HPDF_OCLASS_ARRAY); + if (intents == NULL) { + intents = HPDF_Array_New (pdf->mmgr); + if (intents) { + HPDF_STATUS ret = HPDF_Dict_Add (pdf->catalog, "OutputIntents", intents); + if (ret != HPDF_OK) { + HPDF_CheckError (&pdf->error); + return HPDF_Error_GetDetailCode (&pdf->error); + } + } + } + + HPDF_Array_Add(intents,intent); + return HPDF_Error_GetDetailCode (&pdf->error); +} diff --git a/PDF/src/hpdf_real.c b/PDF/src/hpdf_real.c index 3fd7e72b7..f686918f9 100644 --- a/PDF/src/hpdf_real.c +++ b/PDF/src/hpdf_real.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- hpdf_real.c + * << Haru Free PDF Library >> -- hpdf_real.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, diff --git a/PDF/src/hpdf_streams.c b/PDF/src/hpdf_streams.c index 05a5c3690..d73c1fc90 100644 --- a/PDF/src/hpdf_streams.c +++ b/PDF/src/hpdf_streams.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_streams.h + * << Haru Free PDF Library >> -- hpdf_streams.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -10,22 +13,28 @@ * in supporting documentation. * It is provided "as is" without express or implied warranty. * - * 2005.12.20 Created. - * */ +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS +#endif +#ifndef UNDER_CE #include - -#ifndef HPDF_NOZLIB -#include -#include -#endif /* HPDF_NOZLIB */ +#endif +#ifndef HPDF_UNUSED +#define HPDF_UNUSED(a) ((void)(a)) +#endif #include "hpdf_conf.h" #include "hpdf_consts.h" #include "hpdf_utils.h" #include "hpdf_streams.h" +#ifndef LIBHPDF_HAVE_NOZLIB +#include +#include +#endif /* LIBHPDF_HAVE_NOZLIB */ + HPDF_STATUS HPDF_MemStream_WriteFunc (HPDF_Stream stream, const HPDF_BYTE *ptr, @@ -132,7 +141,7 @@ HPDF_Stream_Read (HPDF_Stream stream, * s : Pointer to a buffer to copy read data. * size : buffer-size of s. * - * Read from stream until the buffer is exhausted or line-feed character is + * Read from stream until the buffer is exhausted or line-feed charactor is * read. * */ @@ -147,7 +156,10 @@ HPDF_Stream_ReadLn (HPDF_Stream stream, HPDF_PTRACE((" HPDF_Stream_ReadLn\n")); - if (!stream || !s || *size == 0) + if (!stream) + return HPDF_INVALID_PARAMETER; + + if (!s || *size == 0) return HPDF_SetError (stream->error, HPDF_INVALID_PARAMETER, 0); if (!(stream->seek_fn) || !(stream->read_fn)) @@ -160,7 +172,7 @@ HPDF_Stream_ReadLn (HPDF_Stream stream, while (r_size > 1) { char *pbuf = buf; - HPDF_STATUS ret = HPDF_Stream_Read (stream, buf, &read_size); + HPDF_STATUS ret = HPDF_Stream_Read (stream, (HPDF_BYTE *)buf, &read_size); if (ret != HPDF_OK && read_size == 0) return ret; @@ -250,7 +262,7 @@ HPDF_STATUS HPDF_Stream_WriteChar (HPDF_Stream stream, char value) { - return HPDF_Stream_Write(stream, &value, sizeof(char)); + return HPDF_Stream_Write(stream, (HPDF_BYTE *)&value, sizeof(char)); } @@ -260,7 +272,7 @@ HPDF_Stream_WriteStr (HPDF_Stream stream, { HPDF_UINT len = HPDF_StrLen(value, -1); - return HPDF_Stream_Write(stream, value, len); + return HPDF_Stream_Write(stream, (HPDF_BYTE *)value, len); } HPDF_STATUS @@ -278,7 +290,7 @@ HPDF_Stream_WriteInt (HPDF_Stream stream, char* p = HPDF_IToA(buf, value, buf + HPDF_INT_LEN); - return HPDF_Stream_Write(stream, buf, (HPDF_UINT)(p - buf)); + return HPDF_Stream_Write(stream, (HPDF_BYTE *)buf, (HPDF_UINT)(p - buf)); } HPDF_STATUS @@ -296,7 +308,7 @@ HPDF_Stream_WriteReal (HPDF_Stream stream, char* p = HPDF_FToA(buf, value, buf + HPDF_REAL_LEN); - return HPDF_Stream_Write(stream, buf, (HPDF_UINT)(p - buf)); + return HPDF_Stream_Write(stream, (HPDF_BYTE *)buf, (HPDF_UINT)(p - buf)); } void @@ -404,7 +416,7 @@ HPDF_Stream_WriteEscapeName (HPDF_Stream stream, } *pos2 = 0; - return HPDF_Stream_Write (stream, tmp_char, HPDF_StrLen(tmp_char, -1)); + return HPDF_Stream_Write (stream, (HPDF_BYTE *)tmp_char, HPDF_StrLen(tmp_char, -1)); } HPDF_STATUS @@ -420,23 +432,29 @@ HPDF_Stream_WriteEscapeText2 (HPDF_Stream stream, HPDF_PTRACE((" HPDF_Stream_WriteEscapeText2\n")); + /* The following block is commented out because it violates "PDF Spec 7.3.4.2 Literal Strings". + * It states that the two matching parentheses must still be present to represent an empty + * string of zero length. + */ + /* if (!len) return HPDF_OK; + */ buf[idx++] = '('; - for (i = 0; i < len; i++) { + for (i = 0; i < (HPDF_INT)len; i++) { HPDF_BYTE c = (HPDF_BYTE)*p++; if (HPDF_NEEDS_ESCAPE(c)) { buf[idx++] = '\\'; - buf[idx] = c >> 6; + buf[idx] = (char)(c >> 6); buf[idx] += 0x30; idx++; - buf[idx] = (c & 0x38) >> 3; + buf[idx] = (char)((c & 0x38) >> 3); buf[idx] += 0x30; idx++; - buf[idx] = (c & 0x07); + buf[idx] = (char)(c & 0x07); buf[idx] += 0x30; idx++; } @@ -444,7 +462,7 @@ HPDF_Stream_WriteEscapeText2 (HPDF_Stream stream, buf[idx++] = c; if (idx > HPDF_TEXT_DEFAULT_LEN - 4) { - ret = HPDF_Stream_Write (stream, buf, idx); + ret = HPDF_Stream_Write (stream, (HPDF_BYTE *)buf, idx); if (ret != HPDF_OK) return ret; idx = 0; @@ -452,7 +470,7 @@ HPDF_Stream_WriteEscapeText2 (HPDF_Stream stream, } buf[idx++] = ')'; - ret = HPDF_Stream_Write (stream, buf, idx); + ret = HPDF_Stream_Write (stream, (HPDF_BYTE *)buf, idx); return ret; } @@ -502,7 +520,7 @@ HPDF_Stream_WriteBinary (HPDF_Stream stream, } for (i = 0; i < len; i++, p++) { - char c = *p >> 4; + char c = (char)(*p >> 4); if (c <= 9) c += 0x30; @@ -510,7 +528,7 @@ HPDF_Stream_WriteBinary (HPDF_Stream stream, c += 0x41 - 10; buf[idx++] = c; - c = *p & 0x0f; + c = (char)(*p & 0x0f); if (c <= 9) c += 0x30; else @@ -518,7 +536,7 @@ HPDF_Stream_WriteBinary (HPDF_Stream stream, buf[idx++] = c; if (idx > HPDF_TEXT_DEFAULT_LEN - 2) { - ret = HPDF_Stream_Write (stream, buf, idx); + ret = HPDF_Stream_Write (stream, (HPDF_BYTE *)buf, idx); if (ret != HPDF_OK) { if (flg) HPDF_FreeMem (stream->mmgr, pbuf); @@ -529,7 +547,7 @@ HPDF_Stream_WriteBinary (HPDF_Stream stream, } if (idx > 0) { - ret = HPDF_Stream_Write (stream, buf, idx); + ret = HPDF_Stream_Write (stream, (HPDF_BYTE *)buf, idx); } if (flg) @@ -544,7 +562,7 @@ HPDF_Stream_WriteToStreamWithDeflate (HPDF_Stream src, HPDF_Stream dst, HPDF_Encrypt e) { -#ifndef HPDF_NOZLIB +#ifndef LIBHPDF_HAVE_NOZLIB #define DEFLATE_BUF_SIZ ((HPDF_INT)(HPDF_STREAM_BUF_SIZ * 1.1) + 13) @@ -658,9 +676,12 @@ HPDF_Stream_WriteToStreamWithDeflate (HPDF_Stream src, deflateEnd(&strm); return HPDF_OK; -#else /* HPDF_NOZLIB */ +#else /* LIBHPDF_HAVE_NOZLIB */ + HPDF_UNUSED (e); + HPDF_UNUSED (dst); + HPDF_UNUSED (src); return HPDF_UNSUPPORTED_FUNC; -#endif /* HPDF_NOZLIB */ +#endif /* LIBHPDF_HAVE_NOZLIB */ } HPDF_STATUS @@ -675,6 +696,7 @@ HPDF_Stream_WriteToStream (HPDF_Stream src, HPDF_BOOL flg; HPDF_PTRACE((" HPDF_Stream_WriteToStream\n")); + HPDF_UNUSED (filter); if (!dst || !(dst->write_fn)) { HPDF_SetError (src->error, HPDF_INVALID_OBJECT, 0); @@ -685,15 +707,15 @@ HPDF_Stream_WriteToStream (HPDF_Stream src, HPDF_Error_GetCode (dst->error) != HPDF_NOERROR) return HPDF_THIS_FUNC_WAS_SKIPPED; -#ifndef HPDF_NOZLIB - if (filter & HPDF_STREAM_FILTER_FLATE_DECODE) - return HPDF_Stream_WriteToStreamWithDeflate (src, dst, e); -#endif /* HPDF_NOZLIB */ - /* initialize input stream */ if (HPDF_Stream_Size (src) == 0) return HPDF_OK; +#ifndef LIBHPDF_HAVE_NOZLIB + if (filter & HPDF_STREAM_FILTER_FLATE_DECODE) + return HPDF_Stream_WriteToStreamWithDeflate (src, dst, e); +#endif /* LIBHPDF_HAVE_NOZLIB */ + ret = HPDF_Stream_Seek (src, 0, HPDF_SEEK_SET); if (ret != HPDF_OK) return ret; @@ -741,7 +763,11 @@ HPDF_FileReader_New (HPDF_MMgr mmgr, HPDF_PTRACE((" HPDF_FileReader_New\n")); if (!fp) { +#ifdef UNDER_CE + HPDF_SetError (mmgr->error, HPDF_FILE_OPEN_ERROR, GetLastError()); +#else HPDF_SetError (mmgr->error, HPDF_FILE_OPEN_ERROR, errno); +#endif return NULL; } @@ -913,7 +939,11 @@ HPDF_FileWriter_New (HPDF_MMgr mmgr, HPDF_PTRACE((" HPDF_FileWriter_New\n")); if (!fp) { +#ifdef UNDER_CE + HPDF_SetError (mmgr->error, HPDF_FILE_OPEN_ERROR, GetLastError()); +#else HPDF_SetError (mmgr->error, HPDF_FILE_OPEN_ERROR, errno); +#endif return NULL; } @@ -1071,8 +1101,13 @@ HPDF_MemStream_SeekFunc (HPDF_Stream stream, } else if (mode == HPDF_SEEK_END) pos = stream->size - pos; - if (pos > stream->size || stream->size == 0) + if (pos > (HPDF_INT)stream->size) { return HPDF_SetError (stream->error, HPDF_STREAM_EOF, 0); + } + + if (stream->size == 0) { + return HPDF_OK; + } attr->r_ptr_idx = pos / attr->buf_siz; attr->r_pos = pos % attr->buf_siz; @@ -1163,11 +1198,11 @@ HPDF_MemStream_New (HPDF_MMgr mmgr, HPDF_PTRACE((" HPDF_MemStream_New\n")); - // Create new HPDF_Stream object. + /* Create new HPDF_Stream object. */ stream = (HPDF_Stream)HPDF_GetMem (mmgr, sizeof(HPDF_Stream_Rec)); if (stream) { - // Create attribute struct. + /* Create attribute struct. */ HPDF_MemStreamAttr attr = (HPDF_MemStreamAttr)HPDF_GetMem (mmgr, sizeof(HPDF_MemStreamAttr_Rec)); diff --git a/PDF/src/hpdf_string.c b/PDF/src/hpdf_string.c index ca4418376..f915093d7 100644 --- a/PDF/src/hpdf_string.c +++ b/PDF/src/hpdf_string.c @@ -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 + * Copyright (c) 2007-2009 Antony Dovgal * * 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 #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); +} diff --git a/PDF/src/hpdf_u3d.c b/PDF/src/hpdf_u3d.c new file mode 100644 index 000000000..a028f6115 --- /dev/null +++ b/PDF/src/hpdf_u3d.c @@ -0,0 +1,880 @@ +/* + * << Haru Free PDF Library >> -- hpdf_u3d.c + * + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal + * + * 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 "hpdf_conf.h" +#include "hpdf_utils.h" +#include "hpdf.h" + +#include + +#ifndef M_PI +/* Not defined in MSVC6 */ +#define M_PI 3.14159265358979323846 +#endif + +HPDF_U3D +HPDF_U3D_LoadU3D (HPDF_MMgr mmgr, + HPDF_Stream u3d_data, + HPDF_Xref xref); + +static const char u3d[] = "U3D"; +static const char prc[] = "PRC"; + +static HPDF_STATUS Get3DStreamType (HPDF_Stream stream, const char **type) +{ + HPDF_BYTE tag[4]; + HPDF_UINT len; + + HPDF_PTRACE ((" HPDF_U3D_Get3DStreamType\n")); + + len = 4; + if (HPDF_Stream_Read (stream, tag, &len) != HPDF_OK) { + return HPDF_Error_GetCode (stream->error); + } + + if (HPDF_Stream_Seek (stream, 0, HPDF_SEEK_SET) != HPDF_OK) { + return HPDF_Error_GetCode (stream->error); + } + + if (HPDF_MemCmp(tag, (HPDF_BYTE *)u3d, 4/* yes, \0 is required */) == 0) { + *type = u3d; + return HPDF_OK; + } + + if (HPDF_MemCmp(tag, (HPDF_BYTE *)prc, 3) == 0) { + *type = prc; + return HPDF_OK; + } + + return HPDF_INVALID_U3D_DATA; +} + + +HPDF_U3D +HPDF_U3D_LoadU3DFromMem ( HPDF_MMgr mmgr, + const HPDF_BYTE *buf, + HPDF_UINT size, + HPDF_Xref xref ) +{ + HPDF_Dict image; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE ((" HPDF_U3D_LoadU3DFromMem\n")); + + image = HPDF_DictStream_New (mmgr, xref); + if (!image) { + return NULL; + } + + image->header.obj_class |= HPDF_OSUBCLASS_XOBJECT; + ret = HPDF_Dict_AddName (image, "Type", "XObject"); + if (ret != HPDF_OK) { + HPDF_Dict_Free(image); + return NULL; + } + + ret = HPDF_Dict_AddName (image, "Subtype", "Image"); + if (ret != HPDF_OK) { + HPDF_Dict_Free(image); + return NULL; + } + + if (HPDF_Stream_Write (image->stream, buf, size) != HPDF_OK) { + HPDF_Dict_Free(image); + return NULL; + } + + return image; +} + + +HPDF_EXPORT(HPDF_Image) +HPDF_LoadU3DFromFile (HPDF_Doc pdf, + const char *filename) +{ + HPDF_Stream imagedata; + HPDF_Image image; + + HPDF_PTRACE ((" HPDF_LoadU3DFromFile\n")); + + if (!HPDF_HasDoc (pdf)) { + return NULL; + } + + /* create file stream */ + imagedata = HPDF_FileReader_New (pdf->mmgr, filename); + + if (HPDF_Stream_Validate (imagedata)) { + image = HPDF_U3D_LoadU3D (pdf->mmgr, imagedata, pdf->xref); + } else { + image = NULL; + } + + /* destroy file stream */ + HPDF_Stream_Free (imagedata); + + if (!image) { + HPDF_CheckError (&pdf->error); + } + return image; +} + +HPDF_EXPORT(HPDF_Image) +HPDF_LoadU3DFromMem (HPDF_Doc pdf, + const HPDF_BYTE *buffer, + HPDF_UINT size) +{ + HPDF_Stream imagedata; + HPDF_Image image; + + HPDF_PTRACE ((" HPDF_LoadU3DFromMem\n")); + + if (!HPDF_HasDoc (pdf)) { + return NULL; + } + + /* create file stream */ + imagedata = HPDF_MemStream_New (pdf->mmgr, size); + + if (!HPDF_Stream_Validate (imagedata)) { + HPDF_RaiseError (&pdf->error, HPDF_INVALID_STREAM, 0); + return NULL; + } + + if (HPDF_Stream_Write (imagedata, buffer, size) != HPDF_OK) { + HPDF_Stream_Free (imagedata); + return NULL; + } + + if (HPDF_Stream_Validate (imagedata)) { + image = HPDF_U3D_LoadU3D (pdf->mmgr, imagedata, pdf->xref); + } else { + image = NULL; + } + + /* destroy file stream */ + HPDF_Stream_Free (imagedata); + + if (!image) { + HPDF_CheckError (&pdf->error); + } + return image; +} + +HPDF_U3D +HPDF_U3D_LoadU3D (HPDF_MMgr mmgr, + HPDF_Stream u3d_data, + HPDF_Xref xref) +{ + HPDF_Dict u3d; + const char *type; + + HPDF_PTRACE ((" HPDF_U3D_LoadU3D\n")); + + u3d = HPDF_DictStream_New (mmgr, xref); + if (!u3d) { + return NULL; + } + + u3d->header.obj_class |= HPDF_OSUBCLASS_XOBJECT; + + /* add required elements */ + u3d->filter = HPDF_STREAM_FILTER_NONE; + + if (HPDF_Dict_AddName (u3d, "Type", "3D") != HPDF_OK) { + HPDF_Dict_Free(u3d); + return NULL; + } + + if (Get3DStreamType (u3d_data, &type) != HPDF_OK) { + HPDF_Dict_Free(u3d); + return NULL; + } + + if (HPDF_Dict_AddName (u3d, "Subtype", type) != HPDF_OK) { + HPDF_Dict_Free(u3d); + return NULL; + } + + for (;;) { + HPDF_BYTE buf[HPDF_STREAM_BUF_SIZ]; + HPDF_UINT len = HPDF_STREAM_BUF_SIZ; + HPDF_STATUS ret = HPDF_Stream_Read (u3d_data, buf, &len); + + if (ret != HPDF_OK) { + if (ret == HPDF_STREAM_EOF) { + if (len > 0) { + ret = HPDF_Stream_Write (u3d->stream, buf, len); + if (ret != HPDF_OK) { + HPDF_Dict_Free(u3d); + return NULL; + } + } + break; + } else { + HPDF_Dict_Free(u3d); + return NULL; + } + } + + if (HPDF_Stream_Write (u3d->stream, buf, len) != HPDF_OK) { + HPDF_Dict_Free(u3d); + return NULL; + } + } + + return u3d; +} + +HPDF_EXPORT(HPDF_Dict) HPDF_Create3DView(HPDF_MMgr mmgr, const char *name) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_Dict view; + + HPDF_PTRACE ((" HPDF_Create3DView\n")); + + if (name == NULL || name[0] == '\0') { + return NULL; + } + + view = HPDF_Dict_New (mmgr); + if (!view) { + return NULL; + } + + ret = HPDF_Dict_AddName (view, "TYPE", "3DView"); + if (ret != HPDF_OK) { + HPDF_Dict_Free (view); + return NULL; + } + + ret = HPDF_Dict_Add (view, "XN", HPDF_String_New (mmgr, name, NULL)); + if (ret != HPDF_OK) { + HPDF_Dict_Free (view); + return NULL; + } + + ret = HPDF_Dict_Add (view, "IN", HPDF_String_New (mmgr, name, NULL)); + if (ret != HPDF_OK) { + HPDF_Dict_Free (view); + return NULL; + } + + return view; +} + +HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_Add3DView(HPDF_U3D u3d, HPDF_Dict view) +{ + HPDF_Array views = NULL; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE ((" HPDF_Add3DView\n")); + + if (u3d == NULL || view == NULL) { + return HPDF_INVALID_U3D_DATA; + } + + views = (HPDF_Array)HPDF_Dict_GetItem (u3d, "VA", HPDF_OCLASS_ARRAY); + if (views == NULL) { + views = HPDF_Array_New (u3d->mmgr); + if (!views) { + return HPDF_Error_GetCode (u3d->error); + } + + ret = HPDF_Dict_Add (u3d, "VA", views); + if (ret == HPDF_OK) { + ret = HPDF_Dict_AddNumber (u3d, "DV", 0); + } else { + HPDF_Array_Free (views); + return ret; + } + } + + if (ret == HPDF_OK) { + ret = HPDF_Array_Add( views, view); + } + + return ret; +} + + +HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_AddOnInstanciate(HPDF_U3D u3d, HPDF_JavaScript javascript) +{ + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE ((" HPDF_U3D_AddOnInstanciate\n")); + + if (u3d == NULL || javascript == NULL) { + return HPDF_INVALID_U3D_DATA; + } + + ret = HPDF_Dict_Add(u3d, "OnInstantiate", javascript); + + return ret; +} + + +HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_SetDefault3DView(HPDF_U3D u3d, const char *name) +{ + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE ((" HPDF_U3D_SetDefault3DView\n")); + + if (u3d == NULL || name == NULL || name[0] == '\0') { + return HPDF_INVALID_U3D_DATA; + } + + ret = HPDF_Dict_Add (u3d, "DV", HPDF_String_New (u3d->mmgr, name, NULL)); + return ret; +} + +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_AddNode(HPDF_Dict view, const char *name, HPDF_REAL opacity, HPDF_BOOL visible) +{ + HPDF_Array nodes = NULL; + HPDF_Dict node; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE ((" HPDF_3DView_AddNode\n")); + + if (view == NULL || opacity < 0 || opacity > 1 || name == NULL || name[0] == '\0') { + return HPDF_INVALID_U3D_DATA; + } + + nodes = (HPDF_Array)HPDF_Dict_GetItem (view, "NA", HPDF_OCLASS_ARRAY); + if (nodes == NULL) { + nodes = HPDF_Array_New (view->mmgr); + if (!nodes) { + return HPDF_Error_GetCode (view->error); + } + + ret = HPDF_Dict_Add (view, "NA", nodes); + if (ret != HPDF_OK) { + HPDF_Array_Free (nodes); + return ret; + } + } + + node = HPDF_Dict_New (view->mmgr); + if (!node) { + HPDF_Array_Free (nodes); + return HPDF_Error_GetCode (view->error); + } + + ret = HPDF_Dict_AddName (node, "Type", "3DNode"); + if (ret != HPDF_OK) { + HPDF_Array_Free (nodes); + HPDF_Dict_Free (node); + return ret; + } + + ret = HPDF_Dict_Add (node, "N", HPDF_String_New (view->mmgr, name, NULL)); + if (ret != HPDF_OK) { + HPDF_Array_Free (nodes); + HPDF_Dict_Free (node); + return ret; + } + + ret = HPDF_Dict_AddReal (node, "O", opacity); + if (ret != HPDF_OK) { + HPDF_Array_Free (nodes); + HPDF_Dict_Free (node); + return ret; + } + + ret = HPDF_Dict_AddBoolean (node, "V", visible); + if (ret != HPDF_OK) { + HPDF_Dict_Free (node); + HPDF_Array_Free (nodes); + return ret; + } + + ret = HPDF_Array_Add(nodes, node); + if (ret != HPDF_OK) { + HPDF_Dict_Free (node); + HPDF_Array_Free (nodes); + return ret; + } + return ret; +} + +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetLighting(HPDF_Dict view, const char *scheme) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_Dict lighting; + int i; + static const char * const schemes[] = + { "Artwork", "None", "White", "Day", "Night", "Hard", "Primary", "Blue", "Red", "Cube", "CAD", "Headlamp" }; + + HPDF_PTRACE ((" HPDF_3DView_SetLighting\n")); + + if (view == NULL || scheme == NULL || scheme[0] == '\0') { + return HPDF_INVALID_U3D_DATA; + } + + for (i = 0; i < 12; i++) { + if (!strcmp(scheme, schemes[i])) { + break; + } + } + + if (i == 12) { + return HPDF_INVALID_U3D_DATA; + } + + lighting = HPDF_Dict_New (view->mmgr); + if (!lighting) { + return HPDF_Error_GetCode (view->error); + } + + ret = HPDF_Dict_AddName (lighting, "Type", "3DLightingScheme"); + if (ret != HPDF_OK) { + HPDF_Dict_Free (lighting); + return ret; + } + + ret = HPDF_Dict_AddName (lighting, "Subtype", scheme); + if (ret != HPDF_OK) { + HPDF_Dict_Free (lighting); + return ret; + } + + ret = HPDF_Dict_Add (view, "LS", lighting); + if (ret != HPDF_OK) { + HPDF_Dict_Free (lighting); + return ret; + } + return ret; +} + +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetBackgroundColor(HPDF_Dict view, HPDF_REAL r, HPDF_REAL g, HPDF_REAL b) +{ + HPDF_Array color; + HPDF_STATUS ret = HPDF_OK; + HPDF_Dict background; + + HPDF_PTRACE ((" HPDF_3DView_SetBackgroundColor\n")); + + if (view == NULL || r < 0 || r > 1 || g < 0 || g > 1 || b < 0 || b > 1) { + return HPDF_INVALID_U3D_DATA; + } + + background = HPDF_Dict_New (view->mmgr); + if (!background) { + return HPDF_Error_GetCode (view->error); + } + + color = HPDF_Array_New (view->mmgr); + if (!color) { + HPDF_Dict_Free (background); + return HPDF_Error_GetCode (view->error); + } + + ret = HPDF_Array_AddReal (color, r); + if (ret != HPDF_OK) { + HPDF_Array_Free (color); + HPDF_Dict_Free (background); + return ret; + } + + ret = HPDF_Array_AddReal (color, g); + if (ret != HPDF_OK) { + HPDF_Array_Free (color); + HPDF_Dict_Free (background); + return ret; + } + + ret = HPDF_Array_AddReal (color, b); + if (ret != HPDF_OK) { + HPDF_Array_Free (color); + HPDF_Dict_Free (background); + return ret; + } + + + ret = HPDF_Dict_AddName (background, "Type", "3DBG"); + if (ret != HPDF_OK) { + HPDF_Array_Free (color); + HPDF_Dict_Free (background); + return ret; + } + + ret = HPDF_Dict_Add (background, "C", color); + if (ret != HPDF_OK) { + HPDF_Array_Free (color); + HPDF_Dict_Free (background); + return ret; + } + + ret = HPDF_Dict_Add (view, "BG", background); + if (ret != HPDF_OK) { + HPDF_Array_Free (color); + HPDF_Dict_Free (background); + return ret; + } + return ret; +} + +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetPerspectiveProjection(HPDF_Dict view, HPDF_REAL fov) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_Dict projection; + + HPDF_PTRACE ((" HPDF_3DView_SetPerspectiveProjection\n")); + + if (view == NULL || fov < 0 || fov > 180) { + return HPDF_INVALID_U3D_DATA; + } + + projection = HPDF_Dict_New (view->mmgr); + if (!projection) { + return HPDF_Error_GetCode (view->error); + } + + ret = HPDF_Dict_AddName (projection, "Subtype", "P"); + if (ret != HPDF_OK) { + HPDF_Dict_Free (projection); + return ret; + } + + ret = HPDF_Dict_AddName (projection, "PS", "Min"); + if (ret != HPDF_OK) { + HPDF_Dict_Free (projection); + return ret; + } + + ret = HPDF_Dict_AddReal (projection, "FOV", fov); + if (ret != HPDF_OK) { + HPDF_Dict_Free (projection); + return ret; + } + + ret = HPDF_Dict_Add (view, "P", projection); + if (ret != HPDF_OK) { + HPDF_Dict_Free (projection); + return ret; + } + return ret; +} + +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetOrthogonalProjection(HPDF_Dict view, HPDF_REAL mag) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_Dict projection; + + HPDF_PTRACE ((" HPDF_3DView_SetOrthogonalProjection\n")); + + if (view == NULL || mag <= 0) { + return HPDF_INVALID_U3D_DATA; + } + + projection = HPDF_Dict_New (view->mmgr); + if (!projection) { + return HPDF_Error_GetCode (view->error); + } + + ret = HPDF_Dict_AddName (projection, "Subtype", "O"); + if (ret != HPDF_OK) { + HPDF_Dict_Free (projection); + return ret; + } + + ret = HPDF_Dict_AddReal (projection, "OS", mag); + if (ret != HPDF_OK) { + HPDF_Dict_Free (projection); + return ret; + } + + ret = HPDF_Dict_Add (view, "P", projection); + if (ret != HPDF_OK) { + HPDF_Dict_Free (projection); + return ret; + } + return ret; +} + +#define normalize(x, y, z) \ +{ \ + HPDF_REAL modulo; \ + modulo = (float)sqrt((float)(x*x) + (float)(y*y) + (float)(z*z)); \ + if (modulo != 0.0) \ + { \ + x = x/modulo; \ + y = y/modulo; \ + z = z/modulo; \ + } \ +} + +/* building the transformation matrix*/ +/* #1,#2,#3 centre of orbit coordinates (coo)*/ +/* #4,#5,#6 centre of orbit to camera direction vector (c2c)*/ +/* #7 orbital radius (roo)*/ +/* #8 camera roll (roll)*/ + +HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetCamera(HPDF_Dict view, HPDF_REAL coox, HPDF_REAL cooy, HPDF_REAL cooz, HPDF_REAL c2cx, HPDF_REAL c2cy, HPDF_REAL c2cz, HPDF_REAL roo, HPDF_REAL roll) +{ + HPDF_REAL viewx, viewy, viewz; + HPDF_REAL leftx, lefty, leftz; + HPDF_REAL upx, upy, upz; + HPDF_REAL transx, transy, transz; + + HPDF_Array matrix; + HPDF_STATUS ret = HPDF_OK; + + HPDF_PTRACE ((" HPDF_3DView_SetCamera\n")); + + if (view == NULL) { + return HPDF_INVALID_U3D_DATA; + } + + /* view vector (opposite to c2c) */ + viewx = -c2cx; + viewy = -c2cy; + viewz = -c2cz; + + /* c2c = (0, -1, 0) by default */ + if (viewx == 0.0 && viewy == 0.0 && viewz == 0.0) { + viewy = 1.0; + } + /* normalize view vector */ + normalize(viewx, viewy, viewz); + + /* rotation matrix */ + + /* top and bottom views */ + leftx = -1.0f; + lefty = 0.0f; + leftz = 0.0f; + + /* up-vector */ + if (viewz < 0.0) /* top view*/ + { + upx = 0.0f; + upy = 1.0f; + upz = 0.0f; + } + else /* bottom view*/ + { + upx = 0.0f; + upy =-1.0f; + upz = 0.0f; + } + + if ( fabs(viewx) + fabs(viewy) != 0.0f) /* other views than top and bottom*/ + { + /* up-vector = up_world - (up_world dot view) view*/ + upx = -viewz*viewx; + upy = -viewz*viewy; + upz = -viewz*viewz + 1.0f; + /* normalize up-vector*/ + normalize(upx, upy, upz); + /* left vector = up x view*/ + leftx = viewz*upy - viewy*upz; + lefty = viewx*upz - viewz*upx; + leftz = viewy*upx - viewx*upy; + /* normalize left vector*/ + normalize(leftx, lefty, leftz); + } + /* apply camera roll*/ + { + HPDF_REAL leftxprime, leftyprime, leftzprime; + HPDF_REAL upxprime, upyprime, upzprime; + HPDF_REAL sinroll, cosroll; + + sinroll = (HPDF_REAL)sin((roll/180.0f)*M_PI); + cosroll = (HPDF_REAL)cos((roll/180.0f)*M_PI); + leftxprime = leftx*cosroll + upx*sinroll; + leftyprime = lefty*cosroll + upy*sinroll; + leftzprime = leftz*cosroll + upz*sinroll; + upxprime = upx*cosroll + leftx*sinroll; + upyprime = upy*cosroll + lefty*sinroll; + upzprime = upz*cosroll + leftz*sinroll; + leftx = leftxprime; + lefty = leftyprime; + leftz = leftzprime; + upx = upxprime; + upy = upyprime; + upz = upzprime; + } + + /* translation vector*/ + roo = (HPDF_REAL)fabs(roo); + if (roo == 0.0) { + roo = (HPDF_REAL)0.000000000000000001; + } + transx = coox - roo*viewx; + transy = cooy - roo*viewy; + transz = cooz - roo*viewz; + + /* transformation matrix*/ + matrix = HPDF_Array_New (view->mmgr); + if (!matrix) { + return HPDF_Error_GetCode (view->error); + } + + ret = HPDF_Array_AddReal (matrix, leftx); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, lefty); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, leftz); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, upx); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, upy); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, upz); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, viewx); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, viewy); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, viewz); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, transx); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, transy); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Array_AddReal (matrix, transz); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Dict_AddName (view, "MS", "M"); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Dict_Add (view, "C2W", matrix); + if (ret != HPDF_OK) goto failed; + + ret = HPDF_Dict_AddNumber (view, "CO", (HPDF_INT32)roo); + +failed: + if (ret != HPDF_OK) { + HPDF_Array_Free (matrix); + return ret; + } + return ret; +} + +HPDF_Dict HPDF_3DView_New( HPDF_MMgr mmgr, HPDF_Xref xref, HPDF_U3D u3d, const char *name) +{ + HPDF_STATUS ret = HPDF_OK; + HPDF_Dict view; + + HPDF_PTRACE ((" HPDF_3DView_New\n")); + + if (name == NULL || name[0] == '\0') { + return NULL; + } + + view = HPDF_Dict_New (mmgr); + if (!view) { + return NULL; + } + + if (HPDF_Xref_Add (xref, view) != HPDF_OK) + return NULL; + + ret = HPDF_Dict_AddName (view, "TYPE", "3DView"); + if (ret != HPDF_OK) { + HPDF_Dict_Free (view); + return NULL; + } + + ret = HPDF_Dict_Add (view, "XN", HPDF_String_New (mmgr, name, NULL)); + if (ret != HPDF_OK) { + HPDF_Dict_Free (view); + return NULL; + } + + ret = HPDF_Dict_Add (view, "IN", HPDF_String_New (mmgr, name, NULL)); + if (ret != HPDF_OK) { + HPDF_Dict_Free (view); + return NULL; + } + + ret = HPDF_U3D_Add3DView( u3d, view); + if (ret != HPDF_OK) { + HPDF_Dict_Free (view); + return NULL; + } + + return view; +} + + +HPDF_EXPORT(HPDF_STATUS) +HPDF_3DView_Add3DC3DMeasure(HPDF_Dict view, + HPDF_3DMeasure measure) +{ + + HPDF_STATUS ret = HPDF_OK; + HPDF_Array array; + void* a; + + a = HPDF_Dict_GetItem (view, "MA", HPDF_OCLASS_ARRAY); + + if ( a ) + { + array = (HPDF_Array)a; + } + else + { + array = HPDF_Array_New (view->mmgr); + if (!array) + return 0; + + if (HPDF_Dict_Add (view, "MA", array) != HPDF_OK) + return 0; + } + + ret = HPDF_Array_Add(array, measure); + + return ret; +} + + +HPDF_EXPORT(HPDF_JavaScript) HPDF_CreateJavaScript( HPDF_Doc pdf, const char *code ) +{ + HPDF_JavaScript javaScript; + int len ; + + HPDF_PTRACE ((" HPDF_CreateJavaScript\n")); + + javaScript = (HPDF_JavaScript) HPDF_DictStream_New(pdf->mmgr, pdf->xref); + if (!javaScript) { + return NULL; + } + + len = (HPDF_UINT)strlen(code); + if (HPDF_Stream_Write (javaScript->stream, (HPDF_BYTE *)code, len) != HPDF_OK) { + HPDF_Dict_Free(javaScript); + return NULL; + } + + return javaScript; +} + + +#undef normalize + diff --git a/PDF/src/hpdf_utils.c b/PDF/src/hpdf_utils.c index cd4ba345a..728da5a8b 100644 --- a/PDF/src/hpdf_utils.c +++ b/PDF/src/hpdf_utils.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.0 >> -- HPDF_utils.c + * << Haru Free PDF Library >> -- hpdf_utils.c * - * Copyright (c) 1999-2004 Takeshi Kanno + * URL: http://libharu.org + * + * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -24,7 +27,11 @@ HPDF_AToI (const char *s) HPDF_BOOL flg = HPDF_FALSE; HPDF_INT v = 0; - /* increment pointer until the character of 's' is not + if (!s) { + return 0; + } + + /* increment pointer until the charactor of 's' is not * white-space-charactor. */ while (*s) { @@ -60,7 +67,7 @@ HPDF_AToF (const char *s) HPDF_DOUBLE v; HPDF_INT tmp = 1; - /* increment pointer until the character of 's' is not + /* increment pointer until the charactor of 's' is not * white-space-charactor. */ while (*s) { @@ -129,7 +136,7 @@ HPDF_IToA (char *s, *t-- = 0; while (val > 0) { - *t = (char)(val % 10) + '0'; + *t = (char)((char)(val % 10) + '0'); val /= 10; t--; } @@ -158,7 +165,7 @@ HPDF_IToA2 (char *s, *u = 0; t = u - 1; while (val > 0 && t >= s) { - *t = (char)(val % 10) + '0'; + *t = (char)((char)(val % 10) + '0'); val /= 10; t--; } @@ -202,7 +209,7 @@ HPDF_FToA (char *s, /* process decimal part */ for (i = 0; i < 5; i++) { - *t = (char)(fpart_val % 10) + '0'; + *t = (char)((char)(fpart_val % 10) + '0'); fpart_val /= 10; t--; } @@ -214,7 +221,7 @@ HPDF_FToA (char *s, t--; while (int_val > 0) { - *t = (char)(int_val % 10) + '0'; + *t = (char)((char)(int_val % 10) + '0'); int_val /= 10; t--; } @@ -266,7 +273,7 @@ HPDF_StrCpy (char *out, *out = 0; - return out; + return (HPDF_BYTE *)out; } @@ -370,7 +377,7 @@ HPDF_StrStr (const char *s1, maxlen++; while (maxlen > 0) { - if (HPDF_MemCmp (s1, s2, len) == 0) + if (HPDF_MemCmp ((HPDF_BYTE *)s1, (HPDF_BYTE *)s2, len) == 0) return s1; s1++; diff --git a/PDF/src/hpdf_xref.c b/PDF/src/hpdf_xref.c index 205129487..8a88ca57f 100644 --- a/PDF/src/hpdf_xref.c +++ b/PDF/src/hpdf_xref.c @@ -1,7 +1,10 @@ /* - * << Haru Free PDF Library 2.0.3 >> -- hpdf_xref.h + * << Haru Free PDF Library >> -- hpdf_xref.c + * + * URL: http://libharu.org * * Copyright (c) 1999-2006 Takeshi Kanno + * Copyright (c) 2007-2009 Antony Dovgal * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -132,8 +135,8 @@ HPDF_Xref_Add (HPDF_Xref xref, header = (HPDF_Obj_Header *)obj; - if ((header->obj_id & HPDF_OTYPE_DIRECT) || - (header->obj_id & HPDF_OTYPE_INDIRECT)) + if (header->obj_id & HPDF_OTYPE_DIRECT || + header->obj_id & HPDF_OTYPE_INDIRECT) return HPDF_SetError(xref->error, HPDF_INVALID_OBJECT, 0); if (xref->entries->count >= HPDF_LIMIT_MAX_XREF_ELEMENT) { @@ -142,7 +145,7 @@ HPDF_Xref_Add (HPDF_Xref xref, } /* in the following, we have to dispose the object when an error is - * occurred. + * occured. */ entry = (HPDF_XrefEntry)HPDF_GetMem (xref->mmgr, @@ -276,7 +279,7 @@ HPDF_Xref_WriteToStream (HPDF_Xref xref, tmp_xref->addr = stream->size; pbuf = buf; - pbuf = HPDF_StrCpy (pbuf, "xref\012", eptr); + 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); @@ -295,7 +298,7 @@ HPDF_Xref_WriteToStream (HPDF_Xref xref, pbuf = HPDF_IToA2 (pbuf, entry->gen_no, HPDF_GEN_NO_LEN + 1); *pbuf++ = ' '; *pbuf++ = entry->entry_typ; - HPDF_StrCpy (pbuf, "\015\012", eptr); + HPDF_StrCpy (pbuf, "\015\012", eptr); /* Acrobat 8.15 requires both \r and \n here */ ret = HPDF_Stream_WriteStr (stream, buf); if (ret != HPDF_OK) return ret; diff --git a/PDF/src/pngget.c b/PDF/src/pngget.c index 0b2a69515..a0e90bb6a 100644 --- a/PDF/src/pngget.c +++ b/PDF/src/pngget.c @@ -896,6 +896,6 @@ png_get_user_height_max (png_structp png_ptr) return (png_ptr? png_ptr->user_height_max : 0); } #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ - + #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/PDF/src/pngmem.c b/PDF/src/pngmem.c index 8af365850..248060f38 100644 --- a/PDF/src/pngmem.c +++ b/PDF/src/pngmem.c @@ -327,7 +327,7 @@ png_free_default(png_structp png_ptr, png_voidp ptr) /* Allocate memory for a png_struct or a png_info. The malloc and memset can be replaced by a single call to calloc() if this is thought - to improve performance noticeably. */ + to improve performance noticably. */ png_voidp /* PRIVATE */ png_create_struct(int type) { @@ -337,7 +337,7 @@ png_create_struct(int type) /* Allocate memory for a png_struct or a png_info. The malloc and memset can be replaced by a single call to calloc() if this is thought - to improve performance noticeably. */ + to improve performance noticably. */ png_voidp /* PRIVATE */ png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr) { diff --git a/PDF/src/pngpread.c b/PDF/src/pngpread.c index c5ad75c33..8f4b7d179 100644 --- a/PDF/src/pngpread.c +++ b/PDF/src/pngpread.c @@ -1491,7 +1491,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 } #endif png_memcpy((png_charp)png_ptr->unknown_chunk.name, - (png_charp)png_ptr->chunk_name, + (png_charp)png_ptr->chunk_name, png_sizeof(png_ptr->unknown_chunk.name)); png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1]='\0'; diff --git a/PDF/src/pngrtran.c b/PDF/src/pngrtran.c index 96ca4a146..cda392154 100644 --- a/PDF/src/pngrtran.c +++ b/PDF/src/pngrtran.c @@ -1319,7 +1319,7 @@ png_do_read_transformations(png_structp png_ptr) if(rgb_error) { png_ptr->rgb_to_gray_status=1; - if((png_ptr->transformations & PNG_RGB_TO_GRAY) == + if((png_ptr->transformations & PNG_RGB_TO_GRAY) == PNG_RGB_TO_GRAY_WARN) png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); if((png_ptr->transformations & PNG_RGB_TO_GRAY) == @@ -3824,7 +3824,7 @@ png_do_expand(png_row_infop row_info, png_bytep row, dp = row + (row_info->rowbytes << 1) - 1; for (i = 0; i < row_width; i++) { - if (*(sp-1) == gray_high && *(sp) == gray_low) + if (*(sp-1) == gray_high && *(sp) == gray_low) { *dp-- = 0; *dp-- = 0; diff --git a/PDF/src/pngrutil.c b/PDF/src/pngrutil.c index dfb2365da..5e40aca48 100644 --- a/PDF/src/pngrutil.c +++ b/PDF/src/pngrutil.c @@ -2224,7 +2224,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } #endif png_memcpy((png_charp)png_ptr->unknown_chunk.name, - (png_charp)png_ptr->chunk_name, + (png_charp)png_ptr->chunk_name, png_sizeof(png_ptr->unknown_chunk.name)); png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1] = '\0'; png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length); diff --git a/PDF/src/pngset.c b/PDF/src/pngset.c index d598d4d1b..f8f9b7e3b 100644 --- a/PDF/src/pngset.c +++ b/PDF/src/pngset.c @@ -1040,8 +1040,8 @@ png_set_unknown_chunks(png_structp png_ptr, png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; png_unknown_chunkp from = unknowns + i; - png_memcpy((png_charp)to->name, - (png_charp)from->name, + png_memcpy((png_charp)to->name, + (png_charp)from->name, png_sizeof(from->name)); to->name[png_sizeof(to->name)-1] = '\0'; diff --git a/PDF/src/pngtest.c b/PDF/src/pngtest.c index 7abd8a2c5..dd2946bf4 100644 --- a/PDF/src/pngtest.c +++ b/PDF/src/pngtest.c @@ -1007,7 +1007,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) pointed to by png_convert_to_rfc1123() gets free'ed before we use it */ png_memcpy(tIME_string, - png_convert_to_rfc1123(read_ptr, mod_time), + png_convert_to_rfc1123(read_ptr, mod_time), png_sizeof(tIME_string)); tIME_string[png_sizeof(tIME_string)-1] = '\0'; tIME_chunk_present++; diff --git a/PDF/src/pngwutil.c b/PDF/src/pngwutil.c index 96bdfd7f8..fef38aef9 100644 --- a/PDF/src/pngwutil.c +++ b/PDF/src/pngwutil.c @@ -466,7 +466,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, interlace_type=PNG_INTERLACE_NONE; #endif - /* save off the relevant information */ + /* save off the relevent information */ png_ptr->bit_depth = (png_byte)bit_depth; png_ptr->color_type = (png_byte)color_type; png_ptr->interlaced = (png_byte)interlace_type; diff --git a/PDF/src/t4.h b/PDF/src/t4.h new file mode 100644 index 000000000..f306e155d --- /dev/null +++ b/PDF/src/t4.h @@ -0,0 +1,285 @@ +/* $Id: t4.h,v 1.20 2007/11/10 18:40:44 drolon Exp $ */ + +/* + * Copyright (c) 1988-1997 Sam Leffler + * Copyright (c) 1991-1997 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the names of + * Sam Leffler and Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Sam Leffler and Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#ifndef _T4_ +#define _T4_ +/* + * CCITT T.4 1D Huffman runlength codes and + * related definitions. Given the small sizes + * of these tables it does not seem + * worthwhile to make code & length 8 bits. + */ +typedef struct tableentry { + unsigned short length; /* bit length of g3 code */ + unsigned short code; /* g3 code */ + short runlen; /* run length in bits */ +} tableentry; + +#define EOL 0x001 /* EOL code value - 0000 0000 0000 1 */ + +/* status values returned instead of a run length */ +#define G3CODE_EOL -1 /* NB: ACT_EOL - ACT_WRUNT */ +#define G3CODE_INVALID -2 /* NB: ACT_INVALID - ACT_WRUNT */ +#define G3CODE_EOF -3 /* end of input data */ +#define G3CODE_INCOMP -4 /* incomplete run code */ + +/* + * Note that these tables are ordered such that the + * index into the table is known to be either the + * run length, or (run length / 64) + a fixed offset. + * + * NB: The G3CODE_INVALID entries are only used + * during state generation (see mkg3states.c). + */ +#ifdef G3CODES +const tableentry TIFFFaxWhiteCodes[] = { + { 8, 0x35, 0 }, /* 0011 0101 */ + { 6, 0x7, 1 }, /* 0001 11 */ + { 4, 0x7, 2 }, /* 0111 */ + { 4, 0x8, 3 }, /* 1000 */ + { 4, 0xB, 4 }, /* 1011 */ + { 4, 0xC, 5 }, /* 1100 */ + { 4, 0xE, 6 }, /* 1110 */ + { 4, 0xF, 7 }, /* 1111 */ + { 5, 0x13, 8 }, /* 1001 1 */ + { 5, 0x14, 9 }, /* 1010 0 */ + { 5, 0x7, 10 }, /* 0011 1 */ + { 5, 0x8, 11 }, /* 0100 0 */ + { 6, 0x8, 12 }, /* 0010 00 */ + { 6, 0x3, 13 }, /* 0000 11 */ + { 6, 0x34, 14 }, /* 1101 00 */ + { 6, 0x35, 15 }, /* 1101 01 */ + { 6, 0x2A, 16 }, /* 1010 10 */ + { 6, 0x2B, 17 }, /* 1010 11 */ + { 7, 0x27, 18 }, /* 0100 111 */ + { 7, 0xC, 19 }, /* 0001 100 */ + { 7, 0x8, 20 }, /* 0001 000 */ + { 7, 0x17, 21 }, /* 0010 111 */ + { 7, 0x3, 22 }, /* 0000 011 */ + { 7, 0x4, 23 }, /* 0000 100 */ + { 7, 0x28, 24 }, /* 0101 000 */ + { 7, 0x2B, 25 }, /* 0101 011 */ + { 7, 0x13, 26 }, /* 0010 011 */ + { 7, 0x24, 27 }, /* 0100 100 */ + { 7, 0x18, 28 }, /* 0011 000 */ + { 8, 0x2, 29 }, /* 0000 0010 */ + { 8, 0x3, 30 }, /* 0000 0011 */ + { 8, 0x1A, 31 }, /* 0001 1010 */ + { 8, 0x1B, 32 }, /* 0001 1011 */ + { 8, 0x12, 33 }, /* 0001 0010 */ + { 8, 0x13, 34 }, /* 0001 0011 */ + { 8, 0x14, 35 }, /* 0001 0100 */ + { 8, 0x15, 36 }, /* 0001 0101 */ + { 8, 0x16, 37 }, /* 0001 0110 */ + { 8, 0x17, 38 }, /* 0001 0111 */ + { 8, 0x28, 39 }, /* 0010 1000 */ + { 8, 0x29, 40 }, /* 0010 1001 */ + { 8, 0x2A, 41 }, /* 0010 1010 */ + { 8, 0x2B, 42 }, /* 0010 1011 */ + { 8, 0x2C, 43 }, /* 0010 1100 */ + { 8, 0x2D, 44 }, /* 0010 1101 */ + { 8, 0x4, 45 }, /* 0000 0100 */ + { 8, 0x5, 46 }, /* 0000 0101 */ + { 8, 0xA, 47 }, /* 0000 1010 */ + { 8, 0xB, 48 }, /* 0000 1011 */ + { 8, 0x52, 49 }, /* 0101 0010 */ + { 8, 0x53, 50 }, /* 0101 0011 */ + { 8, 0x54, 51 }, /* 0101 0100 */ + { 8, 0x55, 52 }, /* 0101 0101 */ + { 8, 0x24, 53 }, /* 0010 0100 */ + { 8, 0x25, 54 }, /* 0010 0101 */ + { 8, 0x58, 55 }, /* 0101 1000 */ + { 8, 0x59, 56 }, /* 0101 1001 */ + { 8, 0x5A, 57 }, /* 0101 1010 */ + { 8, 0x5B, 58 }, /* 0101 1011 */ + { 8, 0x4A, 59 }, /* 0100 1010 */ + { 8, 0x4B, 60 }, /* 0100 1011 */ + { 8, 0x32, 61 }, /* 0011 0010 */ + { 8, 0x33, 62 }, /* 0011 0011 */ + { 8, 0x34, 63 }, /* 0011 0100 */ + { 5, 0x1B, 64 }, /* 1101 1 */ + { 5, 0x12, 128 }, /* 1001 0 */ + { 6, 0x17, 192 }, /* 0101 11 */ + { 7, 0x37, 256 }, /* 0110 111 */ + { 8, 0x36, 320 }, /* 0011 0110 */ + { 8, 0x37, 384 }, /* 0011 0111 */ + { 8, 0x64, 448 }, /* 0110 0100 */ + { 8, 0x65, 512 }, /* 0110 0101 */ + { 8, 0x68, 576 }, /* 0110 1000 */ + { 8, 0x67, 640 }, /* 0110 0111 */ + { 9, 0xCC, 704 }, /* 0110 0110 0 */ + { 9, 0xCD, 768 }, /* 0110 0110 1 */ + { 9, 0xD2, 832 }, /* 0110 1001 0 */ + { 9, 0xD3, 896 }, /* 0110 1001 1 */ + { 9, 0xD4, 960 }, /* 0110 1010 0 */ + { 9, 0xD5, 1024 }, /* 0110 1010 1 */ + { 9, 0xD6, 1088 }, /* 0110 1011 0 */ + { 9, 0xD7, 1152 }, /* 0110 1011 1 */ + { 9, 0xD8, 1216 }, /* 0110 1100 0 */ + { 9, 0xD9, 1280 }, /* 0110 1100 1 */ + { 9, 0xDA, 1344 }, /* 0110 1101 0 */ + { 9, 0xDB, 1408 }, /* 0110 1101 1 */ + { 9, 0x98, 1472 }, /* 0100 1100 0 */ + { 9, 0x99, 1536 }, /* 0100 1100 1 */ + { 9, 0x9A, 1600 }, /* 0100 1101 0 */ + { 6, 0x18, 1664 }, /* 0110 00 */ + { 9, 0x9B, 1728 }, /* 0100 1101 1 */ + { 11, 0x8, 1792 }, /* 0000 0001 000 */ + { 11, 0xC, 1856 }, /* 0000 0001 100 */ + { 11, 0xD, 1920 }, /* 0000 0001 101 */ + { 12, 0x12, 1984 }, /* 0000 0001 0010 */ + { 12, 0x13, 2048 }, /* 0000 0001 0011 */ + { 12, 0x14, 2112 }, /* 0000 0001 0100 */ + { 12, 0x15, 2176 }, /* 0000 0001 0101 */ + { 12, 0x16, 2240 }, /* 0000 0001 0110 */ + { 12, 0x17, 2304 }, /* 0000 0001 0111 */ + { 12, 0x1C, 2368 }, /* 0000 0001 1100 */ + { 12, 0x1D, 2432 }, /* 0000 0001 1101 */ + { 12, 0x1E, 2496 }, /* 0000 0001 1110 */ + { 12, 0x1F, 2560 }, /* 0000 0001 1111 */ + { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */ + { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */ + { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */ + { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */ + { 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */ +}; + +const tableentry TIFFFaxBlackCodes[] = { + { 10, 0x37, 0 }, /* 0000 1101 11 */ + { 3, 0x2, 1 }, /* 010 */ + { 2, 0x3, 2 }, /* 11 */ + { 2, 0x2, 3 }, /* 10 */ + { 3, 0x3, 4 }, /* 011 */ + { 4, 0x3, 5 }, /* 0011 */ + { 4, 0x2, 6 }, /* 0010 */ + { 5, 0x3, 7 }, /* 0001 1 */ + { 6, 0x5, 8 }, /* 0001 01 */ + { 6, 0x4, 9 }, /* 0001 00 */ + { 7, 0x4, 10 }, /* 0000 100 */ + { 7, 0x5, 11 }, /* 0000 101 */ + { 7, 0x7, 12 }, /* 0000 111 */ + { 8, 0x4, 13 }, /* 0000 0100 */ + { 8, 0x7, 14 }, /* 0000 0111 */ + { 9, 0x18, 15 }, /* 0000 1100 0 */ + { 10, 0x17, 16 }, /* 0000 0101 11 */ + { 10, 0x18, 17 }, /* 0000 0110 00 */ + { 10, 0x8, 18 }, /* 0000 0010 00 */ + { 11, 0x67, 19 }, /* 0000 1100 111 */ + { 11, 0x68, 20 }, /* 0000 1101 000 */ + { 11, 0x6C, 21 }, /* 0000 1101 100 */ + { 11, 0x37, 22 }, /* 0000 0110 111 */ + { 11, 0x28, 23 }, /* 0000 0101 000 */ + { 11, 0x17, 24 }, /* 0000 0010 111 */ + { 11, 0x18, 25 }, /* 0000 0011 000 */ + { 12, 0xCA, 26 }, /* 0000 1100 1010 */ + { 12, 0xCB, 27 }, /* 0000 1100 1011 */ + { 12, 0xCC, 28 }, /* 0000 1100 1100 */ + { 12, 0xCD, 29 }, /* 0000 1100 1101 */ + { 12, 0x68, 30 }, /* 0000 0110 1000 */ + { 12, 0x69, 31 }, /* 0000 0110 1001 */ + { 12, 0x6A, 32 }, /* 0000 0110 1010 */ + { 12, 0x6B, 33 }, /* 0000 0110 1011 */ + { 12, 0xD2, 34 }, /* 0000 1101 0010 */ + { 12, 0xD3, 35 }, /* 0000 1101 0011 */ + { 12, 0xD4, 36 }, /* 0000 1101 0100 */ + { 12, 0xD5, 37 }, /* 0000 1101 0101 */ + { 12, 0xD6, 38 }, /* 0000 1101 0110 */ + { 12, 0xD7, 39 }, /* 0000 1101 0111 */ + { 12, 0x6C, 40 }, /* 0000 0110 1100 */ + { 12, 0x6D, 41 }, /* 0000 0110 1101 */ + { 12, 0xDA, 42 }, /* 0000 1101 1010 */ + { 12, 0xDB, 43 }, /* 0000 1101 1011 */ + { 12, 0x54, 44 }, /* 0000 0101 0100 */ + { 12, 0x55, 45 }, /* 0000 0101 0101 */ + { 12, 0x56, 46 }, /* 0000 0101 0110 */ + { 12, 0x57, 47 }, /* 0000 0101 0111 */ + { 12, 0x64, 48 }, /* 0000 0110 0100 */ + { 12, 0x65, 49 }, /* 0000 0110 0101 */ + { 12, 0x52, 50 }, /* 0000 0101 0010 */ + { 12, 0x53, 51 }, /* 0000 0101 0011 */ + { 12, 0x24, 52 }, /* 0000 0010 0100 */ + { 12, 0x37, 53 }, /* 0000 0011 0111 */ + { 12, 0x38, 54 }, /* 0000 0011 1000 */ + { 12, 0x27, 55 }, /* 0000 0010 0111 */ + { 12, 0x28, 56 }, /* 0000 0010 1000 */ + { 12, 0x58, 57 }, /* 0000 0101 1000 */ + { 12, 0x59, 58 }, /* 0000 0101 1001 */ + { 12, 0x2B, 59 }, /* 0000 0010 1011 */ + { 12, 0x2C, 60 }, /* 0000 0010 1100 */ + { 12, 0x5A, 61 }, /* 0000 0101 1010 */ + { 12, 0x66, 62 }, /* 0000 0110 0110 */ + { 12, 0x67, 63 }, /* 0000 0110 0111 */ + { 10, 0xF, 64 }, /* 0000 0011 11 */ + { 12, 0xC8, 128 }, /* 0000 1100 1000 */ + { 12, 0xC9, 192 }, /* 0000 1100 1001 */ + { 12, 0x5B, 256 }, /* 0000 0101 1011 */ + { 12, 0x33, 320 }, /* 0000 0011 0011 */ + { 12, 0x34, 384 }, /* 0000 0011 0100 */ + { 12, 0x35, 448 }, /* 0000 0011 0101 */ + { 13, 0x6C, 512 }, /* 0000 0011 0110 0 */ + { 13, 0x6D, 576 }, /* 0000 0011 0110 1 */ + { 13, 0x4A, 640 }, /* 0000 0010 0101 0 */ + { 13, 0x4B, 704 }, /* 0000 0010 0101 1 */ + { 13, 0x4C, 768 }, /* 0000 0010 0110 0 */ + { 13, 0x4D, 832 }, /* 0000 0010 0110 1 */ + { 13, 0x72, 896 }, /* 0000 0011 1001 0 */ + { 13, 0x73, 960 }, /* 0000 0011 1001 1 */ + { 13, 0x74, 1024 }, /* 0000 0011 1010 0 */ + { 13, 0x75, 1088 }, /* 0000 0011 1010 1 */ + { 13, 0x76, 1152 }, /* 0000 0011 1011 0 */ + { 13, 0x77, 1216 }, /* 0000 0011 1011 1 */ + { 13, 0x52, 1280 }, /* 0000 0010 1001 0 */ + { 13, 0x53, 1344 }, /* 0000 0010 1001 1 */ + { 13, 0x54, 1408 }, /* 0000 0010 1010 0 */ + { 13, 0x55, 1472 }, /* 0000 0010 1010 1 */ + { 13, 0x5A, 1536 }, /* 0000 0010 1101 0 */ + { 13, 0x5B, 1600 }, /* 0000 0010 1101 1 */ + { 13, 0x64, 1664 }, /* 0000 0011 0010 0 */ + { 13, 0x65, 1728 }, /* 0000 0011 0010 1 */ + { 11, 0x8, 1792 }, /* 0000 0001 000 */ + { 11, 0xC, 1856 }, /* 0000 0001 100 */ + { 11, 0xD, 1920 }, /* 0000 0001 101 */ + { 12, 0x12, 1984 }, /* 0000 0001 0010 */ + { 12, 0x13, 2048 }, /* 0000 0001 0011 */ + { 12, 0x14, 2112 }, /* 0000 0001 0100 */ + { 12, 0x15, 2176 }, /* 0000 0001 0101 */ + { 12, 0x16, 2240 }, /* 0000 0001 0110 */ + { 12, 0x17, 2304 }, /* 0000 0001 0111 */ + { 12, 0x1C, 2368 }, /* 0000 0001 1100 */ + { 12, 0x1D, 2432 }, /* 0000 0001 1101 */ + { 12, 0x1E, 2496 }, /* 0000 0001 1110 */ + { 12, 0x1F, 2560 }, /* 0000 0001 1111 */ + { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */ + { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */ + { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */ + { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */ + { 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */ +}; +#else +extern const tableentry TIFFFaxWhiteCodes[]; +extern const tableentry TIFFFaxBlackCodes[]; +#endif +#endif /* _T4_ */ diff --git a/PDF/testsuite/CMakeLists.txt b/PDF/testsuite/CMakeLists.txt index 6ccf6b057..79ca02515 100644 --- a/PDF/testsuite/CMakeLists.txt +++ b/PDF/testsuite/CMakeLists.txt @@ -14,4 +14,4 @@ POCO_SOURCES_AUTO_PLAT( TEST_SRCS OFF add_executable( ${TESTUNIT} ${TEST_SRCS} ) add_test(NAME ${LIBNAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${TESTUNIT} -all) -target_link_libraries( ${TESTUNIT} PocoPDF PocoFoundation PocoCppUnit ) +target_link_libraries( ${TESTUNIT} PocoPDF PocoFoundation CppUnit ) diff --git a/PDF/testsuite/Makefile b/PDF/testsuite/Makefile index 7b73890b6..0c66dedc9 100644 --- a/PDF/testsuite/Makefile +++ b/PDF/testsuite/Makefile @@ -10,6 +10,6 @@ objects = PDFTestSuite Driver PDFTest target = testrunner target_version = 1 -target_libs = PocoPDF PocoFoundation PocoCppUnit +target_libs = PocoPDF PocoFoundation CppUnit include $(POCO_BASE)/build/rules/exec diff --git a/PDF/testsuite/TestSuite.progen b/PDF/testsuite/TestSuite.progen deleted file mode 100644 index 682c09fae..000000000 --- a/PDF/testsuite/TestSuite.progen +++ /dev/null @@ -1,9 +0,0 @@ -vc.project.guid = 24134877-368D-11DB-9FBC-00123FC423B5 -vc.project.name = TestSuite -vc.project.target = TestSuite -vc.project.type = testsuite -vc.project.pocobase = ..\\.. -vc.project.platforms = Win32, x64 -vc.project.configurations = debug_shared, release_shared, debug_static_mt, release_static_mt, debug_static_md, release_static_md -vc.project.prototype = TestSuite_vs90.vcproj -vc.project.compiler.include = ..\\..\\Foundation\\include diff --git a/PDF/testsuite/TestSuite_vs140.vcxproj b/PDF/testsuite/TestSuite_vs140.vcxproj index 35718961d..e855fcaf6 100644 --- a/PDF/testsuite/TestSuite_vs140.vcxproj +++ b/PDF/testsuite/TestSuite_vs140.vcxproj @@ -142,7 +142,7 @@ Default - PocoCppUnitd.lib;%(AdditionalDependencies) + CppUnitd.lib;%(AdditionalDependencies) bin\TestSuited.exe ..\..\lib;%(AdditionalLibraryDirectories) true @@ -173,7 +173,7 @@ Default - PocoCppUnit.lib;%(AdditionalDependencies) + CppUnit.lib;%(AdditionalDependencies) bin\TestSuite.exe ..\..\lib;%(AdditionalLibraryDirectories) false @@ -202,7 +202,7 @@ Default - PocoCppUnitmtd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmtd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin\static_mt\TestSuited.exe ..\..\lib;%(AdditionalLibraryDirectories) true @@ -233,7 +233,7 @@ Default - PocoCppUnitmt.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmt.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin\static_mt\TestSuite.exe ..\..\lib;%(AdditionalLibraryDirectories) false @@ -262,7 +262,7 @@ Default - PocoCppUnitmdd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmdd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin\static_md\TestSuited.exe ..\..\lib;%(AdditionalLibraryDirectories) true @@ -293,7 +293,7 @@ Default - PocoCppUnitmd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin\static_md\TestSuite.exe ..\..\lib;%(AdditionalLibraryDirectories) false diff --git a/PDF/testsuite/TestSuite_vs140.vcxproj.filters b/PDF/testsuite/TestSuite_vs140.vcxproj.filters index 9942bca40..e469bc918 100644 --- a/PDF/testsuite/TestSuite_vs140.vcxproj.filters +++ b/PDF/testsuite/TestSuite_vs140.vcxproj.filters @@ -2,28 +2,28 @@ - {25224422-bc70-4739-b840-3e08a99ec929} + {49cee8e1-befc-4292-b5de-22410187a085} - {e22606c8-c256-4d05-9968-d184c3399837} + {efa63a14-8941-42c2-a23c-9aa4076bfdac} - {1b7784a8-92b7-4ce7-b3c7-cef91500ae09} + {39121e4b-82f7-44eb-8558-3784d8a2b81e} - {138815ba-9e02-43f5-8843-1acf933ed81a} + {636cf943-9472-4f68-9e1e-827308d7a9fd} - {bd0629a8-9245-4be4-8f90-ad22ffdb180f} + {dd2e56ad-cc6d-4755-98be-6d091ade745b} - {e7e8908b-8c3b-4aa7-a4cf-84f183606941} + {365cf1a4-c73c-43da-bea5-a8dd5d0d22d2} - {ee919c41-6966-4205-a6e2-1b5e31023006} + {8a4c5937-c511-4d90-a94d-7992e302159a} - {af3de670-5332-47d0-bbab-ed080d716ef4} + {3ab94302-7103-431f-a3bf-6e77171d0c27} diff --git a/PDF/testsuite/TestSuite_vs150.vcxproj b/PDF/testsuite/TestSuite_vs150.vcxproj index df0731671..2177fe5d7 100644 --- a/PDF/testsuite/TestSuite_vs150.vcxproj +++ b/PDF/testsuite/TestSuite_vs150.vcxproj @@ -142,7 +142,7 @@ Default - PocoCppUnitd.lib;%(AdditionalDependencies) + CppUnitd.lib;%(AdditionalDependencies) bin\TestSuited.exe ..\..\lib;%(AdditionalLibraryDirectories) true @@ -173,7 +173,7 @@ Default - PocoCppUnit.lib;%(AdditionalDependencies) + CppUnit.lib;%(AdditionalDependencies) bin\TestSuite.exe ..\..\lib;%(AdditionalLibraryDirectories) false @@ -202,7 +202,7 @@ Default - PocoCppUnitmtd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmtd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin\static_mt\TestSuited.exe ..\..\lib;%(AdditionalLibraryDirectories) true @@ -233,7 +233,7 @@ Default - PocoCppUnitmt.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmt.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin\static_mt\TestSuite.exe ..\..\lib;%(AdditionalLibraryDirectories) false @@ -262,7 +262,7 @@ Default - PocoCppUnitmdd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmdd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin\static_md\TestSuited.exe ..\..\lib;%(AdditionalLibraryDirectories) true @@ -293,7 +293,7 @@ Default - PocoCppUnitmd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin\static_md\TestSuite.exe ..\..\lib;%(AdditionalLibraryDirectories) false diff --git a/PDF/testsuite/TestSuite_vs150.vcxproj.filters b/PDF/testsuite/TestSuite_vs150.vcxproj.filters index 9942bca40..e469bc918 100644 --- a/PDF/testsuite/TestSuite_vs150.vcxproj.filters +++ b/PDF/testsuite/TestSuite_vs150.vcxproj.filters @@ -2,28 +2,28 @@ - {25224422-bc70-4739-b840-3e08a99ec929} + {49cee8e1-befc-4292-b5de-22410187a085} - {e22606c8-c256-4d05-9968-d184c3399837} + {efa63a14-8941-42c2-a23c-9aa4076bfdac} - {1b7784a8-92b7-4ce7-b3c7-cef91500ae09} + {39121e4b-82f7-44eb-8558-3784d8a2b81e} - {138815ba-9e02-43f5-8843-1acf933ed81a} + {636cf943-9472-4f68-9e1e-827308d7a9fd} - {bd0629a8-9245-4be4-8f90-ad22ffdb180f} + {dd2e56ad-cc6d-4755-98be-6d091ade745b} - {e7e8908b-8c3b-4aa7-a4cf-84f183606941} + {365cf1a4-c73c-43da-bea5-a8dd5d0d22d2} - {ee919c41-6966-4205-a6e2-1b5e31023006} + {8a4c5937-c511-4d90-a94d-7992e302159a} - {af3de670-5332-47d0-bbab-ed080d716ef4} + {3ab94302-7103-431f-a3bf-6e77171d0c27} diff --git a/PDF/testsuite/TestSuite_x64_vs140.vcxproj b/PDF/testsuite/TestSuite_x64_vs140.vcxproj index aa964aa2a..21581cf88 100644 --- a/PDF/testsuite/TestSuite_x64_vs140.vcxproj +++ b/PDF/testsuite/TestSuite_x64_vs140.vcxproj @@ -142,7 +142,7 @@ Default - PocoCppUnitd.lib;%(AdditionalDependencies) + CppUnitd.lib;%(AdditionalDependencies) bin64\TestSuited.exe ..\..\lib64;%(AdditionalLibraryDirectories) true @@ -173,7 +173,7 @@ Default - PocoCppUnit.lib;%(AdditionalDependencies) + CppUnit.lib;%(AdditionalDependencies) bin64\TestSuite.exe ..\..\lib64;%(AdditionalLibraryDirectories) false @@ -202,7 +202,7 @@ Default - PocoCppUnitmtd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmtd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin64\static_mt\TestSuited.exe ..\..\lib64;%(AdditionalLibraryDirectories) true @@ -233,7 +233,7 @@ Default - PocoCppUnitmt.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmt.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin64\static_mt\TestSuite.exe ..\..\lib64;%(AdditionalLibraryDirectories) false @@ -262,7 +262,7 @@ Default - PocoCppUnitmdd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmdd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin64\static_md\TestSuited.exe ..\..\lib64;%(AdditionalLibraryDirectories) true @@ -293,7 +293,7 @@ Default - PocoCppUnitmd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin64\static_md\TestSuite.exe ..\..\lib64;%(AdditionalLibraryDirectories) false diff --git a/PDF/testsuite/TestSuite_x64_vs140.vcxproj.filters b/PDF/testsuite/TestSuite_x64_vs140.vcxproj.filters index a56964be3..83935d411 100644 --- a/PDF/testsuite/TestSuite_x64_vs140.vcxproj.filters +++ b/PDF/testsuite/TestSuite_x64_vs140.vcxproj.filters @@ -2,28 +2,28 @@ - {46aeef0c-236d-4b80-b19a-6d95d6018adf} + {ff51531f-0e9c-4846-bb61-d374b91cba75} - {0ee1a14c-e5b4-42ef-a22a-94bc7e084a8f} + {0f2e5c9e-a179-40de-8ab5-b94b1398a39b} - {062ef8fd-0428-43cd-92dd-1305cec8efaa} + {00734402-fb83-4814-8e5a-4bfd862224f6} - {c763312c-d2e8-4d01-9db2-5cfacc7e323e} + {10b3aae1-bd2b-427d-8415-260439d74543} - {205c9a02-4115-460d-9af3-1ec93d338655} + {4edadfd7-bd68-4701-ae71-800eb9851118} - {b9ddae48-eca1-47db-b62c-f2728e4720d9} + {f869f09e-4a61-48e1-9f5c-1d7f00e1f642} - {516d20f3-9515-4715-aaad-d142294945af} + {29acf815-1b49-4b1e-a346-a99929eadd32} - {b601a474-682a-40e0-849f-602bbbdac6e2} + {2bb4acb2-2dea-487a-bd87-70428ebff560} diff --git a/PDF/testsuite/TestSuite_x64_vs150.vcxproj b/PDF/testsuite/TestSuite_x64_vs150.vcxproj index 97e3c19e8..bea89ab13 100644 --- a/PDF/testsuite/TestSuite_x64_vs150.vcxproj +++ b/PDF/testsuite/TestSuite_x64_vs150.vcxproj @@ -142,7 +142,7 @@ Default - PocoCppUnitd.lib;%(AdditionalDependencies) + CppUnitd.lib;%(AdditionalDependencies) bin64\TestSuited.exe ..\..\lib64;%(AdditionalLibraryDirectories) true @@ -173,7 +173,7 @@ Default - PocoCppUnit.lib;%(AdditionalDependencies) + CppUnit.lib;%(AdditionalDependencies) bin64\TestSuite.exe ..\..\lib64;%(AdditionalLibraryDirectories) false @@ -202,7 +202,7 @@ Default - PocoCppUnitmtd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmtd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin64\static_mt\TestSuited.exe ..\..\lib64;%(AdditionalLibraryDirectories) true @@ -233,7 +233,7 @@ Default - PocoCppUnitmt.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmt.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin64\static_mt\TestSuite.exe ..\..\lib64;%(AdditionalLibraryDirectories) false @@ -262,7 +262,7 @@ Default - PocoCppUnitmdd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmdd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin64\static_md\TestSuited.exe ..\..\lib64;%(AdditionalLibraryDirectories) true @@ -293,7 +293,7 @@ Default - PocoCppUnitmd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) + CppUnitmd.lib;iphlpapi.lib;winmm.lib;%(AdditionalDependencies) bin64\static_md\TestSuite.exe ..\..\lib64;%(AdditionalLibraryDirectories) false diff --git a/PDF/testsuite/TestSuite_x64_vs150.vcxproj.filters b/PDF/testsuite/TestSuite_x64_vs150.vcxproj.filters index a56964be3..83935d411 100644 --- a/PDF/testsuite/TestSuite_x64_vs150.vcxproj.filters +++ b/PDF/testsuite/TestSuite_x64_vs150.vcxproj.filters @@ -2,28 +2,28 @@ - {46aeef0c-236d-4b80-b19a-6d95d6018adf} + {ff51531f-0e9c-4846-bb61-d374b91cba75} - {0ee1a14c-e5b4-42ef-a22a-94bc7e084a8f} + {0f2e5c9e-a179-40de-8ab5-b94b1398a39b} - {062ef8fd-0428-43cd-92dd-1305cec8efaa} + {00734402-fb83-4814-8e5a-4bfd862224f6} - {c763312c-d2e8-4d01-9db2-5cfacc7e323e} + {10b3aae1-bd2b-427d-8415-260439d74543} - {205c9a02-4115-460d-9af3-1ec93d338655} + {4edadfd7-bd68-4701-ae71-800eb9851118} - {b9ddae48-eca1-47db-b62c-f2728e4720d9} + {f869f09e-4a61-48e1-9f5c-1d7f00e1f642} - {516d20f3-9515-4715-aaad-d142294945af} + {29acf815-1b49-4b1e-a346-a99929eadd32} - {b601a474-682a-40e0-849f-602bbbdac6e2} + {2bb4acb2-2dea-487a-bd87-70428ebff560} diff --git a/PDF/testsuite/build.gradle b/PDF/testsuite/build.gradle new file mode 100644 index 000000000..725c1d1bd --- /dev/null +++ b/PDF/testsuite/build.gradle @@ -0,0 +1,61 @@ +import org.gradle.nativeplatform.test.cppunit.CppUnitTestSuiteSpec + +model { + components { + withType(NativeComponentSpec) { + binaries.withType(NativeBinarySpec) { + if (buildType == buildTypes.debug) { + if (it instanceof NativeExecutableBinarySpec) { + executable.file = toLocalBin(appendDebugSuffix(executable.file), targetPlatform) + } + } else + if (buildType == buildTypes.release) { + if (it instanceof NativeExecutableBinarySpec) { + executable.file = toLocalBin(executable.file, targetPlatform) + } + } + } + } + TestSuite(NativeLibrarySpec) { + sources { + cpp { + source { + srcDir 'src' + include '**/*.cpp' + exclude '*Driver.cpp' + } + exportedHeaders { + srcDir 'src' + } + lib project: ':CppUnit', library: 'CppUnit' + lib project: ':Foundation', library: 'Foundation' + } + } + } + } + testSuites { + PDFTestSuite(org.gradle.nativeplatform.test.cppunit.CppUnitTestSuiteSpec) { + testing $.components.TestSuite + } + } + binaries { + withType(org.gradle.nativeplatform.test.cppunit.CppUnitTestSuiteBinarySpec) { + lib project: ':CppUnit', library: 'CppUnit', linkage: 'shared' + if (toolChain in VisualCpp) { + if (buildType == buildTypes.debug) { + cCompiler.args "/MDd" + cppCompiler.args "/MDd" + } else + if (buildType == buildTypes.release) { + cCompiler.args "/MD" + cppCompiler.args "/MD" + } else { + throw new GradleException("Unknown buildType" + buildType) + } + } + if (toolChain in Gcc) { + } + } + } +} +task testsuite { dependsOn "assemble" } diff --git a/PDF/testsuite/src/Driver.cpp b/PDF/testsuite/src/Driver.cpp index 1e554694b..44d1a3ffd 100644 --- a/PDF/testsuite/src/Driver.cpp +++ b/PDF/testsuite/src/Driver.cpp @@ -10,7 +10,7 @@ // -#include "Poco/CppUnit/TestRunner.h" +#include "CppUnit/TestRunner.h" #include "PDFTestSuite.h" diff --git a/PDF/testsuite/src/PDFTest.cpp b/PDF/testsuite/src/PDFTest.cpp index 93f0a1051..09b14154c 100644 --- a/PDF/testsuite/src/PDFTest.cpp +++ b/PDF/testsuite/src/PDFTest.cpp @@ -9,8 +9,8 @@ #include "PDFTest.h" -#include "Poco/CppUnit/TestCaller.h" -#include "Poco/CppUnit/TestSuite.h" +#include "CppUnit/TestCaller.h" +#include "CppUnit/TestSuite.h" PDFTest::PDFTest(const std::string& name): CppUnit::TestCase(name) diff --git a/PDF/testsuite/src/PDFTest.h b/PDF/testsuite/src/PDFTest.h index 1fdbbeb7c..9075cba1b 100644 --- a/PDF/testsuite/src/PDFTest.h +++ b/PDF/testsuite/src/PDFTest.h @@ -15,7 +15,7 @@ #include "Poco/PDF/PDF.h" -#include "Poco/CppUnit/TestCase.h" +#include "CppUnit/TestCase.h" class PDFTest: public CppUnit::TestCase diff --git a/PDF/testsuite/src/PDFTestSuite.h b/PDF/testsuite/src/PDFTestSuite.h index 1bbb35c5d..779302794 100644 --- a/PDF/testsuite/src/PDFTestSuite.h +++ b/PDF/testsuite/src/PDFTestSuite.h @@ -14,7 +14,7 @@ #define PDFTestSuite_INCLUDED -#include "Poco/CppUnit/TestSuite.h" +#include "CppUnit/TestSuite.h" class PDFTestSuite