├── .editorconfig ├── .gitattributes ├── .gitignore ├── C ├── hpdf.h ├── hpdf_annotation.h ├── hpdf_catalog.h ├── hpdf_conf.h ├── hpdf_config.h ├── hpdf_consts.h ├── hpdf_destination.h ├── hpdf_doc.h ├── hpdf_encoder.h ├── hpdf_encrypt.h ├── hpdf_encryptdict.h ├── hpdf_error.h ├── hpdf_ext_gstate.h ├── hpdf_font.h ├── hpdf_fontdef.h ├── hpdf_gstate.h ├── hpdf_image.h ├── hpdf_info.h ├── hpdf_list.h ├── hpdf_mmgr.h ├── hpdf_namedict.h ├── hpdf_objects.h ├── hpdf_outline.h ├── hpdf_page_label.h ├── hpdf_pages.h ├── hpdf_pdfa.h ├── hpdf_streams.h ├── hpdf_types.h ├── hpdf_utils.h └── hpdf_version.h ├── LICENSE ├── README.md ├── bump-version.sh ├── doc └── mm2dot.gnumeric ├── dub.sdl ├── dub.selections.json ├── examples ├── dash │ ├── app.d │ ├── dub.sdl │ └── makefile ├── encoding_list │ ├── app.d │ ├── dub.sdl │ ├── makefile │ └── type1 │ │ ├── COPYING │ │ ├── README │ │ ├── a010013l.afm │ │ └── a010013l.pfb ├── error_handling │ ├── app.d │ ├── dub.sdl │ └── makefile ├── font │ ├── app.d │ ├── dub.sdl │ └── makefile ├── grid_sheet │ ├── app.d │ ├── dub.sdl │ └── makefile ├── hello │ ├── app.d │ ├── dub.sdl │ └── makefile ├── image │ ├── app.d │ ├── dub.sdl │ ├── makefile │ └── pngsuite │ │ ├── README │ │ ├── basn0g01.png │ │ ├── basn0g02.png │ │ ├── basn0g04.png │ │ ├── basn0g08.png │ │ ├── basn0g16.png │ │ ├── basn2c08.png │ │ ├── basn2c16.png │ │ ├── basn3p01.png │ │ ├── basn3p02.png │ │ ├── basn3p04.png │ │ ├── basn3p08.png │ │ ├── basn4a08.png │ │ ├── basn4a16.png │ │ ├── basn6a08.png │ │ ├── basn6a16.png │ │ └── maskimage.png ├── line │ ├── app.d │ ├── dub.sdl │ └── makefile ├── line_cmyk │ ├── app.d │ └── dub.sdl └── table │ ├── app.d │ └── dub.sdl ├── lib └── libhpdf.lib ├── makefile └── src └── harud ├── annotation.d ├── c ├── capi.d ├── consts.d └── package.d ├── destination.d ├── doc.d ├── encoder.d ├── error.d ├── extension.d ├── font.d ├── haruobject.d ├── image.d ├── outline.d ├── package.d ├── page.d ├── semver.d ├── table.d ├── types.d └── util.d /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.d] 2 | dfmt_align_switch_statements = false 3 | # allman, otbs, or stroustrup 4 | dfmt_brace_style = otbs 5 | #dfmt_brace_style = stroustrup 6 | dfmt_outdent_attributes = true 7 | dfmt_outdent_labels = true 8 | dfmt_soft_max_line_length = 120 9 | dfmt_space_after_cast = false 10 | dfmt_space_after_keywords = true 11 | dfmt_split_operator_at_line_end = false 12 | 13 | trim_trailing_whitespace = true 14 | end_of_line = lf 15 | indent_size = 3 16 | indent_style = space 17 | insert_final_newline = true 18 | max_line_length = 180 19 | tab_width = 8 20 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # ignore c files in statistic https://github.com/github/linguist#troubleshooting 2 | *.c linguist-vendored 3 | *.h linguist-vendored 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pdf 2 | *.o 3 | bin 4 | .dub 5 | examples/encoding_list/encoding_list 6 | examples/error_handling/err 7 | examples/font/font 8 | examples/grid_sheet/grid_sheet 9 | examples/dash/dash 10 | examples/image/image 11 | examples/line/line 12 | -------------------------------------------------------------------------------- /C/hpdf_annotation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_annotation.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_ANNOTATION_H 19 | #define _HPDF_ANNOTATION_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /*------ HPDF_Annotation -----------------------------------------------------*/ 29 | 30 | 31 | HPDF_Annotation 32 | HPDF_Annotation_New (HPDF_MMgr mmgr, 33 | HPDF_Xref xref, 34 | HPDF_AnnotType type, 35 | HPDF_Rect rect); 36 | 37 | 38 | HPDF_Annotation 39 | HPDF_LinkAnnot_New (HPDF_MMgr mmgr, 40 | HPDF_Xref xref, 41 | HPDF_Rect rect, 42 | HPDF_Destination dst); 43 | 44 | 45 | HPDF_Annotation 46 | HPDF_URILinkAnnot_New (HPDF_MMgr mmgr, 47 | HPDF_Xref xref, 48 | HPDF_Rect rect, 49 | const char *uri); 50 | 51 | 52 | HPDF_Annotation 53 | HPDF_3DAnnot_New (HPDF_MMgr mmgr, 54 | HPDF_Xref xref, 55 | HPDF_Rect rect, 56 | HPDF_U3D u3d); 57 | 58 | HPDF_Annotation 59 | HPDF_MarkupAnnot_New (HPDF_MMgr mmgr, 60 | HPDF_Xref xref, 61 | HPDF_Rect rect, 62 | const char *text, 63 | HPDF_Encoder encoder, 64 | HPDF_AnnotType subtype); 65 | 66 | HPDF_Annotation 67 | HPDF_PopupAnnot_New (HPDF_MMgr mmgr, 68 | HPDF_Xref xref, 69 | HPDF_Rect rect, 70 | HPDF_Annotation parent); 71 | 72 | HPDF_Annotation 73 | HPDF_StampAnnot_New (HPDF_MMgr mmgr, 74 | HPDF_Xref xref, 75 | HPDF_Rect rect, 76 | HPDF_StampAnnotName name, 77 | const char* text, 78 | HPDF_Encoder encoder); 79 | 80 | HPDF_BOOL 81 | HPDF_Annotation_Validate (HPDF_Annotation annot); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif /* __cplusplus */ 86 | 87 | #endif /* _HPDF_ANNOTATION_H */ 88 | 89 | -------------------------------------------------------------------------------- /C/hpdf_catalog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_catalog.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_CATALOG_H 19 | #define _HPDF_CATALOG_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef HPDF_Dict HPDF_Catalog; 28 | 29 | HPDF_Catalog 30 | HPDF_Catalog_New (HPDF_MMgr mmgr, 31 | HPDF_Xref xref); 32 | 33 | 34 | HPDF_NameDict 35 | HPDF_Catalog_GetNames (HPDF_Catalog catalog); 36 | 37 | 38 | HPDF_STATUS 39 | HPDF_Catalog_SetNames (HPDF_Catalog catalog, 40 | HPDF_NameDict dict); 41 | 42 | 43 | HPDF_Pages 44 | HPDF_Catalog_GetRoot (HPDF_Catalog catalog); 45 | 46 | 47 | HPDF_PageLayout 48 | HPDF_Catalog_GetPageLayout (HPDF_Catalog catalog); 49 | 50 | 51 | HPDF_STATUS 52 | HPDF_Catalog_SetPageLayout (HPDF_Catalog catalog, 53 | HPDF_PageLayout layout); 54 | 55 | 56 | HPDF_PageMode 57 | HPDF_Catalog_GetPageMode (HPDF_Catalog catalog); 58 | 59 | 60 | HPDF_STATUS 61 | HPDF_Catalog_SetPageMode (HPDF_Catalog catalog, 62 | HPDF_PageMode mode); 63 | 64 | 65 | HPDF_STATUS 66 | HPDF_Catalog_SetOpenAction (HPDF_Catalog catalog, 67 | HPDF_Destination open_action); 68 | 69 | 70 | HPDF_STATUS 71 | HPDF_Catalog_AddPageLabel (HPDF_Catalog catalog, 72 | HPDF_UINT page_num, 73 | HPDF_Dict page_label); 74 | 75 | 76 | HPDF_UINT 77 | HPDF_Catalog_GetViewerPreference (HPDF_Catalog catalog); 78 | 79 | 80 | HPDF_STATUS 81 | HPDF_Catalog_SetViewerPreference (HPDF_Catalog catalog, 82 | HPDF_UINT value); 83 | 84 | 85 | HPDF_BOOL 86 | HPDF_Catalog_Validate (HPDF_Catalog catalog); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif /* __cplusplus */ 91 | 92 | #endif /* _HPDF_CATALOG_H */ 93 | 94 | -------------------------------------------------------------------------------- /C/hpdf_conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_conf.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_CONF_H 19 | #define _HPDF_CONF_H 20 | 21 | #include 22 | #include 23 | #if defined(_MSC_VER) 24 | #define _USE_MATH_DEFINES 1 25 | #endif 26 | #define __USE_XOPEN /* for M_PI */ 27 | #include 28 | 29 | /*----------------------------------------------------------------------------*/ 30 | /*----- standard C library functions -----------------------------------------*/ 31 | 32 | #define HPDF_FOPEN fopen 33 | #define HPDF_FCLOSE fclose 34 | #define HPDF_FREAD fread 35 | #define HPDF_FWRITE fwrite 36 | #define HPDF_FFLUSH fflush 37 | #define HPDF_FSEEK fseek 38 | #define HPDF_FTELL ftell 39 | #define HPDF_FEOF feof 40 | #define HPDF_FERROR ferror 41 | #define HPDF_MALLOC malloc 42 | #define HPDF_FREE free 43 | #define HPDF_FILEP FILE* 44 | #define HPDF_TIME time 45 | #define HPDF_PRINTF printf 46 | #define HPDF_SIN sin 47 | #define HPDF_COS cos 48 | 49 | /*----------------------------------------------------------------------------*/ 50 | /*----- parameters in relation to performance --------------------------------*/ 51 | 52 | /* default buffer size of memory-stream-object */ 53 | #define HPDF_STREAM_BUF_SIZ 4096 54 | 55 | /* default array size of list-object */ 56 | #define HPDF_DEF_ITEMS_PER_BLOCK 20 57 | 58 | /* default array size of cross-reference-table */ 59 | #define HPDF_DEFALUT_XREF_ENTRY_NUM 1024 60 | 61 | /* default array size of widths-table of cid-fontdef */ 62 | #define HPDF_DEF_CHAR_WIDTHS_NUM 128 63 | 64 | /* default array size of page-list-tablef */ 65 | #define HPDF_DEF_PAGE_LIST_NUM 256 66 | 67 | /* default array size of range-table of cid-fontdef */ 68 | #define HPDF_DEF_RANGE_TBL_NUM 128 69 | 70 | /* default buffer size of memory-pool-object */ 71 | #define HPDF_MPOOL_BUF_SIZ 8192 72 | #define HPDF_MIN_MPOOL_BUF_SIZ 256 73 | #define HPDF_MAX_MPOOL_BUF_SIZ 1048576 74 | 75 | /* alignment size of memory-pool-object 76 | */ 77 | #define HPDF_ALIGN_SIZ sizeof int; 78 | 79 | 80 | #endif /* _HPDF_CONF_H */ 81 | 82 | -------------------------------------------------------------------------------- /C/hpdf_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _INCLUDE_HPDF_CONFIG_H 2 | #define _INCLUDE_HPDF_CONFIG_H 1 3 | 4 | /* include/hpdf_config.h. Generated automatically at end of configure. */ 5 | /* include/config.h. Generated from config.h.in by configure. */ 6 | /* include/config.h.in. Generated from configure.in by autoheader. */ 7 | 8 | /* debug build */ 9 | /* #undef DEBUG */ 10 | 11 | /* debug trace enabled */ 12 | /* #undef DEBUG_TRACE */ 13 | 14 | /* Define to 1 if you have the header file. */ 15 | #ifndef LIBHPDF_HAVE_DLFCN_H 16 | #define LIBHPDF_HAVE_DLFCN_H 1 17 | #endif 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #ifndef LIBHPDF_HAVE_INTTYPES_H 21 | #define LIBHPDF_HAVE_INTTYPES_H 1 22 | #endif 23 | 24 | /* Define to 1 if you have the `png' library (-lpng). */ 25 | #ifndef LIBHPDF_HAVE_LIBPNG 26 | #define LIBHPDF_HAVE_LIBPNG 1 27 | #endif 28 | 29 | /* Define to 1 if you have the `z' library (-lz). */ 30 | #ifndef LIBHPDF_HAVE_LIBZ 31 | #define LIBHPDF_HAVE_LIBZ 1 32 | #endif 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #ifndef LIBHPDF_HAVE_MEMORY_H 36 | #define LIBHPDF_HAVE_MEMORY_H 1 37 | #endif 38 | 39 | /* libpng is not available */ 40 | /* #undef HAVE_NOPNGLIB */ 41 | 42 | /* zlib is not available */ 43 | /* #undef HAVE_NOZLIB */ 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #ifndef LIBHPDF_HAVE_STDINT_H 47 | #define LIBHPDF_HAVE_STDINT_H 1 48 | #endif 49 | 50 | /* Define to 1 if you have the header file. */ 51 | #ifndef LIBHPDF_HAVE_STDLIB_H 52 | #define LIBHPDF_HAVE_STDLIB_H 1 53 | #endif 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #ifndef LIBHPDF_HAVE_STRINGS_H 57 | #define LIBHPDF_HAVE_STRINGS_H 1 58 | #endif 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #ifndef LIBHPDF_HAVE_STRING_H 62 | #define LIBHPDF_HAVE_STRING_H 1 63 | #endif 64 | 65 | /* Define to 1 if you have the header file. */ 66 | #ifndef LIBHPDF_HAVE_SYS_STAT_H 67 | #define LIBHPDF_HAVE_SYS_STAT_H 1 68 | #endif 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #ifndef LIBHPDF_HAVE_SYS_TYPES_H 72 | #define LIBHPDF_HAVE_SYS_TYPES_H 1 73 | #endif 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #ifndef LIBHPDF_HAVE_UNISTD_H 77 | #define LIBHPDF_HAVE_UNISTD_H 1 78 | #endif 79 | 80 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 81 | */ 82 | #ifndef LIBHPDF_LT_OBJDIR 83 | #define LIBHPDF_LT_OBJDIR ".libs/" 84 | #endif 85 | 86 | /* Define to the address where bug reports for this package should be sent. */ 87 | #ifndef LIBHPDF_PACKAGE_BUGREPORT 88 | #define LIBHPDF_PACKAGE_BUGREPORT "" 89 | #endif 90 | 91 | /* Define to the full name of this package. */ 92 | #ifndef LIBHPDF_PACKAGE_NAME 93 | #define LIBHPDF_PACKAGE_NAME "libhpdf" 94 | #endif 95 | 96 | /* Define to the full name and version of this package. */ 97 | #ifndef LIBHPDF_PACKAGE_STRING 98 | #define LIBHPDF_PACKAGE_STRING "libhpdf 2.2.1" 99 | #endif 100 | 101 | /* Define to the one symbol short name of this package. */ 102 | #ifndef LIBHPDF_PACKAGE_TARNAME 103 | #define LIBHPDF_PACKAGE_TARNAME "libhpdf" 104 | #endif 105 | 106 | /* Define to the home page for this package. */ 107 | #ifndef LIBHPDF_PACKAGE_URL 108 | #define LIBHPDF_PACKAGE_URL "" 109 | #endif 110 | 111 | /* Define to the version of this package. */ 112 | #ifndef LIBHPDF_PACKAGE_VERSION 113 | #define LIBHPDF_PACKAGE_VERSION "2.2.1" 114 | #endif 115 | 116 | /* Define to 1 if you have the ANSI C header files. */ 117 | #ifndef LIBHPDF_STDC_HEADERS 118 | #define LIBHPDF_STDC_HEADERS 1 119 | #endif 120 | 121 | /* Define to `unsigned int' if does not define. */ 122 | /* #undef size_t */ 123 | 124 | /* once: _INCLUDE_HPDF_CONFIG_H */ 125 | #endif 126 | -------------------------------------------------------------------------------- /C/hpdf_destination.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_destination.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_DESTINATION_H 19 | #define _HPDF_DESTINATION_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /*----- HPDF_Destination -----------------------------------------------------*/ 29 | 30 | HPDF_Destination 31 | HPDF_Destination_New (HPDF_MMgr mmgr, 32 | HPDF_Page target, 33 | HPDF_Xref xref); 34 | 35 | 36 | HPDF_BOOL 37 | HPDF_Destination_Validate (HPDF_Destination dst); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif /* __cplusplus */ 42 | 43 | #endif /* _HPDF_DESTINATION_H */ 44 | 45 | -------------------------------------------------------------------------------- /C/hpdf_doc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_doc.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | 19 | #ifndef _HPDF_DOC_H 20 | #define _HPDF_DOC_H 21 | 22 | #define HPDF_SIG_BYTES 0x41504446L 23 | 24 | #include "hpdf_catalog.h" 25 | #include "hpdf_image.h" 26 | #include "hpdf_pages.h" 27 | #include "hpdf_outline.h" 28 | #include "hpdf_ext_gstate.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #define HPDF_VER_DEFAULT HPDF_VER_12 35 | 36 | typedef struct _HPDF_Doc_Rec { 37 | HPDF_UINT32 sig_bytes; 38 | HPDF_PDFVer pdf_version; 39 | 40 | HPDF_MMgr mmgr; 41 | HPDF_Catalog catalog; 42 | HPDF_Outline outlines; 43 | HPDF_Xref xref; 44 | HPDF_Pages root_pages; 45 | HPDF_Pages cur_pages; 46 | HPDF_Page cur_page; 47 | HPDF_List page_list; 48 | HPDF_Error_Rec error; 49 | HPDF_Dict info; 50 | HPDF_Dict trailer; 51 | 52 | HPDF_List font_mgr; 53 | HPDF_BYTE ttfont_tag[6]; 54 | 55 | /* list for loaded fontdefs */ 56 | HPDF_List fontdef_list; 57 | 58 | /* list for loaded encodings */ 59 | HPDF_List encoder_list; 60 | 61 | HPDF_Encoder cur_encoder; 62 | 63 | /* default compression mode */ 64 | HPDF_BOOL compression_mode; 65 | 66 | HPDF_BOOL encrypt_on; 67 | HPDF_EncryptDict encrypt_dict; 68 | 69 | HPDF_Encoder def_encoder; 70 | 71 | HPDF_UINT page_per_pages; 72 | HPDF_UINT cur_page_num; 73 | 74 | /* buffer for saving into memory stream */ 75 | HPDF_Stream stream; 76 | } HPDF_Doc_Rec; 77 | 78 | typedef struct _HPDF_Doc_Rec *HPDF_Doc; 79 | 80 | 81 | HPDF_Encoder 82 | HPDF_Doc_FindEncoder (HPDF_Doc pdf, 83 | const char *encoding_name); 84 | 85 | 86 | HPDF_FontDef 87 | HPDF_Doc_FindFontDef (HPDF_Doc pdf, 88 | const char *font_name); 89 | 90 | 91 | HPDF_Font 92 | HPDF_Doc_FindFont (HPDF_Doc pdf, 93 | const char *font_name, 94 | const char *encoding_name); 95 | 96 | 97 | HPDF_BOOL 98 | HPDF_Doc_Validate (HPDF_Doc pdf); 99 | 100 | 101 | /*----- page handling -------------------------------------------------------*/ 102 | 103 | HPDF_Pages 104 | HPDF_Doc_GetCurrentPages (HPDF_Doc pdf); 105 | 106 | 107 | HPDF_Pages 108 | HPDF_Doc_AddPagesTo (HPDF_Doc pdf, 109 | HPDF_Pages parent); 110 | 111 | 112 | HPDF_STATUS 113 | HPDF_Doc_SetCurrentPages (HPDF_Doc pdf, 114 | HPDF_Pages pages); 115 | 116 | 117 | HPDF_STATUS 118 | HPDF_Doc_SetCurrentPage (HPDF_Doc pdf, 119 | HPDF_Page page); 120 | 121 | 122 | 123 | 124 | /*----- font handling -------------------------------------------------------*/ 125 | 126 | HPDF_FontDef 127 | HPDF_GetFontDef (HPDF_Doc pdf, 128 | const char *font_name); 129 | 130 | 131 | HPDF_STATUS 132 | HPDF_Doc_RegisterFontDef (HPDF_Doc pdf, 133 | HPDF_FontDef fontdef); 134 | 135 | 136 | /*----- encoding handling ---------------------------------------------------*/ 137 | 138 | HPDF_STATUS 139 | HPDF_Doc_RegisterEncoder (HPDF_Doc pdf, 140 | HPDF_Encoder encoder); 141 | 142 | 143 | 144 | /*----- encryptio------------------------------------------------------------*/ 145 | 146 | HPDF_STATUS 147 | HPDF_Doc_SetEncryptOn (HPDF_Doc pdf); 148 | 149 | 150 | HPDF_STATUS 151 | HPDF_Doc_SetEncryptOff (HPDF_Doc pdf); 152 | 153 | 154 | HPDF_STATUS 155 | HPDF_Doc_PrepareEncryption (HPDF_Doc pdf); 156 | 157 | #ifdef __cplusplus 158 | } 159 | #endif /* __cplusplus */ 160 | 161 | #endif /* _HPDF_DOC_H */ 162 | 163 | -------------------------------------------------------------------------------- /C/hpdf_encoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_encoder.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_ENCODER_H 19 | #define _HPDF_ENCODER_H 20 | 21 | #include "hpdf_consts.h" 22 | #include "hpdf_streams.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /*-- HPDF_Encoder ---------------------------------------*/ 29 | 30 | #define HPDF_ENCODER_SIG_BYTES 0x454E4344L 31 | 32 | /*----------------------------------------------------------------------------*/ 33 | /*------ predefined font encodings -------------------------------------------*/ 34 | 35 | #define HPDF_ENCODING_FONT_SPECIFIC "FontSpecific" 36 | #define HPDF_ENCODING_STANDARD "StandardEncoding" 37 | #define HPDF_ENCODING_MAC_ROMAN "MacRomanEncoding" 38 | #define HPDF_ENCODING_WIN_ANSI "WinAnsiEncoding" 39 | #define HPDF_ENCODING_ISO8859_2 "ISO8859-2" 40 | #define HPDF_ENCODING_ISO8859_3 "ISO8859-3" 41 | #define HPDF_ENCODING_ISO8859_4 "ISO8859-4" 42 | #define HPDF_ENCODING_ISO8859_5 "ISO8859-5" 43 | #define HPDF_ENCODING_ISO8859_6 "ISO8859-6" 44 | #define HPDF_ENCODING_ISO8859_7 "ISO8859-7" 45 | #define HPDF_ENCODING_ISO8859_8 "ISO8859-8" 46 | #define HPDF_ENCODING_ISO8859_9 "ISO8859-9" 47 | #define HPDF_ENCODING_ISO8859_10 "ISO8859-10" 48 | #define HPDF_ENCODING_ISO8859_11 "ISO8859-11" 49 | #define HPDF_ENCODING_ISO8859_13 "ISO8859-13" 50 | #define HPDF_ENCODING_ISO8859_14 "ISO8859-14" 51 | #define HPDF_ENCODING_ISO8859_15 "ISO8859-15" 52 | #define HPDF_ENCODING_ISO8859_16 "ISO8859-16" 53 | #define HPDF_ENCODING_CP1250 "CP1250" 54 | #define HPDF_ENCODING_CP1251 "CP1251" 55 | #define HPDF_ENCODING_CP1252 "CP1252" 56 | #define HPDF_ENCODING_CP1253 "CP1253" 57 | #define HPDF_ENCODING_CP1254 "CP1254" 58 | #define HPDF_ENCODING_CP1255 "CP1255" 59 | #define HPDF_ENCODING_CP1256 "CP1256" 60 | #define HPDF_ENCODING_CP1257 "CP1257" 61 | #define HPDF_ENCODING_CP1258 "CP1258" 62 | #define HPDF_ENCODING_KOI8_R "KOI8-R" 63 | 64 | /*----------------------------------------------------------------------------*/ 65 | /*----- definition for font encoding -----------------------------------------*/ 66 | 67 | #define char_NOTDEF ".notdef" 68 | 69 | typedef enum _HPDF_EncodingType { 70 | HPDF_STANDARD_ENCODING = 0, 71 | HPDF_MAC_ROMAN_ENCODING, 72 | HPDF_WIN_ANSI_ENCODING, 73 | HPDF_FONT_SPECIFIC, 74 | HPDF_ENCODING_EOF 75 | } HPDF_EncodingType; 76 | 77 | 78 | typedef struct _HPDF_ParseText_Rec { 79 | const HPDF_BYTE *text; 80 | HPDF_UINT index; 81 | HPDF_UINT len; 82 | HPDF_ByteType byte_type; 83 | } HPDF_ParseText_Rec; 84 | 85 | 86 | typedef struct _HPDF_Encoder_Rec *HPDF_Encoder; 87 | 88 | typedef HPDF_ByteType 89 | (*HPDF_Encoder_ByteType_Func) (HPDF_Encoder encoder, 90 | HPDF_ParseText_Rec *state); 91 | 92 | typedef HPDF_UNICODE 93 | (*HPDF_Encoder_ToUnicode_Func) (HPDF_Encoder encoder, 94 | HPDF_UINT16 code); 95 | 96 | 97 | typedef HPDF_STATUS 98 | (*HPDF_Encoder_Write_Func) (HPDF_Encoder encoder, 99 | HPDF_Stream out); 100 | 101 | 102 | typedef HPDF_STATUS 103 | (*HPDF_Encoder_Init_Func) (HPDF_Encoder encoder); 104 | 105 | 106 | typedef void 107 | (*HPDF_Encoder_Free_Func) (HPDF_Encoder encoder); 108 | 109 | 110 | typedef struct _HPDF_Encoder_Rec { 111 | HPDF_UINT32 sig_bytes; 112 | char name[HPDF_LIMIT_MAX_NAME_LEN + 1]; 113 | HPDF_MMgr mmgr; 114 | HPDF_Error error; 115 | HPDF_EncoderType type; 116 | 117 | HPDF_Encoder_ByteType_Func byte_type_fn; 118 | HPDF_Encoder_ToUnicode_Func to_unicode_fn; 119 | HPDF_Encoder_Write_Func write_fn; 120 | HPDF_Encoder_Free_Func free_fn; 121 | HPDF_Encoder_Init_Func init_fn; 122 | /* 123 | char lang_code[3]; 124 | char country_code[3]; 125 | */ 126 | void *attr; 127 | } HPDF_Encoder_Rec; 128 | 129 | 130 | typedef enum _HPDF_BaseEncodings { 131 | HPDF_BASE_ENCODING_STANDARD, 132 | HPDF_BASE_ENCODING_WIN_ANSI, 133 | HPDF_BASE_ENCODING_MAC_ROMAN, 134 | HPDF_BASE_ENCODING_FONT_SPECIFIC, 135 | HPDF_BASE_ENCODING_EOF 136 | } HPDF_BaseEncodings; 137 | 138 | HPDF_STATUS 139 | HPDF_Encoder_Validate (HPDF_Encoder encoder); 140 | 141 | void 142 | HPDF_Encoder_SetParseText (HPDF_Encoder encoder, 143 | HPDF_ParseText_Rec *state, 144 | const HPDF_BYTE *text, 145 | HPDF_UINT len); 146 | 147 | HPDF_ByteType 148 | HPDF_Encoder_ByteType (HPDF_Encoder encoder, 149 | HPDF_ParseText_Rec *state); 150 | 151 | 152 | 153 | HPDF_UNICODE 154 | HPDF_Encoder_ToUnicode (HPDF_Encoder encoder, 155 | HPDF_UINT16 code); 156 | 157 | 158 | void 159 | HPDF_Encoder_Free (HPDF_Encoder encoder); 160 | 161 | /*-- HPDF_BasicEncoder ----------------------------------*/ 162 | 163 | 164 | typedef struct _HPDF_BasicEncoderAttr_Rec *HPDF_BasicEncoderAttr; 165 | 166 | typedef struct _HPDF_BasicEncoderAttr_Rec { 167 | char base_encoding[HPDF_LIMIT_MAX_NAME_LEN + 1]; 168 | HPDF_BYTE first_char; 169 | HPDF_BYTE last_char; 170 | HPDF_UNICODE unicode_map[256]; 171 | HPDF_BOOL has_differences; 172 | HPDF_BYTE differences[256]; 173 | } HPDF_BasicEncoderAttr_Rec; 174 | 175 | 176 | HPDF_Encoder 177 | HPDF_BasicEncoder_New (HPDF_MMgr mmgr, 178 | const char *encoding_name); 179 | 180 | 181 | void 182 | HPDF_BasicEncoder_Free (HPDF_Encoder encoder); 183 | 184 | 185 | HPDF_STATUS 186 | HPDF_BasicEncoder_Write (HPDF_Encoder encoder, 187 | HPDF_Stream out); 188 | 189 | 190 | HPDF_UNICODE 191 | HPDF_BasicEncoder_ToUnicode (HPDF_Encoder encoder, 192 | HPDF_UINT16 code); 193 | 194 | /*-- HPDF_CMapEncoder ----------------------------------*/ 195 | 196 | typedef HPDF_BOOL 197 | (*HPDF_CMapEncoder_ByteType_Func) (HPDF_Encoder encoder, 198 | HPDF_BYTE b); 199 | 200 | typedef struct _HPDF_CidRange_Rec { 201 | HPDF_UINT16 from; 202 | HPDF_UINT16 to; 203 | HPDF_UINT16 cid; 204 | } HPDF_CidRange_Rec; 205 | 206 | 207 | typedef struct _HPDF_UnicodeMap_Rec { 208 | HPDF_UINT16 code; 209 | HPDF_UINT16 unicode; 210 | } HPDF_UnicodeMap_Rec; 211 | 212 | typedef struct _HPDF_CMapEncoderAttr_Rec *HPDF_CMapEncoderAttr; 213 | 214 | typedef struct _HPDF_CMapEncoderAttr_Rec { 215 | HPDF_UNICODE unicode_map[256][256]; 216 | HPDF_UINT16 cid_map[256][256]; 217 | HPDF_UINT16 jww_line_head[HPDF_MAX_JWW_NUM]; 218 | HPDF_List cmap_range; 219 | HPDF_List notdef_range; 220 | HPDF_List code_space_range; 221 | HPDF_WritingMode writing_mode; 222 | char registry[HPDF_LIMIT_MAX_NAME_LEN + 1]; 223 | char ordering[HPDF_LIMIT_MAX_NAME_LEN + 1]; 224 | HPDF_INT suppliment; 225 | HPDF_CMapEncoder_ByteType_Func is_lead_byte_fn; 226 | HPDF_CMapEncoder_ByteType_Func is_trial_byte_fn; 227 | HPDF_INT uid_offset; 228 | HPDF_UINT xuid[3]; 229 | } HPDF_CMapEncoderAttr_Rec; 230 | 231 | 232 | HPDF_Encoder 233 | HPDF_CMapEncoder_New (HPDF_MMgr mmgr, 234 | char *name, 235 | HPDF_Encoder_Init_Func init_fn); 236 | 237 | 238 | HPDF_STATUS 239 | HPDF_CMapEncoder_InitAttr (HPDF_Encoder encoder); 240 | 241 | 242 | void 243 | HPDF_CMapEncoder_Free (HPDF_Encoder encoder); 244 | 245 | 246 | HPDF_STATUS 247 | HPDF_CMapEncoder_Write (HPDF_Encoder encoder, 248 | HPDF_Stream out); 249 | 250 | 251 | HPDF_UNICODE 252 | HPDF_CMapEncoder_ToUnicode (HPDF_Encoder encoder, 253 | HPDF_UINT16 code); 254 | 255 | HPDF_UINT16 256 | HPDF_CMapEncoder_ToCID (HPDF_Encoder encoder, 257 | HPDF_UINT16 code); 258 | 259 | HPDF_STATUS 260 | HPDF_CMapEncoder_SetParseText (HPDF_Encoder encoder, 261 | HPDF_ParseText_Rec *state, 262 | const HPDF_BYTE *text, 263 | HPDF_UINT len); 264 | 265 | HPDF_ByteType 266 | HPDF_CMapEncoder_ByteType (HPDF_Encoder encoder, 267 | HPDF_ParseText_Rec *state); 268 | 269 | 270 | HPDF_STATUS 271 | HPDF_CMapEncoder_AddCMap (HPDF_Encoder encoder, 272 | const HPDF_CidRange_Rec *range); 273 | 274 | 275 | HPDF_STATUS 276 | HPDF_CMapEncoder_AddNotDefRange (HPDF_Encoder encoder, 277 | HPDF_CidRange_Rec range); 278 | 279 | 280 | HPDF_STATUS 281 | HPDF_CMapEncoder_AddCodeSpaceRange (HPDF_Encoder encoder, 282 | HPDF_CidRange_Rec range); 283 | 284 | 285 | void 286 | HPDF_CMapEncoder_SetUnicodeArray (HPDF_Encoder encoder, 287 | const HPDF_UnicodeMap_Rec *array1); 288 | 289 | 290 | HPDF_STATUS 291 | HPDF_CMapEncoder_AddJWWLineHead (HPDF_Encoder encoder, 292 | const HPDF_UINT16 *code); 293 | 294 | HPDF_BOOL 295 | HPDF_Encoder_CheckJWWLineHead (HPDF_Encoder encoder, 296 | const HPDF_UINT16 code); 297 | 298 | /*-- utility functions ----------------------------------*/ 299 | 300 | const char* 301 | HPDF_UnicodeToGryphName (HPDF_UNICODE unicode); 302 | 303 | 304 | HPDF_UNICODE 305 | HPDF_GryphNameToUnicode (const char *gryph_name); 306 | 307 | #ifdef __cplusplus 308 | } 309 | #endif /* __cplusplus */ 310 | 311 | #endif /* _HPDF_ENCODER_H */ 312 | 313 | -------------------------------------------------------------------------------- /C/hpdf_encrypt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_encrypt.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | *------------------------------------------------------------------------------ 17 | * 18 | * The code implements MD5 message-digest algorithm is based on the code 19 | * written by Colin Plumb. 20 | * The copyright of it is as follows. 21 | * 22 | * This code implements the MD5 message-digest algorithm. 23 | * The algorithm is due to Ron Rivest. This code was 24 | * written by Colin Plumb in 1993, no copyright is claimed. 25 | * This code is in the public domain; do with it what you wish. 26 | * 27 | * Equivalent code is available from RSA Data Security, Inc. 28 | * This code has been tested against that, and is equivalent, 29 | * except that you don't need to include two pages of legalese 30 | * with every copy. 31 | * 32 | * To compute the message digest of a chunk of bytes, declare an 33 | * MD5Context structure, pass it to MD5Init, call MD5Update as 34 | * needed on buffers full of bytes, and then call MD5Final, which 35 | * will fill a supplied 16-byte array with the digest. 36 | * 37 | *---------------------------------------------------------------------------*/ 38 | 39 | #ifndef HPDF_ENCRYPT_H 40 | #define HPDF_ENCRYPT_H 41 | 42 | #include "hpdf_mmgr.h" 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | /*----------------------------------------------------------------------------*/ 49 | /*----- encrypt-dict ---------------------------------------------------------*/ 50 | 51 | #define HPDF_ID_LEN 16 52 | #define HPDF_PASSWD_LEN 32 53 | #define HPDF_ENCRYPT_KEY_MAX 16 54 | #define HPDF_MD5_KEY_LEN 16 55 | #define HPDF_PERMISSION_PAD 0xFFFFFFC0 56 | #define HPDF_ARC4_BUF_SIZE 256 57 | 58 | 59 | typedef struct HPDF_MD5Context 60 | { 61 | HPDF_UINT32 buf[4]; 62 | HPDF_UINT32 bits[2]; 63 | HPDF_BYTE in[64]; 64 | } HPDF_MD5_CTX; 65 | 66 | 67 | typedef struct _HPDF_ARC4_Ctx_Rec { 68 | HPDF_BYTE idx1; 69 | HPDF_BYTE idx2; 70 | HPDF_BYTE state[HPDF_ARC4_BUF_SIZE]; 71 | } HPDF_ARC4_Ctx_Rec; 72 | 73 | 74 | typedef struct _HPDF_Encrypt_Rec *HPDF_Encrypt; 75 | 76 | typedef struct _HPDF_Encrypt_Rec { 77 | HPDF_EncryptMode mode; 78 | 79 | /* key_len must be a multiple of 8, and between 40 to 128 */ 80 | HPDF_UINT key_len; 81 | 82 | /* owner-password (not encrypted) */ 83 | HPDF_BYTE owner_passwd[HPDF_PASSWD_LEN]; 84 | 85 | /* user-password (not encrypted) */ 86 | HPDF_BYTE user_passwd[HPDF_PASSWD_LEN]; 87 | 88 | /* owner-password (encrypted) */ 89 | HPDF_BYTE owner_key[HPDF_PASSWD_LEN]; 90 | 91 | /* user-password (encrypted) */ 92 | HPDF_BYTE user_key[HPDF_PASSWD_LEN]; 93 | 94 | HPDF_INT permission; 95 | HPDF_BYTE encrypt_id[HPDF_ID_LEN]; 96 | HPDF_BYTE encryption_key[HPDF_MD5_KEY_LEN + 5]; 97 | HPDF_BYTE md5_encryption_key[HPDF_MD5_KEY_LEN]; 98 | HPDF_ARC4_Ctx_Rec arc4ctx; 99 | } HPDF_Encrypt_Rec; 100 | 101 | 102 | void 103 | HPDF_MD5Init (struct HPDF_MD5Context *ctx); 104 | 105 | 106 | void 107 | HPDF_MD5Update (struct HPDF_MD5Context *ctx, 108 | const HPDF_BYTE *buf, 109 | HPDF_UINT32 len); 110 | 111 | 112 | void 113 | HPDF_MD5Final (HPDF_BYTE digest[16], 114 | struct HPDF_MD5Context *ctx); 115 | 116 | void 117 | HPDF_PadOrTrancatePasswd (const char *pwd, 118 | HPDF_BYTE *new_pwd); 119 | 120 | 121 | void 122 | HPDF_Encrypt_Init (HPDF_Encrypt attr); 123 | 124 | 125 | void 126 | HPDF_Encrypt_CreateUserKey (HPDF_Encrypt attr); 127 | 128 | 129 | void 130 | HPDF_Encrypt_CreateOwnerKey (HPDF_Encrypt attr); 131 | 132 | 133 | void 134 | HPDF_Encrypt_CreateEncryptionKey (HPDF_Encrypt attr); 135 | 136 | 137 | void 138 | HPDF_Encrypt_InitKey (HPDF_Encrypt attr, 139 | HPDF_UINT32 object_id, 140 | HPDF_UINT16 gen_no); 141 | 142 | 143 | void 144 | HPDF_Encrypt_Reset (HPDF_Encrypt attr); 145 | 146 | 147 | void 148 | HPDF_Encrypt_CryptBuf (HPDF_Encrypt attr, 149 | const HPDF_BYTE *src, 150 | HPDF_BYTE *dst, 151 | HPDF_UINT len); 152 | 153 | #ifdef __cplusplus 154 | } 155 | #endif /* __cplusplus */ 156 | 157 | #endif /* _HPDF_ENCRYPT_H */ 158 | 159 | 160 | -------------------------------------------------------------------------------- /C/hpdf_encryptdict.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_encryptdict.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_ENCRYPTDICT_H 19 | #define _HPDF_ENCRYPTDICT_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /*---------------------------------------------------------------------------*/ 28 | /*------ HPDF_EncryptDict ---------------------------------------------------*/ 29 | 30 | HPDF_EncryptDict 31 | HPDF_EncryptDict_New (HPDF_MMgr mmgr, 32 | HPDF_Xref xref); 33 | 34 | 35 | void 36 | HPDF_EncryptDict_CreateID (HPDF_EncryptDict dict, 37 | HPDF_Dict info, 38 | HPDF_Xref xref); 39 | 40 | 41 | void 42 | HPDF_EncryptDict_OnFree (HPDF_Dict obj); 43 | 44 | 45 | HPDF_STATUS 46 | HPDF_EncryptDict_SetPassword (HPDF_EncryptDict dict, 47 | const char *owner_passwd, 48 | const char *user_passwd); 49 | 50 | 51 | HPDF_BOOL 52 | HPDF_EncryptDict_Validate (HPDF_EncryptDict dict); 53 | 54 | 55 | HPDF_STATUS 56 | HPDF_EncryptDict_Prepare (HPDF_EncryptDict dict, 57 | HPDF_Dict info, 58 | HPDF_Xref xref); 59 | 60 | 61 | HPDF_Encrypt 62 | HPDF_EncryptDict_GetAttr (HPDF_EncryptDict dict); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif /* __cplusplus */ 67 | 68 | #endif /* _HPDF_ENCRYPTDICT_H */ 69 | 70 | -------------------------------------------------------------------------------- /C/hpdf_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_error.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_ERROR_H 19 | #define _HPDF_ERROR_H 20 | 21 | #include "hpdf_types.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* error-code */ 28 | #define HPDF_ARRAY_COUNT_ERR 0x1001 29 | #define HPDF_ARRAY_ITEM_NOT_FOUND 0x1002 30 | #define HPDF_ARRAY_ITEM_UNEXPECTED_TYPE 0x1003 31 | #define HPDF_BINARY_LENGTH_ERR 0x1004 32 | #define HPDF_CANNOT_GET_PALLET 0x1005 33 | #define HPDF_DICT_COUNT_ERR 0x1007 34 | #define HPDF_DICT_ITEM_NOT_FOUND 0x1008 35 | #define HPDF_DICT_ITEM_UNEXPECTED_TYPE 0x1009 36 | #define HPDF_DICT_STREAM_LENGTH_NOT_FOUND 0x100A 37 | #define HPDF_DOC_ENCRYPTDICT_NOT_FOUND 0x100B 38 | #define HPDF_DOC_INVALID_OBJECT 0x100C 39 | /* 0x100D */ 40 | #define HPDF_DUPLICATE_REGISTRATION 0x100E 41 | #define HPDF_EXCEED_JWW_CODE_NUM_LIMIT 0x100F 42 | /* 0x1010 */ 43 | #define HPDF_ENCRYPT_INVALID_PASSWORD 0x1011 44 | /* 0x1012 */ 45 | #define HPDF_ERR_UNKNOWN_CLASS 0x1013 46 | #define HPDF_EXCEED_GSTATE_LIMIT 0x1014 47 | #define HPDF_FAILD_TO_ALLOC_MEM 0x1015 48 | #define HPDF_FILE_IO_ERROR 0x1016 49 | #define HPDF_FILE_OPEN_ERROR 0x1017 50 | /* 0x1018 */ 51 | #define HPDF_FONT_EXISTS 0x1019 52 | #define HPDF_FONT_INVALID_WIDTHS_TABLE 0x101A 53 | #define HPDF_INVALID_AFM_HEADER 0x101B 54 | #define HPDF_INVALID_ANNOTATION 0x101C 55 | /* 0x101D */ 56 | #define HPDF_INVALID_BIT_PER_COMPONENT 0x101E 57 | #define HPDF_INVALID_CHAR_MATRICS_DATA 0x101F 58 | #define HPDF_INVALID_COLOR_SPACE 0x1020 59 | #define HPDF_INVALID_COMPRESSION_MODE 0x1021 60 | #define HPDF_INVALID_DATE_TIME 0x1022 61 | #define HPDF_INVALID_DESTINATION 0x1023 62 | /* 0x1024 */ 63 | #define HPDF_INVALID_DOCUMENT 0x1025 64 | #define HPDF_INVALID_DOCUMENT_STATE 0x1026 65 | #define HPDF_INVALID_ENCODER 0x1027 66 | #define HPDF_INVALID_ENCODER_TYPE 0x1028 67 | /* 0x1029 */ 68 | /* 0x102A */ 69 | #define HPDF_INVALID_ENCODING_NAME 0x102B 70 | #define HPDF_INVALID_ENCRYPT_KEY_LEN 0x102C 71 | #define HPDF_INVALID_FONTDEF_DATA 0x102D 72 | #define HPDF_INVALID_FONTDEF_TYPE 0x102E 73 | #define HPDF_INVALID_FONT_NAME 0x102F 74 | #define HPDF_INVALID_IMAGE 0x1030 75 | #define HPDF_INVALID_JPEG_DATA 0x1031 76 | #define HPDF_INVALID_N_DATA 0x1032 77 | #define HPDF_INVALID_OBJECT 0x1033 78 | #define HPDF_INVALID_OBJ_ID 0x1034 79 | #define HPDF_INVALID_OPERATION 0x1035 80 | #define HPDF_INVALID_OUTLINE 0x1036 81 | #define HPDF_INVALID_PAGE 0x1037 82 | #define HPDF_INVALID_PAGES 0x1038 83 | #define HPDF_INVALID_PARAMETER 0x1039 84 | /* 0x103A */ 85 | #define HPDF_INVALID_PNG_IMAGE 0x103B 86 | #define HPDF_INVALID_STREAM 0x103C 87 | #define HPDF_MISSING_FILE_NAME_ENTRY 0x103D 88 | /* 0x103E */ 89 | #define HPDF_INVALID_TTC_FILE 0x103F 90 | #define HPDF_INVALID_TTC_INDEX 0x1040 91 | #define HPDF_INVALID_WX_DATA 0x1041 92 | #define HPDF_ITEM_NOT_FOUND 0x1042 93 | #define HPDF_LIBPNG_ERROR 0x1043 94 | #define HPDF_NAME_INVALID_VALUE 0x1044 95 | #define HPDF_NAME_OUT_OF_RANGE 0x1045 96 | /* 0x1046 */ 97 | /* 0x1047 */ 98 | #define HPDF_PAGE_INVALID_PARAM_COUNT 0x1048 99 | #define HPDF_PAGES_MISSING_KIDS_ENTRY 0x1049 100 | #define HPDF_PAGE_CANNOT_FIND_OBJECT 0x104A 101 | #define HPDF_PAGE_CANNOT_GET_ROOT_PAGES 0x104B 102 | #define HPDF_PAGE_CANNOT_RESTORE_GSTATE 0x104C 103 | #define HPDF_PAGE_CANNOT_SET_PARENT 0x104D 104 | #define HPDF_PAGE_FONT_NOT_FOUND 0x104E 105 | #define HPDF_PAGE_INVALID_FONT 0x104F 106 | #define HPDF_PAGE_INVALID_FONT_SIZE 0x1050 107 | #define HPDF_PAGE_INVALID_GMODE 0x1051 108 | #define HPDF_PAGE_INVALID_INDEX 0x1052 109 | #define HPDF_PAGE_INVALID_ROTATE_VALUE 0x1053 110 | #define HPDF_PAGE_INVALID_SIZE 0x1054 111 | #define HPDF_PAGE_INVALID_XOBJECT 0x1055 112 | #define HPDF_PAGE_OUT_OF_RANGE 0x1056 113 | #define HPDF_REAL_OUT_OF_RANGE 0x1057 114 | #define HPDF_STREAM_EOF 0x1058 115 | #define HPDF_STREAM_READLN_CONTINUE 0x1059 116 | /* 0x105A */ 117 | #define HPDF_STRING_OUT_OF_RANGE 0x105B 118 | #define HPDF_THIS_FUNC_WAS_SKIPPED 0x105C 119 | #define HPDF_TTF_CANNOT_EMBEDDING_FONT 0x105D 120 | #define HPDF_TTF_INVALID_CMAP 0x105E 121 | #define HPDF_TTF_INVALID_FOMAT 0x105F 122 | #define HPDF_TTF_MISSING_TABLE 0x1060 123 | #define HPDF_UNSUPPORTED_FONT_TYPE 0x1061 124 | #define HPDF_UNSUPPORTED_FUNC 0x1062 125 | #define HPDF_UNSUPPORTED_JPEG_FORMAT 0x1063 126 | #define HPDF_UNSUPPORTED_TYPE1_FONT 0x1064 127 | #define HPDF_XREF_COUNT_ERR 0x1065 128 | #define HPDF_ZLIB_ERROR 0x1066 129 | #define HPDF_INVALID_PAGE_INDEX 0x1067 130 | #define HPDF_INVALID_URI 0x1068 131 | #define HPDF_PAGE_LAYOUT_OUT_OF_RANGE 0x1069 132 | #define HPDF_PAGE_MODE_OUT_OF_RANGE 0x1070 133 | #define HPDF_PAGE_NUM_STYLE_OUT_OF_RANGE 0x1071 134 | #define HPDF_ANNOT_INVALID_ICON 0x1072 135 | #define HPDF_ANNOT_INVALID_BORDER_STYLE 0x1073 136 | #define HPDF_PAGE_INVALID_DIRECTION 0x1074 137 | #define HPDF_INVALID_FONT 0x1075 138 | #define HPDF_PAGE_INSUFFICIENT_SPACE 0x1076 139 | #define HPDF_PAGE_INVALID_DISPLAY_TIME 0x1077 140 | #define HPDF_PAGE_INVALID_TRANSITION_TIME 0x1078 141 | #define HPDF_INVALID_PAGE_SLIDESHOW_TYPE 0x1079 142 | #define HPDF_EXT_GSTATE_OUT_OF_RANGE 0x1080 143 | #define HPDF_INVALID_EXT_GSTATE 0x1081 144 | #define HPDF_EXT_GSTATE_READ_ONLY 0x1082 145 | #define HPDF_INVALID_U3D_DATA 0x1083 146 | #define HPDF_NAME_CANNOT_GET_NAMES 0x1084 147 | #define HPDF_INVALID_ICC_COMPONENT_NUM 0x1085 148 | 149 | /*---------------------------------------------------------------------------*/ 150 | 151 | /*---------------------------------------------------------------------------*/ 152 | /*----- HPDF_Error ----------------------------------------------------------*/ 153 | 154 | typedef struct _HPDF_Error_Rec *HPDF_Error; 155 | 156 | typedef struct _HPDF_Error_Rec { 157 | HPDF_STATUS error_no; 158 | HPDF_STATUS detail_no; 159 | HPDF_Error_Handler error_fn; 160 | void *user_data; 161 | } HPDF_Error_Rec; 162 | 163 | 164 | /* HPDF_Error_init 165 | * 166 | * if error_fn is NULL, the default-handlers are set as error-handler. 167 | * user_data is used to identify the object which threw an error. 168 | * 169 | */ 170 | void 171 | HPDF_Error_Init (HPDF_Error error, 172 | void *user_data); 173 | 174 | 175 | void 176 | HPDF_Error_Reset (HPDF_Error error); 177 | 178 | 179 | HPDF_STATUS 180 | HPDF_Error_GetCode (HPDF_Error error); 181 | 182 | 183 | HPDF_STATUS 184 | HPDF_Error_GetDetailCode (HPDF_Error error); 185 | 186 | 187 | HPDF_STATUS 188 | HPDF_SetError (HPDF_Error error, 189 | HPDF_STATUS error_no, 190 | HPDF_STATUS detail_no); 191 | 192 | 193 | HPDF_STATUS 194 | HPDF_RaiseError (HPDF_Error error, 195 | HPDF_STATUS error_no, 196 | HPDF_STATUS detail_no); 197 | 198 | #ifdef __cplusplus 199 | } 200 | #endif /* __cplusplus */ 201 | 202 | #endif /* _HPDF_ERROR_H */ 203 | 204 | -------------------------------------------------------------------------------- /C/hpdf_ext_gstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_ext_gstate.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_EXT_GSTATE_H 19 | #define _HPDF_EXT_GSTATE_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | HPDF_Dict 28 | HPDF_ExtGState_New (HPDF_MMgr mmgr, 29 | HPDF_Xref xref); 30 | 31 | 32 | HPDF_BOOL 33 | HPDF_ExtGState_Validate (HPDF_ExtGState ext_gstate); 34 | 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /* __cplusplus */ 39 | 40 | #endif /* _HPDF_EXT_GSTATE_H */ 41 | 42 | -------------------------------------------------------------------------------- /C/hpdf_font.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_font.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_FONT_H 19 | #define _HPDF_FONT_H 20 | 21 | #include "hpdf_fontdef.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /*----------------------------------------------------------------------------*/ 29 | /*----- Writing Mode ---------------------------------------------------------*/ 30 | 31 | typedef enum _HPDF_FontType { 32 | HPDF_FONT_TYPE1 = 0, 33 | HPDF_FONT_TRUETYPE, 34 | HPDF_FONT_TYPE3, 35 | HPDF_FONT_TYPE0_CID, 36 | HPDF_FONT_TYPE0_TT, 37 | HPDF_FONT_CID_TYPE0, 38 | HPDF_FONT_CID_TYPE2, 39 | HPDF_FONT_MMTYPE1 40 | } HPDF_FontType; 41 | 42 | 43 | typedef HPDF_Dict HPDF_Font; 44 | 45 | 46 | typedef HPDF_TextWidth 47 | (*HPDF_Font_TextWidths_Func) (HPDF_Font font, 48 | const HPDF_BYTE *text, 49 | HPDF_UINT len); 50 | 51 | 52 | typedef HPDF_UINT 53 | (*HPDF_Font_MeasureText_Func) (HPDF_Font font, 54 | const HPDF_BYTE *text, 55 | HPDF_UINT len, 56 | HPDF_REAL width, 57 | HPDF_REAL fontsize, 58 | HPDF_REAL charspace, 59 | HPDF_REAL wordspace, 60 | HPDF_BOOL wordwrap, 61 | HPDF_REAL *real_width); 62 | 63 | 64 | typedef struct _HPDF_FontAttr_Rec *HPDF_FontAttr; 65 | 66 | typedef struct _HPDF_FontAttr_Rec { 67 | HPDF_FontType type; 68 | HPDF_WritingMode writing_mode; 69 | HPDF_Font_TextWidths_Func text_width_fn; 70 | HPDF_Font_MeasureText_Func measure_text_fn; 71 | HPDF_FontDef fontdef; 72 | HPDF_Encoder encoder; 73 | 74 | /* if the encoding-type is HPDF_ENCODER_TYPE_SINGLE_BYTE, the width of 75 | * each charactors are cashed in 'widths'. 76 | * when HPDF_ENCODER_TYPE_DOUBLE_BYTE the width is calculate each time. 77 | */ 78 | HPDF_INT16* widths; 79 | HPDF_BYTE* used; 80 | 81 | HPDF_Xref xref; 82 | HPDF_Font descendant_font; 83 | HPDF_Dict map_stream; 84 | HPDF_Dict cmap_stream; 85 | } HPDF_FontAttr_Rec; 86 | 87 | 88 | HPDF_Font 89 | HPDF_Type1Font_New (HPDF_MMgr mmgr, 90 | HPDF_FontDef fontdef, 91 | HPDF_Encoder encoder, 92 | HPDF_Xref xref); 93 | 94 | HPDF_Font 95 | HPDF_TTFont_New (HPDF_MMgr mmgr, 96 | HPDF_FontDef fontdef, 97 | HPDF_Encoder encoder, 98 | HPDF_Xref xref); 99 | 100 | HPDF_Font 101 | HPDF_Type0Font_New (HPDF_MMgr mmgr, 102 | HPDF_FontDef fontdef, 103 | HPDF_Encoder encoder, 104 | HPDF_Xref xref); 105 | 106 | 107 | HPDF_BOOL 108 | HPDF_Font_Validate (HPDF_Font font); 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif /* __cplusplus */ 113 | 114 | #endif /* _HPDF_FONT_H */ 115 | 116 | -------------------------------------------------------------------------------- /C/hpdf_fontdef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_fontdef.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_FONTDEF_H 19 | #define _HPDF_FONTDEF_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | #define HPDF_FONTDEF_SIG_BYTES 0x464F4E54L 29 | 30 | /*------ collection of flags for defining characteristics. ---*/ 31 | 32 | #define HPDF_FONT_FIXED_WIDTH 1 33 | #define HPDF_FONT_SERIF 2 34 | #define HPDF_FONT_SYMBOLIC 4 35 | #define HPDF_FONT_SCRIPT 8 36 | /* Reserved 16 */ 37 | #define HPDF_FONT_STD_CHARSET 32 38 | #define HPDF_FONT_ITALIC 64 39 | /* Reserved 128 40 | Reserved 256 41 | Reserved 512 42 | Reserved 1024 43 | Reserved 2048 44 | Reserved 4096 45 | Reserved 8192 46 | Reserved 16384 47 | Reserved 32768 */ 48 | #define HPDF_FONT_ALL_CAP 65536 49 | #define HPDF_FONT_SMALL_CAP 131072 50 | #define HPDF_FONT_FOURCE_BOLD 262144 51 | 52 | #define HPDF_CID_W_TYPE_FROM_TO 0 53 | #define HPDF_CID_W_TYPE_FROM_ARRAY 1 54 | 55 | /*-- HPDF_FontDef ---------------------------------------*/ 56 | 57 | typedef struct _HPDF_CharData { 58 | HPDF_INT16 char_cd; 59 | HPDF_UNICODE unicode; 60 | HPDF_INT16 width; 61 | } HPDF_CharData; 62 | 63 | typedef enum _HPDF_FontDefType { 64 | HPDF_FONTDEF_TYPE_TYPE1, 65 | HPDF_FONTDEF_TYPE_TRUETYPE, 66 | HPDF_FONTDEF_TYPE_CID, 67 | HPDF_FONTDEF_TYPE_UNINITIALIZED, 68 | HPDF_FONTDEF_TYPE_EOF 69 | } HPDF_FontDefType; 70 | 71 | typedef struct _HPDF_CID_Width { 72 | HPDF_UINT16 cid; 73 | HPDF_INT16 width; 74 | } HPDF_CID_Width; 75 | 76 | /*----------------------------------------------------------------------------*/ 77 | /*----- HPDF_FontDef ---------------------------------------------------------*/ 78 | 79 | typedef struct _HPDF_FontDef_Rec *HPDF_FontDef; 80 | 81 | typedef void (*HPDF_FontDef_FreeFunc) (HPDF_FontDef fontdef); 82 | 83 | typedef void (*HPDF_FontDef_CleanFunc) (HPDF_FontDef fontdef); 84 | 85 | typedef HPDF_STATUS (*HPDF_FontDef_InitFunc) (HPDF_FontDef fontdef); 86 | 87 | typedef struct _HPDF_FontDef_Rec { 88 | HPDF_UINT32 sig_bytes; 89 | char base_font[HPDF_LIMIT_MAX_NAME_LEN + 1]; 90 | HPDF_MMgr mmgr; 91 | HPDF_Error error; 92 | HPDF_FontDefType type; 93 | HPDF_FontDef_CleanFunc clean_fn; 94 | HPDF_FontDef_FreeFunc free_fn; 95 | HPDF_FontDef_InitFunc init_fn; 96 | 97 | HPDF_INT16 ascent; 98 | HPDF_INT16 descent; 99 | HPDF_UINT flags; 100 | HPDF_Box font_bbox; 101 | HPDF_INT16 italic_angle; 102 | HPDF_UINT16 stemv; 103 | HPDF_INT16 avg_width; 104 | HPDF_INT16 max_width; 105 | HPDF_INT16 missing_width; 106 | HPDF_UINT16 stemh; 107 | HPDF_UINT16 x_height; 108 | HPDF_UINT16 cap_height; 109 | 110 | /* the initial value of descriptor entry is NULL. 111 | * when first font-object besed on the fontdef object is created, 112 | * the font-descriptor object is created and descriptor entry is set. 113 | */ 114 | HPDF_Dict descriptor; 115 | HPDF_Stream data; 116 | 117 | HPDF_BOOL valid; 118 | void *attr; 119 | } HPDF_FontDef_Rec; 120 | 121 | 122 | void 123 | HPDF_FontDef_Free (HPDF_FontDef fontdef); 124 | 125 | 126 | void 127 | HPDF_FontDef_Cleanup (HPDF_FontDef fontdef); 128 | 129 | 130 | HPDF_BOOL 131 | HPDF_FontDef_Validate (HPDF_FontDef fontdef); 132 | 133 | 134 | /*----------------------------------------------------------------------------*/ 135 | /*----- HPDF_Type1FontDef ---------------------------------------------------*/ 136 | 137 | typedef struct _HPDF_Type1FontDefAttrRec *HPDF_Type1FontDefAttr; 138 | 139 | typedef struct _HPDF_Type1FontDefAttrRec { 140 | HPDF_BYTE first_char; /* Required */ 141 | HPDF_BYTE last_char; /* Required */ 142 | HPDF_CharData *widths; /* Required */ 143 | HPDF_UINT widths_count; 144 | 145 | HPDF_INT16 leading; 146 | char *char_set; 147 | char encoding_scheme[HPDF_LIMIT_MAX_NAME_LEN + 1]; 148 | HPDF_UINT length1; 149 | HPDF_UINT length2; 150 | HPDF_UINT length3; 151 | HPDF_BOOL is_base14font; 152 | HPDF_BOOL is_fixed_pitch; 153 | 154 | HPDF_Stream font_data; 155 | } HPDF_Type1FontDefAttr_Rec; 156 | 157 | 158 | 159 | HPDF_FontDef 160 | HPDF_Type1FontDef_New (HPDF_MMgr mmgr); 161 | 162 | 163 | HPDF_FontDef 164 | HPDF_Type1FontDef_Load (HPDF_MMgr mmgr, 165 | HPDF_Stream afm, 166 | HPDF_Stream font_data); 167 | 168 | 169 | HPDF_FontDef 170 | HPDF_Type1FontDef_Duplicate (HPDF_MMgr mmgr, 171 | HPDF_FontDef src); 172 | 173 | 174 | HPDF_STATUS 175 | HPDF_Type1FontDef_SetWidths (HPDF_FontDef fontdef, 176 | const HPDF_CharData *widths); 177 | 178 | 179 | HPDF_INT16 180 | HPDF_Type1FontDef_GetWidthByName (HPDF_FontDef fontdef, 181 | const char *gryph_name); 182 | 183 | 184 | HPDF_INT16 185 | HPDF_Type1FontDef_GetWidth (HPDF_FontDef fontdef, 186 | HPDF_UNICODE unicode); 187 | 188 | 189 | HPDF_FontDef 190 | HPDF_Base14FontDef_New (HPDF_MMgr mmgr, 191 | const char *font_name); 192 | 193 | 194 | 195 | /*----------------------------------------------------------------------------*/ 196 | /*----- HPDF_TTFontDef ------------------------------------------------------*/ 197 | 198 | #define HPDF_TTF_FONT_TAG_LEN 6 199 | 200 | typedef struct _HPDF_TTF_Table { 201 | char tag[4]; 202 | HPDF_UINT32 check_sum; 203 | HPDF_UINT32 offset; 204 | HPDF_UINT32 length; 205 | } HPDF_TTFTable; 206 | 207 | 208 | typedef struct _HPDF_TTF_OffsetTbl { 209 | HPDF_UINT32 sfnt_version; 210 | HPDF_UINT16 num_tables; 211 | HPDF_UINT16 search_range; 212 | HPDF_UINT16 entry_selector; 213 | HPDF_UINT16 range_shift; 214 | HPDF_TTFTable *table; 215 | } HPDF_TTF_OffsetTbl; 216 | 217 | 218 | typedef struct _HPDF_TTF_CmapRange { 219 | HPDF_UINT16 format; 220 | HPDF_UINT16 length; 221 | HPDF_UINT16 language; 222 | HPDF_UINT16 seg_count_x2; 223 | HPDF_UINT16 search_range; 224 | HPDF_UINT16 entry_selector; 225 | HPDF_UINT16 range_shift; 226 | HPDF_UINT16 *end_count; 227 | HPDF_UINT16 reserved_pad; 228 | HPDF_UINT16 *start_count; 229 | HPDF_INT16 *id_delta; 230 | HPDF_UINT16 *id_range_offset; 231 | HPDF_UINT16 *glyph_id_array; 232 | HPDF_UINT glyph_id_array_count; 233 | } HPDF_TTF_CmapRange; 234 | 235 | 236 | typedef struct _HPDF_TTF_GryphOffsets { 237 | HPDF_UINT32 base_offset; 238 | HPDF_UINT32 *offsets; 239 | HPDF_BYTE *flgs; /* 0: unused, 1: used */ 240 | } HPDF_TTF_GryphOffsets; 241 | 242 | 243 | typedef struct _HPDF_TTF_LongHorMetric { 244 | HPDF_UINT16 advance_width; 245 | HPDF_INT16 lsb; 246 | } HPDF_TTF_LongHorMetric; 247 | 248 | 249 | typedef struct _HPDF_TTF_FontHeader { 250 | HPDF_BYTE version_number[4]; 251 | HPDF_UINT32 font_revision; 252 | HPDF_UINT32 check_sum_adjustment; 253 | HPDF_UINT32 magic_number; 254 | HPDF_UINT16 flags; 255 | HPDF_UINT16 units_per_em; 256 | HPDF_BYTE created[8]; 257 | HPDF_BYTE modified[8]; 258 | HPDF_INT16 x_min; 259 | HPDF_INT16 y_min; 260 | HPDF_INT16 x_max; 261 | HPDF_INT16 y_max; 262 | HPDF_UINT16 mac_style; 263 | HPDF_UINT16 lowest_rec_ppem; 264 | HPDF_INT16 font_direction_hint; 265 | HPDF_INT16 index_to_loc_format; 266 | HPDF_INT16 glyph_data_format; 267 | } HPDF_TTF_FontHeader; 268 | 269 | 270 | typedef struct _HPDF_TTF_NameRecord { 271 | HPDF_UINT16 platform_id; 272 | HPDF_UINT16 encoding_id; 273 | HPDF_UINT16 language_id; 274 | HPDF_UINT16 name_id; 275 | HPDF_UINT16 length; 276 | HPDF_UINT16 offset; 277 | } HPDF_TTF_NameRecord; 278 | 279 | 280 | typedef struct _HPDF_TTF_NamingTable { 281 | HPDF_UINT16 format; 282 | HPDF_UINT16 count; 283 | HPDF_UINT16 string_offset; 284 | HPDF_TTF_NameRecord *name_records; 285 | } HPDF_TTF_NamingTable; 286 | 287 | 288 | typedef struct _HPDF_TTFontDefAttr_Rec *HPDF_TTFontDefAttr; 289 | 290 | typedef struct _HPDF_TTFontDefAttr_Rec { 291 | char base_font[HPDF_LIMIT_MAX_NAME_LEN + 1]; 292 | HPDF_BYTE first_char; 293 | HPDF_BYTE last_char; 294 | char *char_set; 295 | char tag_name[HPDF_TTF_FONT_TAG_LEN + 1]; 296 | char tag_name2[(HPDF_TTF_FONT_TAG_LEN + 1) * 2]; 297 | HPDF_TTF_FontHeader header; 298 | HPDF_TTF_GryphOffsets glyph_tbl; 299 | HPDF_UINT16 num_glyphs; 300 | HPDF_TTF_NamingTable name_tbl; 301 | HPDF_TTF_LongHorMetric *h_metric; 302 | HPDF_UINT16 num_h_metric; 303 | HPDF_TTF_OffsetTbl offset_tbl; 304 | HPDF_TTF_CmapRange cmap; 305 | HPDF_UINT16 fs_type; 306 | HPDF_BYTE panose[12]; 307 | HPDF_UINT32 code_page_range1; 308 | HPDF_UINT32 code_page_range2; 309 | 310 | HPDF_UINT length1; 311 | 312 | HPDF_BOOL embedding; 313 | HPDF_BOOL is_cidfont; 314 | 315 | HPDF_Stream stream; 316 | } HPDF_TTFontDefAttr_Rec; 317 | 318 | 319 | 320 | HPDF_FontDef 321 | HPDF_TTFontDef_New (HPDF_MMgr mmgr); 322 | 323 | 324 | HPDF_FontDef 325 | HPDF_TTFontDef_Load (HPDF_MMgr mmgr, 326 | HPDF_Stream stream, 327 | HPDF_BOOL embedding); 328 | 329 | 330 | HPDF_FontDef 331 | HPDF_TTFontDef_Load2 (HPDF_MMgr mmgr, 332 | HPDF_Stream stream, 333 | HPDF_UINT index, 334 | HPDF_BOOL embedding); 335 | 336 | 337 | HPDF_UINT16 338 | HPDF_TTFontDef_GetGlyphid (HPDF_FontDef fontdef, 339 | HPDF_UINT16 unicode); 340 | 341 | 342 | HPDF_INT16 343 | HPDF_TTFontDef_GetCharWidth (HPDF_FontDef fontdef, 344 | HPDF_UINT16 unicode); 345 | 346 | 347 | HPDF_INT16 348 | HPDF_TTFontDef_GetGidWidth (HPDF_FontDef fontdef, 349 | HPDF_UINT16 gid); 350 | 351 | 352 | HPDF_STATUS 353 | HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef, 354 | HPDF_Stream stream); 355 | 356 | 357 | HPDF_Box 358 | HPDF_TTFontDef_GetCharBBox (HPDF_FontDef fontdef, 359 | HPDF_UINT16 unicode); 360 | 361 | 362 | void 363 | HPDF_TTFontDef_SetTagName (HPDF_FontDef fontdef, 364 | char *tag); 365 | 366 | 367 | /*----------------------------------------------------------------------------*/ 368 | /*----- HPDF_CIDFontDef -----------------------------------------------------*/ 369 | 370 | typedef struct _HPDF_CIDFontDefAttrRec *HPDF_CIDFontDefAttr; 371 | 372 | typedef struct _HPDF_CIDFontDefAttrRec { 373 | HPDF_List widths; 374 | HPDF_INT16 DW; 375 | HPDF_INT16 DW2[2]; 376 | } HPDF_CIDFontDefAttr_Rec; 377 | 378 | 379 | HPDF_FontDef 380 | HPDF_CIDFontDef_New (HPDF_MMgr mmgr, 381 | char *name, 382 | HPDF_FontDef_InitFunc init_fn); 383 | 384 | 385 | HPDF_STATUS 386 | HPDF_CIDFontDef_AddWidth (HPDF_FontDef fontdef, 387 | const HPDF_CID_Width *widths); 388 | 389 | 390 | HPDF_INT16 391 | HPDF_CIDFontDef_GetCIDWidth (HPDF_FontDef fontdef, 392 | HPDF_UINT16 cid); 393 | 394 | 395 | 396 | HPDF_STATUS 397 | HPDF_CIDFontDef_ChangeStyle (HPDF_FontDef fontdef, 398 | HPDF_BOOL bold, 399 | HPDF_BOOL italic); 400 | 401 | #ifdef __cplusplus 402 | } 403 | #endif /* __cplusplus */ 404 | 405 | #endif /* _HPDF_FONTDEF_H */ 406 | 407 | -------------------------------------------------------------------------------- /C/hpdf_gstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_gstate.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_GSTATE_H 19 | #define _HPDF_GSTATE_H 20 | 21 | #include "hpdf_font.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /*----------------------------------------------------------------------------*/ 29 | /*------ graphic state stack -------------------------------------------------*/ 30 | 31 | typedef struct _HPDF_GState_Rec *HPDF_GState; 32 | 33 | typedef struct _HPDF_GState_Rec { 34 | HPDF_TransMatrix trans_matrix; 35 | HPDF_REAL line_width; 36 | HPDF_LineCap line_cap; 37 | HPDF_LineJoin line_join; 38 | HPDF_REAL miter_limit; 39 | HPDF_DashMode dash_mode; 40 | HPDF_REAL flatness; 41 | 42 | HPDF_REAL char_space; 43 | HPDF_REAL word_space; 44 | HPDF_REAL h_scalling; 45 | HPDF_REAL text_leading; 46 | HPDF_TextRenderingMode rendering_mode; 47 | HPDF_REAL text_rise; 48 | 49 | HPDF_ColorSpace cs_fill; 50 | HPDF_ColorSpace cs_stroke; 51 | HPDF_RGBColor rgb_fill; 52 | HPDF_RGBColor rgb_stroke; 53 | HPDF_CMYKColor cmyk_fill; 54 | HPDF_CMYKColor cmyk_stroke; 55 | HPDF_REAL gray_fill; 56 | HPDF_REAL gray_stroke; 57 | 58 | HPDF_Font font; 59 | HPDF_REAL font_size; 60 | HPDF_WritingMode writing_mode; 61 | 62 | HPDF_GState prev; 63 | HPDF_UINT depth; 64 | } HPDF_GState_Rec; 65 | 66 | /*----------------------------------------------------------------------------*/ 67 | /*----------------------------------------------------------------------------*/ 68 | 69 | HPDF_GState 70 | HPDF_GState_New (HPDF_MMgr mmgr, 71 | HPDF_GState current); 72 | 73 | 74 | HPDF_GState 75 | HPDF_GState_Free (HPDF_MMgr mmgr, 76 | HPDF_GState gstate); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif /* __cplusplus */ 81 | 82 | #endif /* _HPDF_GSTATE_H */ 83 | 84 | -------------------------------------------------------------------------------- /C/hpdf_image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_image.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_IMAGE_H 19 | #define _HPDF_IMAGE_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #ifndef LIBHPDF_HAVE_NOPNGLIB 28 | 29 | HPDF_Image 30 | HPDF_Image_LoadPngImage (HPDF_MMgr mmgr, 31 | HPDF_Stream png_data, 32 | HPDF_Xref xref, 33 | HPDF_BOOL delayed_loading); 34 | 35 | #endif 36 | 37 | HPDF_Image 38 | HPDF_Image_LoadJpegImage (HPDF_MMgr mmgr, 39 | HPDF_Stream jpeg_data, 40 | HPDF_Xref xref); 41 | 42 | HPDF_Image 43 | HPDF_Image_LoadJpegImageFromMem (HPDF_MMgr mmgr, 44 | const HPDF_BYTE *buf, 45 | HPDF_UINT size, 46 | HPDF_Xref xref); 47 | 48 | HPDF_Image 49 | HPDF_Image_LoadRawImage (HPDF_MMgr mmgr, 50 | HPDF_Stream stream, 51 | HPDF_Xref xref, 52 | HPDF_UINT width, 53 | HPDF_UINT height, 54 | HPDF_ColorSpace color_space); 55 | 56 | 57 | HPDF_Image 58 | HPDF_Image_LoadRawImageFromMem (HPDF_MMgr mmgr, 59 | const HPDF_BYTE *buf, 60 | HPDF_Xref xref, 61 | HPDF_UINT width, 62 | HPDF_UINT height, 63 | HPDF_ColorSpace color_space, 64 | HPDF_UINT bits_per_component); 65 | 66 | 67 | HPDF_BOOL 68 | HPDF_Image_Validate (HPDF_Image image); 69 | 70 | 71 | HPDF_STATUS 72 | HPDF_Image_SetMask (HPDF_Image image, 73 | HPDF_BOOL mask); 74 | 75 | HPDF_STATUS 76 | HPDF_Image_SetColorSpace (HPDF_Image image, 77 | HPDF_Array colorspace); 78 | 79 | HPDF_STATUS 80 | HPDF_Image_SetRenderingIntent (HPDF_Image image, 81 | const char* intent); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif /* __cplusplus */ 86 | 87 | #endif /* _HPDF_XOBJECTS_H */ 88 | 89 | -------------------------------------------------------------------------------- /C/hpdf_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_info.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | 19 | #ifndef _HPDF_INFO_H 20 | #define _HPDF_INFO_H 21 | 22 | #include "hpdf_objects.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | HPDF_STATUS 30 | HPDF_Info_SetInfoAttr (HPDF_Dict info, 31 | HPDF_InfoType type, 32 | const char *value, 33 | HPDF_Encoder encoder); 34 | 35 | 36 | const char* 37 | HPDF_Info_GetInfoAttr (HPDF_Dict info, 38 | HPDF_InfoType type); 39 | 40 | 41 | HPDF_STATUS 42 | HPDF_Info_SetInfoDateAttr (HPDF_Dict info, 43 | HPDF_InfoType type, 44 | HPDF_Date value); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif /* __cplusplus */ 49 | 50 | #endif /* _HPDF_INFO_H */ 51 | 52 | -------------------------------------------------------------------------------- /C/hpdf_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_list.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_LIST_H 19 | #define _HPDF_LIST_H 20 | 21 | #include "hpdf_error.h" 22 | #include "hpdf_mmgr.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef struct _HPDF_List_Rec *HPDF_List; 29 | 30 | typedef struct _HPDF_List_Rec { 31 | HPDF_MMgr mmgr; 32 | HPDF_Error error; 33 | HPDF_UINT block_siz; 34 | HPDF_UINT items_per_block; 35 | HPDF_UINT count; 36 | void **obj; 37 | } HPDF_List_Rec; 38 | 39 | 40 | HPDF_List 41 | HPDF_List_New (HPDF_MMgr mmgr, 42 | HPDF_UINT items_per_block); 43 | 44 | 45 | void 46 | HPDF_List_Free (HPDF_List list); 47 | 48 | 49 | HPDF_STATUS 50 | HPDF_List_Add (HPDF_List list, 51 | void *item); 52 | 53 | 54 | HPDF_STATUS 55 | HPDF_List_Insert (HPDF_List list, 56 | void *target, 57 | void *item); 58 | 59 | 60 | HPDF_STATUS 61 | HPDF_List_Remove (HPDF_List list, 62 | void *item); 63 | 64 | 65 | void* 66 | HPDF_List_RemoveByIndex (HPDF_List list, 67 | HPDF_UINT index); 68 | 69 | 70 | void* 71 | HPDF_List_ItemAt (HPDF_List list, 72 | HPDF_UINT index); 73 | 74 | 75 | HPDF_INT32 76 | HPDF_List_Find (HPDF_List list, 77 | void *item); 78 | 79 | 80 | void 81 | HPDF_List_Clear (HPDF_List list); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif /* __cplusplus */ 86 | 87 | #endif /* _HPDF_LIST_H */ 88 | 89 | -------------------------------------------------------------------------------- /C/hpdf_mmgr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_mmgr.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_MMGR_H 19 | #define _HPDF_MMGR_H 20 | 21 | #include "hpdf_types.h" 22 | #include "hpdf_error.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef struct _HPDF_MPool_Node_Rec *HPDF_MPool_Node; 29 | 30 | typedef struct _HPDF_MPool_Node_Rec { 31 | HPDF_BYTE* buf; 32 | HPDF_UINT size; 33 | HPDF_UINT used_size; 34 | HPDF_MPool_Node next_node; 35 | } HPDF_MPool_Node_Rec; 36 | 37 | 38 | typedef struct _HPDF_MMgr_Rec *HPDF_MMgr; 39 | 40 | typedef struct _HPDF_MMgr_Rec { 41 | HPDF_Error error; 42 | HPDF_Alloc_Func alloc_fn; 43 | HPDF_Free_Func free_fn; 44 | HPDF_MPool_Node mpool; 45 | HPDF_UINT buf_size; 46 | 47 | #ifdef HPDF_MEM_DEBUG 48 | HPDF_UINT alloc_cnt; 49 | HPDF_UINT free_cnt; 50 | #endif 51 | } HPDF_MMgr_Rec; 52 | 53 | 54 | /* HPDF_mpool_new 55 | * 56 | * create new HPDF_mpool object. when memory allocation goes wrong, 57 | * it returns NULL and error handling function will be called. 58 | * if buf_size is non-zero, mmgr is configured to be using memory-pool 59 | */ 60 | HPDF_MMgr 61 | HPDF_MMgr_New (HPDF_Error error, 62 | HPDF_UINT buf_size, 63 | HPDF_Alloc_Func alloc_fn, 64 | HPDF_Free_Func free_fn); 65 | 66 | 67 | void 68 | HPDF_MMgr_Free (HPDF_MMgr mmgr); 69 | 70 | 71 | void* 72 | HPDF_GetMem (HPDF_MMgr mmgr, 73 | HPDF_UINT size); 74 | 75 | 76 | void 77 | HPDF_FreeMem (HPDF_MMgr mmgr, 78 | void *aptr); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif /* __cplusplus */ 83 | 84 | #endif /* _HPDF_MMGR_H */ 85 | 86 | -------------------------------------------------------------------------------- /C/hpdf_namedict.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_namedict.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_NAMEDICT_H 19 | #define _HPDF_NAMEDICT_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | HPDF_NameDict 29 | HPDF_NameDict_New (HPDF_MMgr mmgr, 30 | HPDF_Xref xref); 31 | 32 | HPDF_NameTree 33 | HPDF_NameDict_GetNameTree (HPDF_NameDict namedict, 34 | HPDF_NameDictKey key); 35 | 36 | HPDF_STATUS 37 | HPDF_NameDict_SetNameTree (HPDF_NameDict namedict, 38 | HPDF_NameDictKey key, 39 | HPDF_NameTree tree); 40 | 41 | HPDF_BOOL 42 | HPDF_NameDict_Validate (HPDF_NameDict namedict); 43 | 44 | 45 | /*------- NameTree -------*/ 46 | 47 | HPDF_NameTree 48 | HPDF_NameTree_New (HPDF_MMgr mmgr, 49 | HPDF_Xref xref); 50 | 51 | HPDF_STATUS 52 | HPDF_NameTree_Add (HPDF_NameTree tree, 53 | HPDF_String name, 54 | void *obj); 55 | 56 | HPDF_BOOL 57 | HPDF_NameTree_Validate (HPDF_NameTree tree); 58 | 59 | 60 | /*------- EmbeddedFile -------*/ 61 | 62 | HPDF_EmbeddedFile 63 | HPDF_EmbeddedFile_New (HPDF_MMgr mmgr, 64 | HPDF_Xref xref, 65 | const char *file); 66 | 67 | HPDF_BOOL 68 | HPDF_EmbeddedFile_Validate (HPDF_EmbeddedFile emfile); 69 | 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif /* __cplusplus */ 74 | 75 | #endif /* _HPDF_NAMEDICT_H */ 76 | 77 | -------------------------------------------------------------------------------- /C/hpdf_objects.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/C/hpdf_objects.h -------------------------------------------------------------------------------- /C/hpdf_outline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_outline.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_OUTLINE_H 19 | #define _HPDF_OUTLINE_H 20 | 21 | #include "hpdf_objects.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /*----------------------------------------------------------------------------*/ 29 | /*----- HPDF_Outline ---------------------------------------------------------*/ 30 | 31 | HPDF_Outline 32 | HPDF_OutlineRoot_New (HPDF_MMgr mmgr, 33 | HPDF_Xref xref); 34 | 35 | 36 | HPDF_Outline 37 | HPDF_Outline_New (HPDF_MMgr mmgr, 38 | HPDF_Outline parent, 39 | const char *title, 40 | HPDF_Encoder encoder, 41 | HPDF_Xref xref); 42 | 43 | 44 | HPDF_Outline 45 | HPDF_Outline_GetFirst (HPDF_Outline outline); 46 | 47 | 48 | HPDF_Outline 49 | HPDF_Outline_GetLast (HPDF_Outline outline); 50 | 51 | 52 | HPDF_Outline 53 | HPDF_Outline_GetPrev(HPDF_Outline outline); 54 | 55 | 56 | HPDF_Outline 57 | HPDF_Outline_GetNext (HPDF_Outline outline); 58 | 59 | 60 | HPDF_Outline 61 | HPDF_Outline_GetParent (HPDF_Outline outline); 62 | 63 | 64 | HPDF_BOOL 65 | HPDF_Outline_GetOpened (HPDF_Outline outline); 66 | 67 | 68 | 69 | HPDF_BOOL 70 | HPDF_Outline_Validate (HPDF_Outline obj); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif /* __cplusplus */ 75 | 76 | #endif /* _HPDF_OUTLINE_H */ 77 | 78 | -------------------------------------------------------------------------------- /C/hpdf_page_label.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_page_label.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_PAGE_LABEL_H 19 | #define _HPDF_PAGE_LABEL_H 20 | 21 | #include "hpdf.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | HPDF_Dict 28 | HPDF_PageLabel_New (HPDF_Doc pdf, 29 | HPDF_PageNumStyle style, 30 | HPDF_INT first_page, 31 | const char *prefix); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /* __cplusplus */ 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /C/hpdf_pages.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_pages.c 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_PAGES_H 19 | #define _HPDF_PAGES_H 20 | 21 | #include "hpdf_gstate.h" 22 | #include "hpdf_ext_gstate.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /*----------------------------------------------------------------------------*/ 29 | /*----- HPDF_Pages -----------------------------------------------------------*/ 30 | 31 | HPDF_Pages 32 | HPDF_Pages_New (HPDF_MMgr mmgr, 33 | HPDF_Pages parent, 34 | HPDF_Xref xref); 35 | 36 | 37 | HPDF_BOOL 38 | HPDF_Pages_Validate (HPDF_Pages pages); 39 | 40 | 41 | HPDF_STATUS 42 | HPDF_Pages_AddKids (HPDF_Pages parent, 43 | HPDF_Dict kid); 44 | 45 | 46 | HPDF_STATUS 47 | HPDF_Page_InsertBefore (HPDF_Page page, 48 | HPDF_Page target); 49 | 50 | 51 | typedef struct _HPDF_PageAttr_Rec *HPDF_PageAttr; 52 | 53 | typedef struct _HPDF_PageAttr_Rec { 54 | HPDF_Pages parent; 55 | HPDF_Dict fonts; 56 | HPDF_Dict xobjects; 57 | HPDF_Dict ext_gstates; 58 | HPDF_GState gstate; 59 | HPDF_Point str_pos; 60 | HPDF_Point cur_pos; 61 | HPDF_Point text_pos; 62 | HPDF_TransMatrix text_matrix; 63 | HPDF_UINT16 gmode; 64 | HPDF_Dict contents; 65 | HPDF_Stream stream; 66 | HPDF_Xref xref; 67 | HPDF_UINT compression_mode; 68 | HPDF_PDFVer *ver; 69 | } HPDF_PageAttr_Rec; 70 | 71 | 72 | /*----------------------------------------------------------------------------*/ 73 | /*----- HPDF_Page ------------------------------------------------------------*/ 74 | 75 | HPDF_BOOL 76 | HPDF_Page_Validate (HPDF_Page page); 77 | 78 | 79 | HPDF_Page 80 | HPDF_Page_New (HPDF_MMgr mmgr, 81 | HPDF_Xref xref); 82 | 83 | 84 | void* 85 | HPDF_Page_GetInheritableItem (HPDF_Page page, 86 | const char *key, 87 | HPDF_UINT16 obj_class); 88 | 89 | 90 | const char* 91 | HPDF_Page_GetXObjectName (HPDF_Page page, 92 | HPDF_XObject xobj); 93 | 94 | 95 | const char* 96 | HPDF_Page_GetLocalFontName (HPDF_Page page, 97 | HPDF_Font font); 98 | 99 | 100 | const char* 101 | HPDF_Page_GetExtGStateName (HPDF_Page page, 102 | HPDF_ExtGState gstate); 103 | 104 | 105 | HPDF_Box 106 | HPDF_Page_GetMediaBox (HPDF_Page page); 107 | 108 | 109 | HPDF_STATUS 110 | HPDF_Page_SetBoxValue (HPDF_Page page, 111 | const char *name, 112 | HPDF_UINT index, 113 | HPDF_REAL value); 114 | 115 | 116 | void 117 | HPDF_Page_SetFilter (HPDF_Page page, 118 | HPDF_UINT filter); 119 | 120 | 121 | HPDF_STATUS 122 | HPDF_Page_CheckState (HPDF_Page page, 123 | HPDF_UINT mode); 124 | 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif /* __cplusplus */ 129 | 130 | #endif /* _HPDF_PAGES_H */ 131 | 132 | -------------------------------------------------------------------------------- /C/hpdf_pdfa.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_pdfa.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_PDFA_H 19 | #define _HPDF_PDFA_H 20 | 21 | #include "hpdf_doc.h" 22 | #include "hpdf_objects.h" 23 | 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | HPDF_STATUS 31 | HPDF_PDFA_SetPDFAConformance (HPDF_Doc pdf, 32 | HPDF_PDFAType pdfatype); 33 | 34 | HPDF_STATUS 35 | HPDF_PDFA_GenerateID(HPDF_Doc); 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /C/hpdf_streams.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- hpdf_streams.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | * 2005.12.20 Created. 17 | * 18 | */ 19 | 20 | #ifndef _HPDF_STREAMS_H 21 | #define _HPDF_STREAMS_H 22 | 23 | #include "hpdf_list.h" 24 | #include "hpdf_encrypt.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | #define HPDF_STREAM_SIG_BYTES 0x5354524DL 32 | 33 | typedef enum _HPDF_StreamType { 34 | HPDF_STREAM_UNKNOWN = 0, 35 | HPDF_STREAM_CALLBACK, 36 | HPDF_STREAM_FILE, 37 | HPDF_STREAM_MEMORY 38 | } HPDF_StreamType; 39 | 40 | #define HPDF_STREAM_FILTER_NONE 0x0000 41 | #define HPDF_STREAM_FILTER_ASCIIHEX 0x0100 42 | #define HPDF_STREAM_FILTER_ASCII85 0x0200 43 | #define HPDF_STREAM_FILTER_FLATE_DECODE 0x0400 44 | #define HPDF_STREAM_FILTER_DCT_DECODE 0x0800 45 | 46 | typedef enum _HPDF_WhenceMode { 47 | HPDF_SEEK_SET = 0, 48 | HPDF_SEEK_CUR, 49 | HPDF_SEEK_END 50 | } HPDF_WhenceMode; 51 | 52 | typedef struct _HPDF_Stream_Rec *HPDF_Stream; 53 | 54 | typedef HPDF_STATUS 55 | (*HPDF_Stream_Write_Func) (HPDF_Stream stream, 56 | const HPDF_BYTE *ptr, 57 | HPDF_UINT siz); 58 | 59 | 60 | typedef HPDF_STATUS 61 | (*HPDF_Stream_Read_Func) (HPDF_Stream stream, 62 | HPDF_BYTE *ptr, 63 | HPDF_UINT *siz); 64 | 65 | 66 | typedef HPDF_STATUS 67 | (*HPDF_Stream_Seek_Func) (HPDF_Stream stream, 68 | HPDF_INT pos, 69 | HPDF_WhenceMode mode); 70 | 71 | 72 | typedef HPDF_INT32 73 | (*HPDF_Stream_Tell_Func) (HPDF_Stream stream); 74 | 75 | 76 | typedef void 77 | (*HPDF_Stream_Free_Func) (HPDF_Stream stream); 78 | 79 | 80 | typedef HPDF_UINT32 81 | (*HPDF_Stream_Size_Func) (HPDF_Stream stream); 82 | 83 | 84 | typedef struct _HPDF_MemStreamAttr_Rec *HPDF_MemStreamAttr; 85 | 86 | 87 | typedef struct _HPDF_MemStreamAttr_Rec { 88 | HPDF_List buf; 89 | HPDF_UINT buf_siz; 90 | HPDF_UINT w_pos; 91 | HPDF_BYTE *w_ptr; 92 | HPDF_UINT r_ptr_idx; 93 | HPDF_UINT r_pos; 94 | HPDF_BYTE *r_ptr; 95 | } HPDF_MemStreamAttr_Rec; 96 | 97 | 98 | typedef struct _HPDF_Stream_Rec { 99 | HPDF_UINT32 sig_bytes; 100 | HPDF_StreamType type; 101 | HPDF_MMgr mmgr; 102 | HPDF_Error error; 103 | HPDF_UINT size; 104 | HPDF_Stream_Write_Func write_fn; 105 | HPDF_Stream_Read_Func read_fn; 106 | HPDF_Stream_Seek_Func seek_fn; 107 | HPDF_Stream_Free_Func free_fn; 108 | HPDF_Stream_Tell_Func tell_fn; 109 | HPDF_Stream_Size_Func size_fn; 110 | void* attr; 111 | } HPDF_Stream_Rec; 112 | 113 | 114 | 115 | HPDF_Stream 116 | HPDF_MemStream_New (HPDF_MMgr mmgr, 117 | HPDF_UINT buf_siz); 118 | 119 | 120 | HPDF_BYTE* 121 | HPDF_MemStream_GetBufPtr (HPDF_Stream stream, 122 | HPDF_UINT index, 123 | HPDF_UINT *length); 124 | 125 | 126 | HPDF_UINT 127 | HPDF_MemStream_GetBufSize (HPDF_Stream stream); 128 | 129 | 130 | HPDF_UINT 131 | HPDF_MemStream_GetBufCount (HPDF_Stream stream); 132 | 133 | 134 | HPDF_STATUS 135 | HPDF_MemStream_Rewrite (HPDF_Stream stream, 136 | HPDF_BYTE *buf, 137 | HPDF_UINT size); 138 | 139 | 140 | void 141 | HPDF_MemStream_FreeData (HPDF_Stream stream); 142 | 143 | 144 | HPDF_STATUS 145 | HPDF_Stream_WriteToStream (HPDF_Stream src, 146 | HPDF_Stream dst, 147 | HPDF_UINT filter, 148 | HPDF_Encrypt e); 149 | 150 | 151 | HPDF_Stream 152 | HPDF_FileReader_New (HPDF_MMgr mmgr, 153 | const char *fname); 154 | 155 | 156 | HPDF_Stream 157 | HPDF_FileWriter_New (HPDF_MMgr mmgr, 158 | const char *fname); 159 | 160 | 161 | HPDF_Stream 162 | HPDF_CallbackReader_New (HPDF_MMgr mmgr, 163 | HPDF_Stream_Read_Func read_fn, 164 | HPDF_Stream_Seek_Func seek_fn, 165 | HPDF_Stream_Tell_Func tell_fn, 166 | HPDF_Stream_Size_Func size_fn, 167 | void* data); 168 | 169 | 170 | HPDF_Stream 171 | HPDF_CallbackWriter_New (HPDF_MMgr mmgr, 172 | HPDF_Stream_Write_Func write_fn, 173 | void* data); 174 | 175 | 176 | void 177 | HPDF_Stream_Free (HPDF_Stream stream); 178 | 179 | 180 | HPDF_STATUS 181 | HPDF_Stream_WriteChar (HPDF_Stream stream, 182 | char value); 183 | 184 | 185 | HPDF_STATUS 186 | HPDF_Stream_WriteStr (HPDF_Stream stream, 187 | const char *value); 188 | 189 | 190 | HPDF_STATUS 191 | HPDF_Stream_WriteUChar (HPDF_Stream stream, 192 | HPDF_BYTE value); 193 | 194 | 195 | HPDF_STATUS 196 | HPDF_Stream_WriteInt (HPDF_Stream stream, 197 | HPDF_INT value); 198 | 199 | 200 | HPDF_STATUS 201 | HPDF_Stream_WriteUInt (HPDF_Stream stream, 202 | HPDF_UINT value); 203 | 204 | 205 | HPDF_STATUS 206 | HPDF_Stream_WriteReal (HPDF_Stream stream, 207 | HPDF_REAL value); 208 | 209 | 210 | HPDF_STATUS 211 | HPDF_Stream_Write (HPDF_Stream stream, 212 | const HPDF_BYTE *ptr, 213 | HPDF_UINT size); 214 | 215 | 216 | HPDF_STATUS 217 | HPDF_Stream_Read (HPDF_Stream stream, 218 | HPDF_BYTE *ptr, 219 | HPDF_UINT *size); 220 | 221 | HPDF_STATUS 222 | HPDF_Stream_ReadLn (HPDF_Stream stream, 223 | char *s, 224 | HPDF_UINT *size); 225 | 226 | 227 | HPDF_INT32 228 | HPDF_Stream_Tell (HPDF_Stream stream); 229 | 230 | 231 | HPDF_STATUS 232 | HPDF_Stream_Seek (HPDF_Stream stream, 233 | HPDF_INT pos, 234 | HPDF_WhenceMode mode); 235 | 236 | 237 | HPDF_BOOL 238 | HPDF_Stream_EOF (HPDF_Stream stream); 239 | 240 | 241 | HPDF_UINT32 242 | HPDF_Stream_Size (HPDF_Stream stream); 243 | 244 | HPDF_STATUS 245 | HPDF_Stream_Flush (HPDF_Stream stream); 246 | 247 | 248 | HPDF_STATUS 249 | HPDF_Stream_WriteEscapeName (HPDF_Stream stream, 250 | const char *value); 251 | 252 | 253 | HPDF_STATUS 254 | HPDF_Stream_WriteEscapeText2 (HPDF_Stream stream, 255 | const char *text, 256 | HPDF_UINT len); 257 | 258 | 259 | HPDF_STATUS 260 | HPDF_Stream_WriteEscapeText (HPDF_Stream stream, 261 | const char *text); 262 | 263 | 264 | HPDF_STATUS 265 | HPDF_Stream_WriteBinary (HPDF_Stream stream, 266 | const HPDF_BYTE *data, 267 | HPDF_UINT len, 268 | HPDF_Encrypt e); 269 | 270 | 271 | HPDF_STATUS 272 | HPDF_Stream_Validate (HPDF_Stream stream); 273 | 274 | 275 | #ifdef __cplusplus 276 | } 277 | #endif /* __cplusplus */ 278 | 279 | #endif /* _HPDF_STREAMS_H */ 280 | -------------------------------------------------------------------------------- /C/hpdf_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * << Haru Free PDF Library >> -- fpdf_utils.h 3 | * 4 | * URL: http://libharu.org 5 | * 6 | * Copyright (c) 1999-2006 Takeshi Kanno 7 | * Copyright (c) 2007-2009 Antony Dovgal 8 | * 9 | * Permission to use, copy, modify, distribute and sell this software 10 | * and its documentation for any purpose is hereby granted without fee, 11 | * provided that the above copyright notice appear in all copies and 12 | * that both that copyright notice and this permission notice appear 13 | * in supporting documentation. 14 | * It is provided "as is" without express or implied warranty. 15 | * 16 | */ 17 | 18 | #ifndef _HPDF_UTILS_H 19 | #define _HPDF_UTILS_H 20 | 21 | #include "hpdf_config.h" 22 | #include "hpdf_types.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /* __cplusplus */ 27 | 28 | HPDF_INT 29 | HPDF_AToI (const char* s); 30 | 31 | 32 | HPDF_DOUBLE 33 | HPDF_AToF (const char* s); 34 | 35 | 36 | char* 37 | HPDF_IToA (char* s, 38 | HPDF_INT32 val, 39 | char* eptr); 40 | 41 | 42 | char* 43 | HPDF_IToA2 (char *s, 44 | HPDF_UINT32 val, 45 | HPDF_UINT len); 46 | 47 | 48 | char* 49 | HPDF_FToA (char *s, 50 | HPDF_REAL val, 51 | char *eptr); 52 | 53 | 54 | HPDF_BYTE* 55 | HPDF_MemCpy (HPDF_BYTE* out, 56 | const HPDF_BYTE* in, 57 | HPDF_UINT n); 58 | 59 | 60 | HPDF_BYTE* 61 | HPDF_StrCpy (char* out, 62 | const char* in, 63 | char* eptr); 64 | 65 | 66 | HPDF_INT 67 | HPDF_MemCmp (const HPDF_BYTE* s1, 68 | const HPDF_BYTE* s2, 69 | HPDF_UINT n); 70 | 71 | 72 | HPDF_INT 73 | HPDF_StrCmp (const char* s1, 74 | const char* s2); 75 | 76 | 77 | const char* 78 | HPDF_StrStr (const char *s1, 79 | const char *s2, 80 | HPDF_UINT maxlen); 81 | 82 | 83 | void* 84 | HPDF_MemSet (void* s, 85 | HPDF_BYTE c, 86 | HPDF_UINT n); 87 | 88 | 89 | HPDF_UINT 90 | HPDF_StrLen (const char* s, 91 | HPDF_INT maxlen); 92 | 93 | 94 | HPDF_Box 95 | HPDF_ToBox (HPDF_INT16 left, 96 | HPDF_INT16 bottom, 97 | HPDF_INT16 right, 98 | HPDF_INT16 top); 99 | 100 | 101 | HPDF_Point 102 | HPDF_ToPoint (HPDF_INT16 x, 103 | HPDF_INT16 y); 104 | 105 | 106 | HPDF_Rect 107 | HPDF_ToRect (HPDF_REAL left, 108 | HPDF_REAL bottom, 109 | HPDF_REAL right, 110 | HPDF_REAL top); 111 | 112 | 113 | void 114 | HPDF_UInt16Swap (HPDF_UINT16 *value); 115 | 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif /* __cplusplus */ 120 | 121 | #define HPDF_NEEDS_ESCAPE(c) (c < 0x20 || \ 122 | c > 0x7e || \ 123 | c == '\\' || \ 124 | c == '%' || \ 125 | c == '#' || \ 126 | c == '/' || \ 127 | c == '(' || \ 128 | c == ')' || \ 129 | c == '<' || \ 130 | c == '>' || \ 131 | c == '[' || \ 132 | c == ']' || \ 133 | c == '{' || \ 134 | c == '}' ) \ 135 | 136 | #define HPDF_IS_WHITE_SPACE(c) (c == 0x00 || \ 137 | c == 0x09 || \ 138 | c == 0x0A || \ 139 | c == 0x0C || \ 140 | c == 0x0D || \ 141 | c == 0x20 ) \ 142 | 143 | /*----------------------------------------------------------------------------*/ 144 | /*----- macros for debug -----------------------------------------------------*/ 145 | 146 | #ifdef LIBHPDF_DEBUG_TRACE 147 | #ifndef HPDF_PTRACE_ON 148 | #define HPDF_PTRACE_ON 149 | #endif /* HPDF_PTRACE_ON */ 150 | #endif /* LIBHPDF_DEBUG_TRACE */ 151 | 152 | #ifdef HPDF_PTRACE_ON 153 | #define HPDF_PTRACE(ARGS) HPDF_PRINTF ARGS 154 | #else 155 | #define HPDF_PTRACE(ARGS) /* do nothing */ 156 | #endif /* HPDF_PTRACE */ 157 | 158 | #ifdef LIBHPDF_DEBUG 159 | #define HPDF_PRINT_BINARY(BUF, LEN, CAPTION) HPDF_PrintBinary(BUF, LEN, CAPTION) 160 | #else 161 | #define HPDF_PRINT_BINARY(BUF, LEN, CAPTION) /* do nothing */ 162 | #endif 163 | 164 | #endif /* _HPDF_UTILS_H */ 165 | 166 | -------------------------------------------------------------------------------- /C/hpdf_version.h: -------------------------------------------------------------------------------- 1 | /* automatically generated by configure */ 2 | /* edit configure.in to change version number */ 3 | #define HPDF_MAJOR_VERSION 2 4 | #define HPDF_MINOR_VERSION 2 5 | #define HPDF_BUGFIX_VERSION 1 6 | #define HPDF_EXTRA_VERSION "" 7 | #define HPDF_VERSION_TEXT "2.2.1" 8 | #define HPDF_VERSION_ID 20201 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 o3o 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # harud 2 | 3 | A D binding to [libharu](http://libharu.org/) (library for generating PDF files) 4 | 5 | The project is a reactivation of the dharu project on [dsource repository](http://dsource.org/projects/aki/). 6 | 7 | ## Use 8 | See directory `examples/` and [wiki](https://github.com/o3o/harud/wiki). 9 | 10 | ## References 11 | * [dsource original project](http://www.dsource.org/projects/aki/) 12 | * [Dub package](http://code.dlang.org/packages/harud) 13 | * [libharu](http://libharu.org/) 14 | 15 | ## Resources 16 | * [How does the Import Library work?](http://stackoverflow.com/questions/3573475/how-does-the-import-library-work-details#3573527) 17 | * [Basic Utilities Package](http://ftp.digitalmars.com/bup.zip) 18 | * [implib man page](http://www.digitalmars.com/ctg/implib.html) 19 | * [Windows OMF and more resources](https://github.com/AndrejMitrovic/linker_resources) 20 | 21 | ## Related Projects 22 | * [fpdf: Minimalist class for generating PDF documents](https://github.com/jaypha/fpdf) 23 | -------------------------------------------------------------------------------- /bump-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh +v 2 | NEW_VER=$@ 3 | 4 | sed -i -r "s/VERSION\s*=\s*\"[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?\"/VERSION = \"${NEW_VER}\"/g" src/harud/semver.d 5 | git commit -a -m "Bumped version to ${NEW_VER}" 6 | -------------------------------------------------------------------------------- /doc/mm2dot.gnumeric: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/doc/mm2dot.gnumeric -------------------------------------------------------------------------------- /dub.sdl: -------------------------------------------------------------------------------- 1 | name "harud" 2 | description "D binding to libharu" 3 | authors "Orfeo Da Via'" 4 | copyright "Copyright © 2015, o3o" 5 | license "MIT License" 6 | targetType "library" 7 | targetPath "bin" 8 | libs "hpdf" 9 | -------------------------------------------------------------------------------- /dub.selections.json: -------------------------------------------------------------------------------- 1 | { 2 | "fileVersion": 1, 3 | "versions": { 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/dash/app.d: -------------------------------------------------------------------------------- 1 | import std.stdio; 2 | import std.conv; 3 | 4 | import harud; 5 | import harud.c; 6 | 7 | void main() { 8 | void errorCallback(uint error_number, uint detail_number) { 9 | writefln("err %x, %s, (num %x)" 10 | , error_number 11 | , getErrorDescription(error_number), 12 | detail_number); 13 | } 14 | 15 | 16 | try { 17 | Doc pdf = new Doc(&errorCallback); 18 | Font helvetica = pdf.getFont("Helvetica"); 19 | 20 | Page page = pdf.addPage(); 21 | page.rectangle(0, 0, 100, 100); 22 | page.rectangle(100, 100, 100, 100); 23 | page.stroke(); 24 | 25 | auto status = page.setFontAndSize(helvetica, 10); 26 | 27 | /* Line dash pattern */ 28 | testLineDashPattern(page); 29 | 30 | pdf.saveToFile("./dash.pdf"); 31 | } catch (Exception exc) { 32 | writeln(exc); 33 | } 34 | } 35 | 36 | private void testLineDashPattern(Page page) { 37 | /* Line dash pattern */ 38 | page.setLineWidth(1.0); 39 | 40 | enum ushort[] NN = [0, 0, 0, 0, 0, 0, 0, 0]; 41 | enum ushort[] DASH_MODE1 = [3]; 42 | enum ushort[] DASH_MODE2 = [3, 7]; 43 | enum ushort[] DASH_MODE3 = [8, 7, 2, 7]; 44 | enum ushort[] DOTTED = [2]; 45 | enum ushort[] DASH_DASH_DOT = [2,2,2,2,8,2]; 46 | enum ushort[] DASH_DOT = [2,2,8,2]; 47 | enum ushort[] DASHED = [4]; 48 | 49 | page.setDash(DASH_MODE1, 1); 50 | drawLine(page, 60, 680, "dash=[3], phase=1 -- 2 on, 3 off, 3 on..."); 51 | 52 | page.setDash(DASH_MODE2, 2); 53 | drawLine(page, 60, 650, "dash=[7, 3], phase=2 -- 5 on 3 off, 7 on,..."); 54 | 55 | page.setDash(DASH_MODE3, 0); 56 | drawLine(page, 60, 620, "dash=[8, 7, 2, 7], phase=0"); 57 | 58 | page.setDash(DOTTED, 0); 59 | drawLine(page, 60, 590, "dash=[2], phase=0"); 60 | 61 | page.setDash(DASH_DASH_DOT, 0); 62 | drawLine(page, 60, 560, "[2,2,2,2,8,2]"); 63 | 64 | page.setDash(DASH_DASH_DOT, 5); 65 | drawLine(page, 300, 560, "[2,2,2,2,8,2] fase=4"); 66 | 67 | page.setDash(DASH_DOT, 0); 68 | drawLine(page, 60, 530, "[2,2,8,2]"); 69 | 70 | page.setDash(DASHED, 0); 71 | drawLine(page, 60, 500, "[4]"); 72 | 73 | 74 | page.setDashDashDot(); 75 | drawLine(page, 60,470, "DASH_DASH_DOT"); 76 | 77 | page.setDashDot(); 78 | drawLine(page, 60, 440, "DASH_DOT"); 79 | 80 | page.setDashed(); 81 | drawLine(page, 60, 410, "DASHED"); 82 | page.setDotted(); 83 | drawLine(page, 60, 380, "DOTTED"); 84 | 85 | page.setSolid(); 86 | drawLine(page, 60, 350, "SOLID"); 87 | } 88 | 89 | void drawLine(Page page, float x, float y, string label) { 90 | page.beginText(); 91 | page.moveTextPos(x, y - 10); 92 | page.showText(label); 93 | page.endText(); 94 | 95 | page.moveTo(x, y - 15); 96 | page.lineTo(x + 220, y - 15); 97 | page.stroke(); 98 | } 99 | -------------------------------------------------------------------------------- /examples/dash/dub.sdl: -------------------------------------------------------------------------------- 1 | name "dash" 2 | targetType "executable" 3 | dependency "harud" path="../../" 4 | sourceFiles "app.d" 5 | -------------------------------------------------------------------------------- /examples/dash/makefile: -------------------------------------------------------------------------------- 1 | NAME = dash 2 | VERSION = 0.1.0 3 | #IS_LIB = true 4 | 5 | ROOT_SOURCE_DIR = . 6 | 7 | getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d") 8 | SRC = $(getSources) 9 | 10 | LIB += ../../bin/libharud.a 11 | 12 | INCLUDES += -I../../src 13 | 14 | DFLAGS += $(if $(IS_LIB), -lib, ) 15 | ## -debug compile in debug code 16 | DFLAGS += -debug 17 | ## -g add symbolic debug info 18 | #DFLAGS += -g 19 | 20 | ## -w warnings as errors (compilation will halt) 21 | DFLAGS += -w 22 | 23 | ##-wi warnings as messages (compilation will continue) 24 | #DFLAGS += -wi 25 | 26 | DFLAGS += -m64 27 | 28 | LDFLAGS = -L-lhpdf 29 | ## si usa make VERS=x 30 | VERSION_FLAG = $(if $(VERS), -version=$(VERS), ) 31 | 32 | ################# 33 | # TEST 34 | ################# 35 | 36 | SRC_TEST = $(SRC) 37 | #SRC_TEST = $(filter-out $(ROOT_SOURCE_DIR)/app.d, $(SRC)) 38 | #SRC_TEST += $(wildcard tests/*.d) 39 | 40 | ## oppure 41 | #SRC_TEST = $(wildcard $(ROOT_SOURCE_DIR)/$(NAME)/*.d) 42 | #SRC_TEST += $(wildcard tests/*.d) 43 | 44 | LIB_TEST += $(LIB) 45 | #LIB_TEST = $(D_DIR)/dunit/libdunit.a 46 | #LIB_TEST += $(D_DIR)/DMocks-revived/libdmocks-revived.a 47 | #LIB_TEST += $(D_DIR)/unit-threaded/libunit-threaded.a 48 | 49 | INCLUDES_TEST += $(INCLUDES) 50 | #INCLUDES_TEST += -I$(D_DIR)/dunit/source 51 | #INCLUDES_TEST += -I$(D_DIR)/DMocks-revived 52 | #INCLUDES_TEST += -I$(D_DIR)/unit-threaded/source 53 | 54 | DFLAGS_TEST += -unittest 55 | # DFLAGS_TEST += -main -quiet 56 | 57 | PKG = $(wildcard $(BIN)/$(NAME)) 58 | PKG_SRC = $(PKG) $(SRC) makefile 59 | 60 | DEFAULT: all 61 | 62 | ################# 63 | BIN = . 64 | DMD = dmd 65 | BASE_NAME = $(basename $(NAME)) 66 | TEST_NAME = $(BASE_NAME)-test 67 | DSCAN = ~/dscanner 68 | .PHONY: all clean clobber test run 69 | 70 | all: builddir $(BIN)/$(NAME) 71 | 72 | builddir: 73 | @mkdir -p $(BIN) 74 | 75 | $(BIN)/$(NAME): $(SRC) $(LIB)| builddir 76 | $(DMD) $^ $(DFLAGS) $(INCLUDES) $(LDFLAGS) $(VERSION_FLAG) -of$@ 77 | 78 | run: all 79 | $(BIN)/$(NAME) 80 | xpdf ./$(NAME).pdf 81 | 82 | ## se si usa unit_threaded 83 | ## make test T=nome_test 84 | test: $(BIN)/$(TEST_NAME) 85 | @$(BIN)/$(TEST_NAME) $(T) 86 | 87 | $(BIN)/$(TEST_NAME): $(SRC_TEST) $(LIB_TEST)| builddir 88 | $(DMD) $^ $(DFLAGS_TEST) $(INCLUDES_TEST) $(LDFLAGS) $(VERSION_FLAG) -of$@ 89 | 90 | pkgdir: 91 | @mkdir -p pkg 92 | 93 | pkg: $(PKG) | pkgdir 94 | tar -jcf pkg/$(BASE_NAME)-$(VERSION).tar.bz2 $^ 95 | zip pkg/$(BASE_NAME)-$(VERSION).zip $^ 96 | 97 | pkgsrc: $(PKG_SRC) | pkgdir 98 | tar -jcf pkg/$(BASE_NAME)-$(VERSION)-src.tar.bz2 $^ 99 | 100 | tags: $(SRC) 101 | $(DSCAN) --ctags -R src > tags 102 | 103 | style: 104 | $(DSCAN) --styleCheck -R src/ 105 | 106 | clean: 107 | -rm -f $(BIN)/*.o 108 | -rm -f $(BIN)/__* 109 | 110 | clobber: 111 | -rm -f $(BIN)/* 112 | 113 | var: 114 | @echo SRC:$(SRC) 115 | @echo INCLUDES: $(INCLUDES) 116 | @echo DFLAGS: $(DFLAGS) 117 | @echo LDFLAGS: $(LDFLAGS) 118 | @echo VERSION: $(VERSION_FLAG) 119 | @echo 120 | @echo SRC_TEST: $(SRC_TEST) 121 | @echo INCLUDES_TEST: $(INCLUDES_TEST) 122 | -------------------------------------------------------------------------------- /examples/encoding_list/app.d: -------------------------------------------------------------------------------- 1 | import harud.c; 2 | import harud; 3 | import std.conv; 4 | import std.stdio; 5 | import std.string; 6 | 7 | enum int PAGE_WIDTH = 420; 8 | enum int PAGE_HEIGHT = 400; 9 | enum int CELL_WIDTH = 20; 10 | enum int CELL_HEIGHT = 20; 11 | enum int CELL_HEADER = 10; 12 | 13 | void main() { 14 | Doc pdf = new Doc(); 15 | pdf.setCompressionMode(CompressionMode.all); 16 | pdf.setPageMode(PageMode.useOutline); 17 | 18 | Font helvetica = pdf.getFont("Helvetica"); 19 | string font_name 20 | = pdf.loadType1FontFromFile("type1/a010013l.afm", "type1/a010013l.pfb"); 21 | 22 | Outline root = pdf.createOutline("Encoding list"); 23 | root.setOpened(true); 24 | 25 | string[] encodings = [ 26 | "StandardEncoding", 27 | "MacRomanEncoding", 28 | "WinAnsiEncoding", 29 | "ISO8859-2", 30 | "ISO8859-3", 31 | "ISO8859-4", 32 | "ISO8859-5", 33 | "ISO8859-9", 34 | "ISO8859-10", 35 | "ISO8859-13", 36 | "ISO8859-14", 37 | "ISO8859-15", 38 | "ISO8859-16", 39 | "CP1250", 40 | "CP1251", 41 | "CP1252", 42 | "CP1254", 43 | "CP1257", 44 | "KOI8-R", 45 | "Symbol-Set", 46 | "ZapfDingbats-Set", 47 | ]; 48 | 49 | 50 | foreach (enc; encodings) { 51 | Page page = pdf.addPage(); /// Add a new page to the document 52 | page.setWidth(PAGE_WIDTH); 53 | page.setHeight(PAGE_HEIGHT); 54 | 55 | Outline outline = pdf.createOutline(enc, root); 56 | 57 | Destination dest = page.createDestination(); 58 | dest.setXYZ(0, page.getHeight, 1); 59 | outline.setDestination(dest); 60 | page.setFontAndSize(helvetica, 15); 61 | drawGraph(page); 62 | 63 | page.beginText(); 64 | page.setFontAndSize(helvetica, 20); 65 | page.moveTextPos (40, PAGE_HEIGHT - 50); 66 | page.showText(enc); 67 | page.showText(" Encoding"); 68 | page.endText(); 69 | 70 | Font font2; 71 | if (enc == "Symbol-Set") { 72 | font2 = pdf.getFont("Symbol"); 73 | } else if (enc == "ZapfDingbats-Set") { 74 | font2 = pdf.getFont("ZapfDingbats"); 75 | } else { 76 | font2 = pdf.getFont(font_name, enc); 77 | } 78 | page.setFontAndSize(font2, 14); 79 | drawFonts(page); 80 | } 81 | pdf.saveToFile("./encoding_list.pdf"); 82 | } 83 | 84 | void drawGraph(Page page) { 85 | string buf; 86 | int i; 87 | 88 | /* Draw 16 X 15 cells */ 89 | 90 | /* Draw vertical lines. */ 91 | page.setLineWidth(0.5f); 92 | 93 | for (i = 0; i <= 17; i++) { 94 | int x = i * CELL_WIDTH + 40; 95 | 96 | page.moveTo(x, PAGE_HEIGHT - 60); 97 | page.lineTo(x, 40); 98 | page.stroke(); 99 | 100 | if (i > 0 && i <= 16) { 101 | page.beginText(); 102 | page.moveTextPos(x + 5, PAGE_HEIGHT - 75); 103 | buf = format("%X", i - 1); 104 | 105 | page.showText(buf); 106 | page.endText(); 107 | } 108 | } 109 | 110 | /* Draw horizontal lines. */ 111 | for (i = 0; i <= 15; i++) { 112 | int y = i * CELL_HEIGHT + 40; 113 | 114 | page.moveTo(40, y); 115 | page.lineTo(PAGE_WIDTH - 40, y); 116 | page.stroke(); 117 | 118 | if (i < 14) { 119 | page.beginText(); 120 | page.moveTextPos(45, y + 5); 121 | buf = format("%X", 15 - i); 122 | page.showText(buf); 123 | page.endText(); 124 | } 125 | } 126 | } 127 | 128 | void drawFonts(Page page) { 129 | int i; 130 | int j; 131 | 132 | page.beginText(); 133 | 134 | /* Draw all character from 0x20 to 0xFF to the canvas. */ 135 | for (i = 1; i < 17; i++) { 136 | for (j = 1; j < 17; j++) { 137 | int y = PAGE_HEIGHT - 55 - ((i - 1) * CELL_HEIGHT); 138 | int x = j * CELL_WIDTH + 50; 139 | 140 | char[2] buf; 141 | buf[1] = 0x00; 142 | buf[0] = to!(char)((i - 1) * 16 + (j - 1)); 143 | if (buf[0] >= 32) { 144 | double d; 145 | string s = to!string(buf); 146 | d = x - page.getTextWidth(s) / 2; 147 | page.textOut(d, y, s); 148 | } 149 | } 150 | } 151 | page.endText(); 152 | } 153 | -------------------------------------------------------------------------------- /examples/encoding_list/dub.sdl: -------------------------------------------------------------------------------- 1 | name "encoding_list" 2 | targetType "executable" 3 | dependency "harud" path="../../" 4 | sourceFiles "app.d" 5 | -------------------------------------------------------------------------------- /examples/encoding_list/makefile: -------------------------------------------------------------------------------- 1 | NAME = encoding_list 2 | VERSION = 0.1.0 3 | #IS_LIB = true 4 | 5 | ROOT_SOURCE_DIR = . 6 | 7 | getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d") 8 | SRC = $(getSources) 9 | 10 | LIB += ../../bin/libharud.a 11 | 12 | INCLUDES += -I../../src 13 | 14 | DFLAGS += $(if $(IS_LIB), -lib, ) 15 | ## -debug compile in debug code 16 | DFLAGS += -debug 17 | ## -g add symbolic debug info 18 | DFLAGS += -g 19 | 20 | ## -w warnings as errors (compilation will halt) 21 | DFLAGS += -w 22 | 23 | ##-wi warnings as messages (compilation will continue) 24 | #DFLAGS += -wi 25 | 26 | DFLAGS += -m64 27 | 28 | LDFLAGS = -L-lhpdf 29 | ## si usa make VERS=x 30 | VERSION_FLAG = $(if $(VERS), -version=$(VERS), ) 31 | 32 | ################# 33 | # TEST 34 | ################# 35 | 36 | SRC_TEST = $(SRC) 37 | #SRC_TEST = $(filter-out $(ROOT_SOURCE_DIR)/app.d, $(SRC)) 38 | #SRC_TEST += $(wildcard tests/*.d) 39 | 40 | ## oppure 41 | #SRC_TEST = $(wildcard $(ROOT_SOURCE_DIR)/$(NAME)/*.d) 42 | #SRC_TEST += $(wildcard tests/*.d) 43 | 44 | LIB_TEST += $(LIB) 45 | #LIB_TEST = $(D_DIR)/dunit/libdunit.a 46 | #LIB_TEST += $(D_DIR)/DMocks-revived/libdmocks-revived.a 47 | #LIB_TEST += $(D_DIR)/unit-threaded/libunit-threaded.a 48 | 49 | INCLUDES_TEST += $(INCLUDES) 50 | #INCLUDES_TEST += -I$(D_DIR)/dunit/source 51 | #INCLUDES_TEST += -I$(D_DIR)/DMocks-revived 52 | #INCLUDES_TEST += -I$(D_DIR)/unit-threaded/source 53 | 54 | DFLAGS_TEST += -unittest 55 | # DFLAGS_TEST += -main -quiet 56 | 57 | PKG = $(wildcard $(BIN)/$(NAME)) 58 | PKG_SRC = $(PKG) $(SRC) makefile 59 | 60 | DEFAULT: all 61 | 62 | ################# 63 | BIN = . 64 | DMD = dmd 65 | BASE_NAME = $(basename $(NAME)) 66 | TEST_NAME = $(BASE_NAME)-test 67 | DSCAN = ~/dscanner 68 | .PHONY: all clean clobber test run 69 | 70 | all: builddir $(BIN)/$(NAME) 71 | 72 | builddir: 73 | @mkdir -p $(BIN) 74 | 75 | $(BIN)/$(NAME): $(SRC) $(LIB)| builddir 76 | $(DMD) $^ $(DFLAGS) $(INCLUDES) $(LDFLAGS) $(VERSION_FLAG) -of$@ 77 | 78 | run: all 79 | $(BIN)/$(NAME) 80 | xpdf ./$(NAME).pdf 81 | 82 | ## se si usa unit_threaded 83 | ## make test T=nome_test 84 | test: $(BIN)/$(TEST_NAME) 85 | @$(BIN)/$(TEST_NAME) $(T) 86 | 87 | $(BIN)/$(TEST_NAME): $(SRC_TEST) $(LIB_TEST)| builddir 88 | $(DMD) $^ $(DFLAGS_TEST) $(INCLUDES_TEST) $(LDFLAGS) $(VERSION_FLAG) -of$@ 89 | 90 | pkgdir: 91 | @mkdir -p pkg 92 | 93 | pkg: $(PKG) | pkgdir 94 | tar -jcf pkg/$(BASE_NAME)-$(VERSION).tar.bz2 $^ 95 | zip pkg/$(BASE_NAME)-$(VERSION).zip $^ 96 | 97 | pkgsrc: $(PKG_SRC) | pkgdir 98 | tar -jcf pkg/$(BASE_NAME)-$(VERSION)-src.tar.bz2 $^ 99 | 100 | tags: $(SRC) 101 | $(DSCAN) --ctags -R src > tags 102 | 103 | style: 104 | $(DSCAN) --styleCheck -R src/ 105 | 106 | clean: 107 | -rm -f $(BIN)/*.o 108 | -rm -f $(BIN)/__* 109 | 110 | clobber: 111 | -rm -f $(BIN)/* 112 | 113 | var: 114 | @echo SRC:$(SRC) 115 | @echo INCLUDES: $(INCLUDES) 116 | @echo DFLAGS: $(DFLAGS) 117 | @echo LDFLAGS: $(LDFLAGS) 118 | @echo VERSION: $(VERSION_FLAG) 119 | @echo 120 | @echo SRC_TEST: $(SRC_TEST) 121 | @echo INCLUDES_TEST: $(INCLUDES_TEST) 122 | -------------------------------------------------------------------------------- /examples/encoding_list/type1/README: -------------------------------------------------------------------------------- 1 | This is release 1.0.7pre22 of Valek Filippov's improved versions of the URW 2 | type 1 font collection, repackaged for distribution with Ghostscript. 3 | 4 | Cyrillized free URW fonts. 5 | 6 | These fonts were made from the free URW fonts distributed with ghostcript. 7 | There are NO changes in the latin part of them (I hope). 8 | Cyrillic glyphs were added by copying suitable latin ones 9 | and painting oulines of unique cyrillic glyphs in same style as the others. 10 | For all modification pfaedit was used. 11 | The license for result is (of course) same as for original fonts, 12 | i.e. GPL with an exception that you can put these fonts in your own non-GPLed 13 | documents. (Looks like LGPL from my point of view =). 14 | 15 | The "sources" of these fonts in the native pfaedit format are available 16 | at ftp://ftp.gnome.ru/fonts/sources 17 | 18 | The great font editor pfaedit is available at http://pfaedit.sf.net. 19 | That page also includes some links to fonts created by 20 | George Williams -- the author of pfaedit. 21 | 22 | Acknowledgements: 23 | I would like to thank George Williams, the pfaedit's author and developer. 24 | He is the most bug-reporter/feature-requester friendly developer 25 | I ever saw in my not so short life. At some moment in the future 26 | I must write a book about him: "George Williams and my best experience 27 | in bug-reporting." George also greatly helped me bug-hunting these fonts, 28 | explained to me some very important things about fonts and font design, 29 | quickly adopted pfaedit to my needs (or pointed me to The Right Place in 30 | documentation where I found better way of doing things). 31 | 32 | I would like to thank Alexey Novodvorsky (aka AEN), who 33 | pointed me to pfaedit and George Williams' fonts, explained 34 | The Task to me. He is also one of the main participators in the 35 | development of Sysiphus -- free repository of free software. 36 | I didn't loose my time for compiling/installing and supporting 37 | my linux box coz I used the result of Sysiphus developers' works. 38 | 39 | I would like to thank Sergey Vlasov, who tested these fonts and reported 40 | about bugs. Also he help me to make some bug-reports to George about 41 | pfaedit bugs. 42 | 43 | I would like Dmitry 40in, who did big QA for some font outlines, drawn some glyphs, 44 | and explain some The Truths for me. 45 | 46 | I would like to thank Vlad Harchev (aka hvv), who 47 | proofread this text for me. 48 | 49 | Also I have to thank RMS for GPL and URW for releasing the fonts 50 | under it. 51 | 52 | Thank you very much! 53 | Valek Filippov frob@df.ru 54 | (C)opyLeft 2001 55 | -------------------------------------------------------------------------------- /examples/encoding_list/type1/a010013l.pfb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/encoding_list/type1/a010013l.pfb -------------------------------------------------------------------------------- /examples/error_handling/app.d: -------------------------------------------------------------------------------- 1 | import harud.c; 2 | import harud; 3 | import std.stdio; 4 | 5 | void main() { 6 | void errorCallback(uint error_number, uint detail_number) { 7 | writefln("err from callback %x, %s, (num %x)" 8 | , error_number 9 | , getErrorDescription(error_number), 10 | detail_number); 11 | } 12 | 13 | writeln("+++with try+++"); 14 | 15 | Doc pdf0 = new Doc(); 16 | Page page0 = pdf0.addPage(); 17 | try { 18 | page0.setWidth(1); 19 | } catch(HarudException e) { 20 | writeln("exp:", e.msg, " num:", e.errCode); 21 | } 22 | writeln(); 23 | 24 | writeln("+++with callback+++"); 25 | 26 | Doc pdf1 = new Doc(&errorCallback); 27 | Page page1 = pdf1.addPage(); 28 | page1.setWidth(1); 29 | writeln(); 30 | 31 | writeln("+++without try+++"); 32 | Doc pdf2 = new Doc(); 33 | Page page2 = pdf2.addPage(); 34 | page2.setWidth(1); 35 | } 36 | -------------------------------------------------------------------------------- /examples/error_handling/dub.sdl: -------------------------------------------------------------------------------- 1 | name "err" 2 | targetType "executable" 3 | dependency "harud" path="../../" 4 | sourceFiles "app.d" 5 | -------------------------------------------------------------------------------- /examples/error_handling/makefile: -------------------------------------------------------------------------------- 1 | NAME = err 2 | VERSION = 0.1.0 3 | #IS_LIB = true 4 | 5 | ROOT_SOURCE_DIR = . 6 | 7 | getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d") 8 | SRC = $(getSources) 9 | 10 | LIB += ../../bin/libharud.a 11 | 12 | 13 | INCLUDES += -I../../src 14 | 15 | DFLAGS += $(if $(IS_LIB), -lib, ) 16 | ## -debug compile in debug code 17 | DFLAGS += -debug 18 | ## -g add symbolic debug info 19 | #DFLAGS += -g 20 | 21 | ## -w warnings as errors (compilation will halt) 22 | DFLAGS += -w 23 | 24 | ##-wi warnings as messages (compilation will continue) 25 | #DFLAGS += -wi 26 | 27 | DFLAGS += -m64 28 | 29 | LDFLAGS = -L-lhpdf 30 | ## si usa make VERS=x 31 | VERSION_FLAG = $(if $(VERS), -version=$(VERS), ) 32 | 33 | ################# 34 | # TEST 35 | ################# 36 | 37 | SRC_TEST = $(SRC) 38 | #SRC_TEST = $(filter-out $(ROOT_SOURCE_DIR)/app.d, $(SRC)) 39 | #SRC_TEST += $(wildcard tests/*.d) 40 | 41 | ## oppure 42 | #SRC_TEST = $(wildcard $(ROOT_SOURCE_DIR)/$(NAME)/*.d) 43 | #SRC_TEST += $(wildcard tests/*.d) 44 | 45 | LIB_TEST += $(LIB) 46 | #LIB_TEST = $(D_DIR)/dunit/libdunit.a 47 | #LIB_TEST += $(D_DIR)/DMocks-revived/libdmocks-revived.a 48 | #LIB_TEST += $(D_DIR)/unit-threaded/libunit-threaded.a 49 | 50 | INCLUDES_TEST += $(INCLUDES) 51 | #INCLUDES_TEST += -I$(D_DIR)/dunit/source 52 | #INCLUDES_TEST += -I$(D_DIR)/DMocks-revived 53 | #INCLUDES_TEST += -I$(D_DIR)/unit-threaded/source 54 | 55 | DFLAGS_TEST += -unittest 56 | # DFLAGS_TEST += -main -quiet 57 | 58 | PKG = $(wildcard $(BIN)/$(NAME)) 59 | PKG_SRC = $(PKG) $(SRC) makefile 60 | 61 | DEFAULT: all 62 | 63 | ################# 64 | BIN = . 65 | DMD = dmd 66 | BASE_NAME = $(basename $(NAME)) 67 | TEST_NAME = $(BASE_NAME)-test 68 | DSCAN = ~/dscanner 69 | .PHONY: all clean clobber test run 70 | 71 | all: builddir $(BIN)/$(NAME) 72 | 73 | builddir: 74 | @mkdir -p $(BIN) 75 | 76 | $(BIN)/$(NAME): $(SRC) $(LIB)| builddir 77 | $(DMD) $^ $(DFLAGS) $(INCLUDES) $(LDFLAGS) $(VERSION_FLAG) -of$@ 78 | 79 | run: all 80 | $(BIN)/$(NAME) 81 | 82 | ## se si usa unit_threaded 83 | ## make test T=nome_test 84 | test: $(BIN)/$(TEST_NAME) 85 | @$(BIN)/$(TEST_NAME) $(T) 86 | 87 | $(BIN)/$(TEST_NAME): $(SRC_TEST) $(LIB_TEST)| builddir 88 | $(DMD) $^ $(DFLAGS_TEST) $(INCLUDES_TEST) $(LDFLAGS) $(VERSION_FLAG) -of$@ 89 | 90 | pkgdir: 91 | @mkdir -p pkg 92 | 93 | pkg: $(PKG) | pkgdir 94 | tar -jcf pkg/$(BASE_NAME)-$(VERSION).tar.bz2 $^ 95 | zip pkg/$(BASE_NAME)-$(VERSION).zip $^ 96 | 97 | pkgsrc: $(PKG_SRC) | pkgdir 98 | tar -jcf pkg/$(BASE_NAME)-$(VERSION)-src.tar.bz2 $^ 99 | 100 | tags: $(SRC) 101 | $(DSCAN) --ctags -R src > tags 102 | 103 | style: 104 | $(DSCAN) --styleCheck -R src/ 105 | 106 | clean: 107 | -rm -f $(BIN)/*.o 108 | -rm -f $(BIN)/__* 109 | 110 | clobber: 111 | -rm -f $(BIN)/* 112 | 113 | var: 114 | @echo SRC:$(SRC) 115 | @echo INCLUDES: $(INCLUDES) 116 | @echo DFLAGS: $(DFLAGS) 117 | @echo LDFLAGS: $(LDFLAGS) 118 | @echo VERSION: $(VERSION_FLAG) 119 | @echo 120 | @echo SRC_TEST: $(SRC_TEST) 121 | @echo INCLUDES_TEST: $(INCLUDES_TEST) 122 | -------------------------------------------------------------------------------- /examples/font/app.d: -------------------------------------------------------------------------------- 1 | import harud.c; 2 | import harud; 3 | import std.stdio; 4 | 5 | void main() { 6 | void errorCallback(uint error_number, uint detail_number) { 7 | writefln("err %x, %s, (num %x)" 8 | , error_number 9 | , getErrorDescription(error_number), 10 | detail_number); 11 | } 12 | 13 | string[] fontList = [ 14 | "Courier", 15 | "Courier-Bold", 16 | "Courier-Oblique", 17 | "Courier-BoldOblique", 18 | "Helvetica", 19 | "Helvetica-Bold", 20 | "Helvetica-Oblique", 21 | "Helvetica-BoldOblique", 22 | "Times-Roman", 23 | "Times-Bold", 24 | "Times-Italic", 25 | "Times-BoldItalic", 26 | "Symbol", 27 | "ZapfDingbats" 28 | ]; 29 | writeln("libhpdf-", getVersion()); 30 | 31 | try { 32 | enum string TITLE = "FontDemo"; 33 | 34 | Doc pdf = new Doc(&errorCallback); 35 | Page page = pdf.addPage(); 36 | 37 | float height = page.getHeight; 38 | float width = page.getWidth; 39 | /* Print the lines of the page. */ 40 | page.setLineWidth(1); 41 | page.rectangle(50, 50, width - 100, height - 110); 42 | page.stroke(); 43 | 44 | /* Print the title of the page (with positioning center). */ 45 | Font helvetica = pdf.getFont("Helvetica"); 46 | page.setFontAndSize(helvetica, 24); 47 | 48 | float tw = page.getTextWidth(TITLE); 49 | page.beginText(); 50 | page.textOut((width - tw) / 2, height - 50, TITLE); 51 | page.endText(); 52 | 53 | /* output subtitle. */ 54 | page.beginText(); 55 | page.setFontAndSize(helvetica, 16); 56 | page.textOut(60, height - 80, ""); 57 | page.endText(); 58 | 59 | page.beginText(); 60 | page.moveTextPos(60, height - 105); 61 | 62 | for (int i = 0; i < fontList.length -1 ; i++) { 63 | enum string SAMPLE_TEXT = "abcdefghijklmnopqrstxyuwvz"; 64 | //enum string SAMPLE_TEXT = "abcdefgABCDEFGO12345!#$%&+-@?°C"; 65 | Font font = pdf.getFont(fontList[i]); 66 | 67 | /* print a label of text */ 68 | page.setFontAndSize(helvetica, 9); 69 | page.showText(fontList[i]); 70 | page.moveTextPos(0, -18); 71 | 72 | /* print a sample text. */ 73 | page.setFontAndSize(font, 20); 74 | page.showText(SAMPLE_TEXT); 75 | page.moveTextPos(0, -20); 76 | } 77 | pdf.useCNSFonts(); 78 | pdf.useCNSEncodings(); 79 | page.setFontAndSize(helvetica, 9); 80 | page.showText("simsun"); 81 | page.moveTextPos(0, -18); 82 | 83 | Font cfont = pdf.getFont("SimSun", "GB-EUC-H"); 84 | page.setFontAndSize(cfont, 20); 85 | page.showText("奥菲欧"); 86 | 87 | page.endText(); 88 | 89 | pdf.saveToFile("./font.pdf"); 90 | } catch (Exception exc) { 91 | writeln(exc); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /examples/font/dub.sdl: -------------------------------------------------------------------------------- 1 | name "font" 2 | targetType "executable" 3 | dependency "harud" path="../../" 4 | sourceFiles "app.d" 5 | -------------------------------------------------------------------------------- /examples/font/makefile: -------------------------------------------------------------------------------- 1 | NAME = font 2 | VERSION = 0.1.0 3 | 4 | ROOT_SOURCE_DIR = . 5 | 6 | getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d") 7 | SRC = $(getSources) 8 | 9 | LIB += ../../bin/libharud.a 10 | INCLUDES += -I../../src 11 | 12 | DFLAGS += $(if $(IS_LIB), -lib, ) 13 | ## -debug compile in debug code 14 | DFLAGS += -debug 15 | ## -g add symbolic debug info 16 | #DFLAGS += -g 17 | ## -w warnings as errors (compilation will halt) 18 | DFLAGS += -w 19 | DFLAGS += -m64 20 | LDFLAGS = -L-lhpdf 21 | 22 | VERSION_FLAG = $(if $(V), -version=$(V), ) 23 | 24 | DEFAULT: all 25 | 26 | ################# 27 | BIN = . 28 | DMD = dmd 29 | BASE_NAME = $(basename $(NAME)) 30 | PDF = evince 31 | .PHONY: all clean clobber run 32 | 33 | all: builddir $(BIN)/$(NAME) 34 | 35 | builddir: 36 | @mkdir -p $(BIN) 37 | 38 | $(BIN)/$(NAME): $(SRC) $(LIB)| builddir 39 | $(DMD) $^ $(DFLAGS) $(INCLUDES) $(LDFLAGS) $(VERSION_FLAG) -of$@ 40 | 41 | run: all 42 | $(BIN)/$(NAME) 43 | $(PDF) ./$(NAME).pdf 44 | 45 | ps: $(NAME).ps 46 | 47 | $(NAME).ps : $(NAME).pdf 48 | pdftops -paper A4 $^ 49 | 50 | $(NAME).pdf : all 51 | $(BIN)/$(NAME) 52 | 53 | tags: $(SRC) 54 | $(DSCAN) --ctags -R src > tags 55 | 56 | clean: 57 | -rm -f $(BIN)/*.o 58 | -rm -f $(BIN)/__* 59 | -rm -f $(BIN)/*.pdf 60 | 61 | clobber: 62 | -rm -f $(BIN)/$(NAME) 63 | 64 | 65 | var: 66 | @echo SRC:$(SRC) 67 | @echo INCLUDES: $(INCLUDES) 68 | @echo DFLAGS: $(DFLAGS) 69 | @echo LDFLAGS: $(LDFLAGS) 70 | @echo VERSION: $(VERSION_FLAG) 71 | -------------------------------------------------------------------------------- /examples/grid_sheet/app.d: -------------------------------------------------------------------------------- 1 | import std.stdio; 2 | import std.conv; 3 | 4 | import harud; 5 | import harud.c; 6 | 7 | void main() { 8 | void errorCallback(uint error_number, uint detail_number) { 9 | writefln("err %x, %s, (num %x)" 10 | , error_number 11 | , getErrorDescription(error_number), 12 | detail_number); 13 | } 14 | 15 | Doc pdf = new Doc(&errorCallback); 16 | Font helvetica = pdf.getFont("Helvetica"); 17 | 18 | Page page = pdf.addPage(); 19 | 20 | /// Set the current font and size for the page 21 | page.setFontAndSize(helvetica, 10); 22 | page.setSize(PageSizes.A4, PageDirection.portrait); 23 | writefln("page w: %s h: %s", page.getWidth, page.getHeight); 24 | 25 | printGrid(page); 26 | pdf.saveToFile("./grid_sheet.pdf"); /// Write to disk 27 | } 28 | 29 | void printGrid(Page page) { 30 | float height = page.getHeight(); 31 | writeln("h:", height); 32 | float width = page.getWidth(); 33 | 34 | uint x, y; 35 | //page.setGrayFill(0.5); 36 | page.setGrayStroke(0.8); 37 | y = 0; 38 | writeln(page.getGMode); 39 | 40 | while (y < height) { 41 | page.setAltWidth(y); 42 | 43 | page.moveTo(0, y); 44 | page.lineTo(width, y); 45 | page.stroke(); 46 | 47 | if (y % 10 == 0 && y > 0) { 48 | page.setGrayStroke(0.5); 49 | 50 | page.moveTo(0, y); 51 | page.lineTo(25, y); 52 | page.stroke(); 53 | 54 | page.setGrayStroke(0.8); 55 | } 56 | y += 5; 57 | } 58 | 59 | /* Draw vertical lines */ 60 | x = 0; 61 | while (x < width) { 62 | page.setAltWidth(x); 63 | 64 | page.moveTo(x, 0); 65 | page.lineTo(x, height); 66 | page.stroke(); 67 | 68 | if (x % 50 == 0 && x > 0) { 69 | page.setGrayStroke(0.5); 70 | 71 | page.moveTo(x, 0); 72 | page.lineTo(x, 5); 73 | page.stroke(); 74 | 75 | page.moveTo(x, height); 76 | page.lineTo(x, height - 25); 77 | page.stroke(); 78 | 79 | page.setGrayStroke(0.8); 80 | } 81 | 82 | x += 5; 83 | } 84 | /* Draw horizontal text */ 85 | y = 0; 86 | while (y < height) { 87 | if (y % 10 == 0 && y > 0) { 88 | page.beginText(); 89 | page.moveTextPos(25, y - 2); 90 | 91 | page.showText(to!string(y)); 92 | page.endText; 93 | } 94 | 95 | y += 5; 96 | } 97 | 98 | 99 | /* Draw virtical text */ 100 | x = 0; 101 | while (x < width) { 102 | if (x % 50 == 0 && x > 0) { 103 | page.beginText(); 104 | page.moveTextPos(x, 5); 105 | page.showText(to!string(x)); 106 | page.endText; 107 | 108 | page.beginText; 109 | page.moveTextPos(x, height - 30); 110 | page.showText(to!string(x)); 111 | page.endText(); 112 | } 113 | x += 5; 114 | } 115 | page.setGrayFill(0); 116 | page.setGrayStroke(0); 117 | } 118 | 119 | private void setAltWidth(Page page, double y) { 120 | if (y % 10 == 0) { 121 | page.setLineWidth(0.5); 122 | } else { 123 | if (page.getLineWidth != 0.25) { 124 | page.setLineWidth(0.25); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /examples/grid_sheet/dub.sdl: -------------------------------------------------------------------------------- 1 | name "grid_sheet" 2 | targetType "executable" 3 | dependency "harud" path="../../" 4 | sourceFiles "app.d" 5 | -------------------------------------------------------------------------------- /examples/grid_sheet/makefile: -------------------------------------------------------------------------------- 1 | NAME = grid_sheet 2 | VERSION = 0.1.0 3 | 4 | ROOT_SOURCE_DIR = . 5 | 6 | getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d") 7 | SRC = $(getSources) 8 | 9 | LIB += ../../bin/libharud.a 10 | INCLUDES += -I../../src 11 | 12 | DFLAGS += $(if $(IS_LIB), -lib, ) 13 | ## -debug compile in debug code 14 | DFLAGS += -debug 15 | ## -g add symbolic debug info 16 | #DFLAGS += -g 17 | ## -w warnings as errors (compilation will halt) 18 | DFLAGS += -w 19 | DFLAGS += -m64 20 | LDFLAGS = -L-lhpdf 21 | 22 | VERSION_FLAG = $(if $(V), -version=$(V), ) 23 | 24 | DEFAULT: all 25 | 26 | ################# 27 | BIN = . 28 | DMD = dmd 29 | BASE_NAME = $(basename $(NAME)) 30 | PDF = evince 31 | .PHONY: all clean clobber run 32 | 33 | all: builddir $(BIN)/$(NAME) 34 | 35 | builddir: 36 | @mkdir -p $(BIN) 37 | 38 | $(BIN)/$(NAME): $(SRC) $(LIB)| builddir 39 | $(DMD) $^ $(DFLAGS) $(INCLUDES) $(LDFLAGS) $(VERSION_FLAG) -of$@ 40 | 41 | run: all 42 | $(BIN)/$(NAME) 43 | $(PDF) ./$(NAME).pdf 44 | 45 | ps: $(NAME).ps 46 | 47 | $(NAME).ps : $(NAME).pdf 48 | pdftops -paper A4 $^ 49 | 50 | $(NAME).pdf : all 51 | $(BIN)/$(NAME) 52 | 53 | tags: $(SRC) 54 | $(DSCAN) --ctags -R src > tags 55 | 56 | clean: 57 | -rm -f $(BIN)/*.o 58 | -rm -f $(BIN)/__* 59 | -rm -f $(BIN)/*.pdf 60 | 61 | clobber: 62 | -rm -f $(BIN)/$(NAME) 63 | 64 | var: 65 | @echo SRC:$(SRC) 66 | @echo INCLUDES: $(INCLUDES) 67 | @echo DFLAGS: $(DFLAGS) 68 | @echo LDFLAGS: $(LDFLAGS) 69 | @echo VERSION: $(VERSION_FLAG) 70 | -------------------------------------------------------------------------------- /examples/hello/app.d: -------------------------------------------------------------------------------- 1 | import std.stdio: writeln; 2 | 3 | import harud; 4 | void main() { 5 | try { 6 | 7 | Doc pdf = new Doc(); /// New pdf document 8 | Font helvetica = pdf.getFont("Helvetica"); 9 | writeln("build font"); 10 | 11 | Page page = pdf.addPage(); /// Add a new page to the document 12 | 13 | writeln("page width:", page.getWidth); 14 | writeln("page height:", page.getHeight); 15 | 16 | auto status = page.setFontAndSize(helvetica, 60); /// Set the current font and size for the page 17 | writeln("set font width:", 60, " status", status); 18 | 19 | status = page.beginText(); /// Begin text mode 20 | writeln("begin ", status); 21 | 22 | status = page.showText("Hello World Ω"); /// Print text to the page 23 | writeln("show ", status); 24 | 25 | page.endText(); /// End text mode 26 | 27 | pdf.saveToFile("./hello.pdf"); /// Write to disk 28 | } catch(HarudException e) { 29 | writeln("exp:", e.msg, " num:", e.errCode); 30 | } catch (Exception e) { 31 | writeln("unknow error ", e.msg); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /examples/hello/dub.sdl: -------------------------------------------------------------------------------- 1 | name "hello" 2 | description "Simple example with harud" 3 | targetType "executable" 4 | authors "Orfeo Da Vià" 5 | copyright "Copyright © 2015, o3o" 6 | license "Boost License" 7 | 8 | dependency "harud" path="../../" 9 | libs "hpdf" platform="posix" 10 | sourceFiles "../../lib/libhpdf.lib" platform="windows" 11 | sourceFiles "app.d" 12 | sourcePaths "." 13 | sourcePaths "../../lib/" platform="windows" 14 | -------------------------------------------------------------------------------- /examples/hello/makefile: -------------------------------------------------------------------------------- 1 | NAME = hello 2 | VERSION = 0.1.0 3 | 4 | ROOT_SOURCE_DIR = . 5 | 6 | getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d") 7 | SRC = $(getSources) 8 | 9 | LIB += ../../bin/libharud.a 10 | INCLUDES += -I../../src 11 | 12 | DFLAGS += $(if $(IS_LIB), -lib, ) 13 | ## -debug compile in debug code 14 | DFLAGS += -debug 15 | ## -g add symbolic debug info 16 | #DFLAGS += -g 17 | ## -w warnings as errors (compilation will halt) 18 | DFLAGS += -w 19 | DFLAGS += -m64 20 | LDFLAGS = -L-lhpdf 21 | 22 | VERSION_FLAG = $(if $(V), -version=$(V), ) 23 | 24 | DEFAULT: all 25 | 26 | ################# 27 | BIN = . 28 | DMD = dmd 29 | BASE_NAME = $(basename $(NAME)) 30 | PDF = evince 31 | .PHONY: all clean clobber run 32 | 33 | all: builddir $(BIN)/$(NAME) 34 | 35 | builddir: 36 | @mkdir -p $(BIN) 37 | 38 | $(BIN)/$(NAME): $(SRC) $(LIB)| builddir 39 | $(DMD) $^ $(DFLAGS) $(INCLUDES) $(LDFLAGS) $(VERSION_FLAG) -of$@ 40 | 41 | run: all 42 | $(BIN)/$(NAME) 43 | $(PDF) ./$(NAME).pdf 44 | 45 | ps: $(NAME).ps 46 | 47 | $(NAME).ps : $(NAME).pdf 48 | pdftops -paper A4 $^ 49 | 50 | $(NAME).pdf : all 51 | $(BIN)/$(NAME) 52 | 53 | tags: $(SRC) 54 | $(DSCAN) --ctags -R src > tags 55 | 56 | clean: 57 | -rm -f $(BIN)/*.o 58 | -rm -f $(BIN)/__* 59 | -rm -f $(BIN)/*.pdf 60 | 61 | clobber: 62 | -rm -f $(BIN)/$(NAME) 63 | 64 | var: 65 | @echo SRC:$(SRC) 66 | @echo INCLUDES: $(INCLUDES) 67 | @echo DFLAGS: $(DFLAGS) 68 | @echo LDFLAGS: $(LDFLAGS) 69 | @echo VERSION: $(VERSION_FLAG) 70 | -------------------------------------------------------------------------------- /examples/image/app.d: -------------------------------------------------------------------------------- 1 | import harud; 2 | import std.conv; 3 | import std.math; 4 | import std.stdio; 5 | import std.string; 6 | 7 | void main() { 8 | void errorCallback(uint error_number, uint detail_number) { 9 | writefln("err %x, %s, (num %x)" 10 | , error_number 11 | , getErrorDescription(error_number), 12 | detail_number); 13 | } 14 | 15 | try { 16 | Doc pdf = new Doc(&errorCallback); 17 | pdf.setCompressionMode(CompressionMode.all); 18 | Font helvetica = pdf.getFont("Helvetica"); 19 | 20 | Page page = pdf.addPage(); 21 | page.setWidth(550); 22 | page.setHeight(500); 23 | Destination dst = page.createDestination(); 24 | writeln(hasDoc(pdf)); 25 | 26 | pdf.setOpenAction(dst.destinationHandle()); 27 | 28 | page.beginText(); 29 | page.setFontAndSize(helvetica, 20); 30 | page.moveTextPos(220, page.getHeight - 70); 31 | page.showText("ImageDemo"); 32 | page.endText(); 33 | 34 | Image image = pdf.getPngImage("basn3p02.png"); 35 | Image image1 = pdf.getPngImage("basn3p02.png"); 36 | Image image2 = pdf.getPngImage("basn0g01.png"); 37 | Image image3 = pdf.getPngImage("maskimage.png"); 38 | 39 | double iw = image.getWidth; 40 | double ih = image.getHeight; 41 | page.setLineWidth(0.5); 42 | 43 | double x = 100; 44 | double y = page.getHeight - 150; 45 | 46 | page.drawImage(image, x, y, iw, ih); 47 | showDescription(page, x, y, "Actual Size"); 48 | 49 | x += 150; 50 | 51 | /* Scalling image (X direction) */ 52 | page.drawImage(image, x, y, iw * 1.5, ih); 53 | showDescription(page, x, y, "Scalling image (X direction)"); 54 | 55 | x += 150; 56 | /* Scalling image (Y direction). */ 57 | page.drawImage(image, x, y, iw, ih * 1.5); 58 | showDescription(page, x, y, "Scalling image (Y direction)"); 59 | 60 | x = 100; 61 | y -= 120; 62 | 63 | /* Skewing image. */ 64 | double angle1 = 10; 65 | double angle2 = 20; 66 | double rad1 = angle1 / 180 * 3.141592; 67 | double rad2 = angle2 / 180 * 3.141592; 68 | 69 | page.graphicSave(); 70 | page.concat(iw, tan(rad1) * iw, tan(rad2) * ih, ih, x, y); 71 | 72 | page.executeXObject(image); 73 | page.graphicRestore(); 74 | showDescription(page, x, y, "Skewing image"); 75 | 76 | x += 150; 77 | /* Rotating image */ 78 | double angle = 30; /* rotation of 30 degrees. */ 79 | double rad = angle / 180 * 3.141592; /* Calcurate the radian value. */ 80 | 81 | page.graphicSave(); 82 | page.concat(iw * cos(rad), 83 | iw * sin(rad), 84 | ih * -sin(rad), 85 | ih * cos(rad), 86 | x, y); 87 | 88 | page.executeXObject( image); 89 | page.graphicRestore(); 90 | showDescription (page, x, y, "Rotating image"); 91 | 92 | x += 150; 93 | /* draw masked image. */ 94 | /* Set image2 to the mask image of image1 */ 95 | image1.setMaskImage(image2); 96 | 97 | page.setRGBFill(0, 0, 0); 98 | 99 | page.beginText(); 100 | page.moveTextPos(x - 6, y + 14); 101 | page.showText("MASKMASK"); 102 | page.endText(); 103 | 104 | page.drawImage(image1, x - 3, y - 3, iw + 6, ih + 6); 105 | 106 | showDescription(page, x, y, "masked image"); 107 | 108 | x = 100; 109 | y -= 120; 110 | /* color mask. */ 111 | page.setRGBFill(0, 0, 0); 112 | page.beginText(); 113 | page.moveTextPos(x - 6, y + 14); 114 | page.showText("MASKMASK"); 115 | page.endText(); 116 | 117 | image3.setColorMask(0, 255, 0, 0, 0, 255); 118 | page.drawImage(image3, x, y, iw, ih); 119 | showDescription(page, x, y, "Color Mask"); 120 | 121 | pdf.saveToFile("./image.pdf"); 122 | } catch (Exception exc) { 123 | writeln(exc); 124 | } 125 | } 126 | 127 | private Image getPngImage(Doc pdf, string fn) { 128 | version (Windows) { 129 | return pdf.loadPngImageFromFile("pngsuite\\" ~ fn); 130 | } else { 131 | return pdf.loadPngImageFromFile("pngsuite/" ~ fn); 132 | } 133 | } 134 | 135 | void showDescription(Page page, float x, float y, string text) { 136 | page.moveTo(x, y - 10); 137 | page.lineTo(x, y + 10); 138 | page.moveTo(x - 10, y); 139 | page.lineTo(x + 10, y); 140 | page.stroke(); 141 | 142 | page.setFontAndSize(page.getCurrentFont, 8); 143 | page.setRGBFill(0, 0, 0); 144 | 145 | page.beginText(); 146 | string coor = "(x=%s, y=%s)".format(x, y); 147 | page.moveTextPos (x - page.getTextWidth(coor) - 5, y - 10); 148 | page.showText(coor); 149 | page.endText(); 150 | 151 | page.beginText(); 152 | page.moveTextPos(x - 20, y - 25); 153 | page.showText(text); 154 | page.endText(); 155 | } 156 | -------------------------------------------------------------------------------- /examples/image/dub.sdl: -------------------------------------------------------------------------------- 1 | name "image" 2 | targetType "executable" 3 | dependency "harud" path="../../" 4 | sourceFiles "app.d" 5 | -------------------------------------------------------------------------------- /examples/image/makefile: -------------------------------------------------------------------------------- 1 | NAME = image 2 | VERSION = 0.1.0 3 | 4 | #IS_LIB = true 5 | 6 | ROOT_SOURCE_DIR = . 7 | 8 | getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d") 9 | SRC = $(getSources) 10 | 11 | LIB += ../../bin/libharud.a 12 | 13 | INCLUDES += -I../../src 14 | 15 | DFLAGS += $(if $(IS_LIB), -lib, ) 16 | ## -debug compile in debug code 17 | DFLAGS += -debug 18 | ## -g add symbolic debug info 19 | #DFLAGS += -g 20 | 21 | ## -w warnings as errors (compilation will halt) 22 | DFLAGS += -w 23 | 24 | ##-wi warnings as messages (compilation will continue) 25 | #DFLAGS += -wi 26 | 27 | DFLAGS += -m64 28 | 29 | LDFLAGS = -L-lhpdf 30 | ## si usa make VERS=x 31 | VERSION_FLAG = $(if $(VERS), -version=$(VERS), ) 32 | 33 | ################# 34 | # TEST 35 | ################# 36 | 37 | SRC_TEST = $(SRC) 38 | #SRC_TEST = $(filter-out $(ROOT_SOURCE_DIR)/app.d, $(SRC)) 39 | #SRC_TEST += $(wildcard tests/*.d) 40 | 41 | ## oppure 42 | #SRC_TEST = $(wildcard $(ROOT_SOURCE_DIR)/$(NAME)/*.d) 43 | #SRC_TEST += $(wildcard tests/*.d) 44 | 45 | LIB_TEST += $(LIB) 46 | #LIB_TEST = $(D_DIR)/dunit/libdunit.a 47 | #LIB_TEST += $(D_DIR)/DMocks-revived/libdmocks-revived.a 48 | #LIB_TEST += $(D_DIR)/unit-threaded/libunit-threaded.a 49 | 50 | INCLUDES_TEST += $(INCLUDES) 51 | #INCLUDES_TEST += -I$(D_DIR)/dunit/source 52 | #INCLUDES_TEST += -I$(D_DIR)/DMocks-revived 53 | #INCLUDES_TEST += -I$(D_DIR)/unit-threaded/source 54 | 55 | DFLAGS_TEST += -unittest 56 | # DFLAGS_TEST += -main -quiet 57 | 58 | PKG = $(wildcard $(BIN)/$(NAME)) 59 | PKG_SRC = $(PKG) $(SRC) makefile 60 | 61 | DEFAULT: all 62 | 63 | ################# 64 | BIN = . 65 | DMD = dmd 66 | BASE_NAME = $(basename $(NAME)) 67 | TEST_NAME = $(BASE_NAME)-test 68 | DSCAN = ~/dscanner 69 | .PHONY: all clean clobber test run 70 | 71 | all: builddir $(BIN)/$(NAME) 72 | 73 | builddir: 74 | @mkdir -p $(BIN) 75 | 76 | $(BIN)/$(NAME): $(SRC) $(LIB)| builddir 77 | $(DMD) $^ $(DFLAGS) $(INCLUDES) $(LDFLAGS) $(VERSION_FLAG) -of$@ 78 | 79 | run: all 80 | $(BIN)/$(NAME) 81 | xpdf ./$(NAME).pdf 82 | 83 | ## se si usa unit_threaded 84 | ## make test T=nome_test 85 | test: $(BIN)/$(TEST_NAME) 86 | @$(BIN)/$(TEST_NAME) $(T) 87 | 88 | $(BIN)/$(TEST_NAME): $(SRC_TEST) $(LIB_TEST)| builddir 89 | $(DMD) $^ $(DFLAGS_TEST) $(INCLUDES_TEST) $(LDFLAGS) $(VERSION_FLAG) -of$@ 90 | 91 | pkgdir: 92 | @mkdir -p pkg 93 | 94 | pkg: $(PKG) | pkgdir 95 | tar -jcf pkg/$(BASE_NAME)-$(VERSION).tar.bz2 $^ 96 | zip pkg/$(BASE_NAME)-$(VERSION).zip $^ 97 | 98 | pkgsrc: $(PKG_SRC) | pkgdir 99 | tar -jcf pkg/$(BASE_NAME)-$(VERSION)-src.tar.bz2 $^ 100 | 101 | tags: $(SRC) 102 | $(DSCAN) --ctags -R src > tags 103 | 104 | style: 105 | $(DSCAN) --styleCheck -R src/ 106 | 107 | clean: 108 | -rm -f $(BIN)/$(NAME) 109 | -rm -f $(BIN)/*.o 110 | -rm -f $(BIN)/*.pdf 111 | 112 | var: 113 | @echo SRC:$(SRC) 114 | @echo INCLUDES: $(INCLUDES) 115 | @echo DFLAGS: $(DFLAGS) 116 | @echo LDFLAGS: $(LDFLAGS) 117 | @echo VERSION: $(VERSION_FLAG) 118 | @echo 119 | @echo SRC_TEST: $(SRC_TEST) 120 | @echo INCLUDES_TEST: $(INCLUDES_TEST) 121 | -------------------------------------------------------------------------------- /examples/image/pngsuite/README: -------------------------------------------------------------------------------- 1 | 2 | pngsuite 3 | -------- 4 | (c) Willem van Schaik, 1999 5 | 6 | Permission to use, copy, and distribute these images for any purpose and 7 | without fee is hereby granted. 8 | 9 | These 15 images are part of the much larger PngSuite test-set of 10 | images, available for developers of PNG supporting software. The 11 | complete set, available at http:/www.schaik.com/pngsuite/, contains 12 | a variety of images to test interlacing, gamma settings, ancillary 13 | chunks, etc. 14 | 15 | The images in this directory represent the basic PNG color-types: 16 | grayscale (1-16 bit deep), full color (8 or 16 bit), paletted 17 | (1-8 bit) and grayscale or color images with alpha channel. You 18 | can use them to test the proper functioning of PNG software. 19 | 20 | filename depth type 21 | ------------ ------ -------------- 22 | basn0g01.png 1-bit grayscale 23 | basn0g02.png 2-bit grayscale 24 | basn0g04.png 4-bit grayscale 25 | basn0g08.png 8-bit grayscale 26 | basn0g16.png 16-bit grayscale 27 | basn2c08.png 8-bit truecolor 28 | basn2c16.png 16-bit truecolor 29 | basn3p01.png 1-bit paletted 30 | basn3p02.png 2-bit paletted 31 | basn3p04.png 4-bit paletted 32 | basn3p08.png 8-bit paletted 33 | basn4a08.png 8-bit gray with alpha 34 | basn4a16.png 16-bit gray with alpha 35 | basn6a08.png 8-bit RGBA 36 | basn6a16.png 16-bit RGBA 37 | 38 | Here is the correct result of typing "pngtest -m *.png" in 39 | this directory: 40 | 41 | Testing basn0g01.png: PASS (524 zero samples) 42 | Filter 0 was used 32 times 43 | Testing basn0g02.png: PASS (448 zero samples) 44 | Filter 0 was used 32 times 45 | Testing basn0g04.png: PASS (520 zero samples) 46 | Filter 0 was used 32 times 47 | Testing basn0g08.png: PASS (3 zero samples) 48 | Filter 1 was used 9 times 49 | Filter 4 was used 23 times 50 | Testing basn0g16.png: PASS (1 zero samples) 51 | Filter 1 was used 1 times 52 | Filter 2 was used 31 times 53 | Testing basn2c08.png: PASS (6 zero samples) 54 | Filter 1 was used 5 times 55 | Filter 4 was used 27 times 56 | Testing basn2c16.png: PASS (592 zero samples) 57 | Filter 1 was used 1 times 58 | Filter 4 was used 31 times 59 | Testing basn3p01.png: PASS (512 zero samples) 60 | Filter 0 was used 32 times 61 | Testing basn3p02.png: PASS (448 zero samples) 62 | Filter 0 was used 32 times 63 | Testing basn3p04.png: PASS (544 zero samples) 64 | Filter 0 was used 32 times 65 | Testing basn3p08.png: PASS (4 zero samples) 66 | Filter 0 was used 32 times 67 | Testing basn4a08.png: PASS (32 zero samples) 68 | Filter 1 was used 1 times 69 | Filter 4 was used 31 times 70 | Testing basn4a16.png: PASS (64 zero samples) 71 | Filter 0 was used 1 times 72 | Filter 1 was used 2 times 73 | Filter 2 was used 1 times 74 | Filter 4 was used 28 times 75 | Testing basn6a08.png: PASS (160 zero samples) 76 | Filter 1 was used 1 times 77 | Filter 4 was used 31 times 78 | Testing basn6a16.png: PASS (1072 zero samples) 79 | Filter 1 was used 4 times 80 | Filter 4 was used 28 times 81 | libpng passes test 82 | 83 | Willem van Schaik 84 | 85 | October 1999 86 | -------------------------------------------------------------------------------- /examples/image/pngsuite/basn0g01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn0g01.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn0g02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn0g02.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn0g04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn0g04.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn0g08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn0g08.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn0g16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn0g16.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn2c08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn2c08.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn2c16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn2c16.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn3p01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn3p01.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn3p02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn3p02.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn3p04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn3p04.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn3p08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn3p08.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn4a08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn4a08.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn4a16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn4a16.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn6a08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn6a08.png -------------------------------------------------------------------------------- /examples/image/pngsuite/basn6a16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/basn6a16.png -------------------------------------------------------------------------------- /examples/image/pngsuite/maskimage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/examples/image/pngsuite/maskimage.png -------------------------------------------------------------------------------- /examples/line/app.d: -------------------------------------------------------------------------------- 1 | import std.stdio; 2 | import std.conv; 3 | 4 | import harud; 5 | import harud.c; 6 | 7 | void main() { 8 | void errorCallback(uint error_number, uint detail_number) { 9 | writefln("err %x, %s, (num %x)" 10 | , error_number 11 | , getErrorDescription(error_number), 12 | detail_number); 13 | } 14 | 15 | 16 | try { 17 | Doc pdf = new Doc(&errorCallback); 18 | Font helvetica = pdf.getFont("Helvetica"); 19 | 20 | Page page = pdf.addPage(); 21 | 22 | page.drawBorder(); 23 | auto status = page.setFontAndSize(helvetica, 10); 24 | 25 | /* Draw verious widths of lines. */ 26 | page.setLineWidth( 0); 27 | page.drawLine( 60, 770, "line width = 0"); 28 | 29 | page.setLineWidth(1.0); 30 | page.drawLine(60, 740, "line width = 1.0"); 31 | 32 | page.setLineWidth(2.0); 33 | page.drawLine(60, 710, "line width = 2.0"); 34 | 35 | 36 | /* set big green line */ 37 | page.setLineWidth(30); 38 | page.setRGBStroke(0.0, 0.5, 0.0); 39 | 40 | /* Line Cap Style */ 41 | page.setLineCap( HaruLineCap.buttEnd); 42 | drawLine2(page, 60, 570, "PDF_BUTT_END"); 43 | 44 | page.setLineCap(HaruLineCap.roundEnd); 45 | drawLine2(page, 60, 505, "PDF_ROUND_END"); 46 | 47 | page.setLineCap(HaruLineCap.projectingScuareEnd); 48 | drawLine2(page, 60, 440, "PDF_PROJECTING_SCUARE_END"); 49 | 50 | page.setLineWidth(30); 51 | page.setRGBStroke(0.0, 0.5, 0.0); 52 | 53 | /* Line dash pattern */ 54 | testLineDashPattern(page); 55 | 56 | /* Line Join Style */ 57 | page.setLineWidth(30); 58 | page.setRGBStroke(0.0, 0.0, 0.5); 59 | 60 | page.setLineJoin(HaruLineJoin.miterJoin); 61 | page.drawHat(120, 300); 62 | 63 | page.beginText(); 64 | page.moveTextPos(60, 360); 65 | page.showText("PDF_MITER_JOIN"); 66 | page.endText(); 67 | 68 | page.setLineJoin(HaruLineJoin.roundJoin); 69 | writeln("LJ ", page.getLineJoin); 70 | 71 | page.drawHat(120, 195); 72 | 73 | page.beginText(); 74 | page.moveTextPos(60, 255); 75 | page.showText("PDF_ROUND_JOIN"); 76 | page.endText(); 77 | 78 | 79 | page.setLineJoin(HaruLineJoin.bevelJoin); 80 | page.drawHat(120, 90); 81 | 82 | page.beginText(); 83 | page.moveTextPos(60, 150); 84 | page.showText("PDF_BEVEL_JOIN"); 85 | page.endText(); 86 | 87 | /* Draw Rectangle */ 88 | page.setLineWidth(2); 89 | page.setRGBStroke(0, 0, 0); 90 | page.setRGBFill(0.75, 0.0, 0.0); 91 | 92 | drawRect(page, 300, 770, "Stroke"); 93 | page.stroke; 94 | 95 | drawRect(page, 300, 720, "Fill"); 96 | page.fill; 97 | 98 | drawRect(page, 300, 670, "Fill then Stroke"); 99 | page.fillStroke; 100 | 101 | 102 | pdf.saveToFile("./line.pdf"); 103 | } catch (Exception exc) { 104 | writeln(exc); 105 | } 106 | } 107 | 108 | private void testLineDashPattern(Page page) { 109 | /* Line dash pattern */ 110 | page.setLineWidth(1.0); 111 | 112 | enum ushort[] NN = [0, 0, 0, 0, 0, 0, 0, 0]; 113 | enum ushort[] DASH_MODE1 = [3]; 114 | enum ushort[] DASH_MODE2 = [3, 7]; 115 | enum ushort[] DASH_MODE3 = [8, 7, 2, 7]; 116 | 117 | page.setDash(DASH_MODE1, 1); 118 | 119 | drawLine(page, 60, 680, "dash_ptn=[3], phase=1 -- 2 on, 3 off, 3 on..."); 120 | 121 | page.setDash(DASH_MODE2, 2); 122 | drawLine(page, 60, 650, "dash_ptn=[7, 3], phase=2 -- 5 on 3 off, 7 on,..."); 123 | 124 | page.setDash(DASH_MODE3, 0); 125 | drawLine(page, 60, 620, "dash_ptn=[8, 7, 2, 7], phase=0"); 126 | page.setSolid(); 127 | } 128 | 129 | void drawBorder(Page page) { 130 | page.setLineWidth(1); 131 | page.rectangle(50, 50, page.getWidth - 100, page.getHeight - 110); 132 | page.stroke(); 133 | } 134 | 135 | void drawHat(Page page, float x, float y) { 136 | page.moveTo(x, y); 137 | page.lineTo(x + 40, y + 40); 138 | page.lineTo(x + 40 * 2, y); 139 | page.stroke(); 140 | } 141 | 142 | void drawLine(Page page, float x, float y, string label) { 143 | writeln(label); 144 | 145 | page.beginText(); 146 | page.moveTextPos( x, y - 10); 147 | page.showText(label); 148 | page.endText(); 149 | 150 | page.moveTo(x, y - 15); 151 | page.lineTo(x + 220, y - 15); 152 | page.stroke(); 153 | } 154 | 155 | void drawLine2(Page page, float x, float y, string label) { 156 | page.beginText(); 157 | page.moveTextPos(x, y); 158 | page.showText(label); 159 | page.endText(); 160 | 161 | page.moveTo(x + 30, y - 25); 162 | page.lineTo(x + 160, y - 25); 163 | page.stroke(); 164 | } 165 | 166 | void drawRect(Page page, float x, float y, string label) { 167 | page.beginText(); 168 | page.moveTextPos(x, y - 10); 169 | page.showText(label); 170 | page.endText(); 171 | page.rectangle(x, y - 40, 220, 25); 172 | } 173 | 174 | -------------------------------------------------------------------------------- /examples/line/dub.sdl: -------------------------------------------------------------------------------- 1 | name "line" 2 | targetType "executable" 3 | dependency "harud" path="../../" 4 | sourceFiles "app.d" 5 | -------------------------------------------------------------------------------- /examples/line/makefile: -------------------------------------------------------------------------------- 1 | NAME = line 2 | VERSION = 0.1.0 3 | 4 | ROOT_SOURCE_DIR = . 5 | 6 | getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d") 7 | SRC = $(getSources) 8 | 9 | LIB += ../../bin/libharud.a 10 | INCLUDES += -I../../src 11 | 12 | DFLAGS += $(if $(IS_LIB), -lib, ) 13 | ## -debug compile in debug code 14 | DFLAGS += -debug 15 | ## -g add symbolic debug info 16 | #DFLAGS += -g 17 | ## -w warnings as errors (compilation will halt) 18 | DFLAGS += -w 19 | DFLAGS += -m64 20 | LDFLAGS = -L-lhpdf 21 | 22 | VERSION_FLAG = $(if $(V), -version=$(V), ) 23 | 24 | DEFAULT: all 25 | 26 | ################# 27 | BIN = . 28 | DMD = dmd 29 | BASE_NAME = $(basename $(NAME)) 30 | PDF = evince 31 | .PHONY: all clean clobber run 32 | 33 | all: builddir $(BIN)/$(NAME) 34 | 35 | builddir: 36 | @mkdir -p $(BIN) 37 | 38 | $(BIN)/$(NAME): $(SRC) $(LIB)| builddir 39 | $(DMD) $^ $(DFLAGS) $(INCLUDES) $(LDFLAGS) $(VERSION_FLAG) -of$@ 40 | 41 | run: all 42 | $(BIN)/$(NAME) 43 | $(PDF) ./$(NAME).pdf 44 | 45 | ps: $(NAME).ps 46 | 47 | $(NAME).ps : $(NAME).pdf 48 | pdftops -paper A4 $^ 49 | 50 | $(NAME).pdf : all 51 | $(BIN)/$(NAME) 52 | 53 | tags: $(SRC) 54 | $(DSCAN) --ctags -R src > tags 55 | 56 | clean: 57 | -rm -f $(BIN)/*.o 58 | -rm -f $(BIN)/__* 59 | -rm -f $(BIN)/*.pdf 60 | 61 | clobber: 62 | -rm -f $(BIN)/$(NAME) 63 | 64 | 65 | var: 66 | @echo SRC:$(SRC) 67 | @echo INCLUDES: $(INCLUDES) 68 | @echo DFLAGS: $(DFLAGS) 69 | @echo LDFLAGS: $(LDFLAGS) 70 | @echo VERSION: $(VERSION_FLAG) 71 | -------------------------------------------------------------------------------- /examples/line_cmyk/app.d: -------------------------------------------------------------------------------- 1 | import std.stdio; 2 | import std.conv; 3 | 4 | import harud; 5 | import harud.c; 6 | 7 | void main() { 8 | void errorCallback(uint error_number, uint detail_number) { 9 | writefln("err %x, %s, (num %x)" 10 | , error_number 11 | , getErrorDescription(error_number), 12 | detail_number); 13 | } 14 | 15 | 16 | try { 17 | Doc pdf = new Doc(&errorCallback); 18 | Font helvetica = pdf.getFont("Helvetica"); 19 | 20 | Page page = pdf.addPage(); 21 | 22 | page.drawBorder(); 23 | auto status = page.setFontAndSize(helvetica, 10); 24 | 25 | /* Draw verious widths of lines. */ 26 | page.setLineWidth( 0); 27 | page.drawLine( 60, 770, "line width = 0"); 28 | 29 | page.setLineWidth(1.0); 30 | page.drawLine(60, 740, "line width = 1.0"); 31 | 32 | page.setLineWidth(2.0); 33 | page.drawLine(60, 710, "line width = 2.0"); 34 | 35 | 36 | /* set big green line */ 37 | page.setLineWidth(30); 38 | page.setCMYKStroke(0.0, 0.5, 0.0, 0); 39 | 40 | /* Line Cap Style */ 41 | page.setLineCap( HaruLineCap.buttEnd); 42 | drawLine2(page, 60, 570, "PDF_BUTT_END"); 43 | 44 | page.setLineCap(HaruLineCap.roundEnd); 45 | drawLine2(page, 60, 505, "PDF_ROUND_END"); 46 | 47 | page.setLineCap(HaruLineCap.projectingScuareEnd); 48 | drawLine2(page, 60, 440, "PDF_PROJECTING_SCUARE_END"); 49 | 50 | page.setLineWidth(30); 51 | page.setRGBStroke(0.0, 0.5, 0.0); 52 | 53 | /* Line dash pattern */ 54 | testLineDashPattern(page); 55 | 56 | /* Line Join Style */ 57 | page.setLineWidth(30); 58 | page.setRGBStroke(0.0, 0.0, 0.5); 59 | 60 | page.setLineJoin(HaruLineJoin.miterJoin); 61 | page.drawHat(120, 300); 62 | 63 | page.beginText(); 64 | page.moveTextPos(60, 360); 65 | page.showText("PDF_MITER_JOIN"); 66 | page.endText(); 67 | 68 | page.setLineJoin(HaruLineJoin.roundJoin); 69 | writeln("LJ ", page.getLineJoin); 70 | 71 | page.drawHat(120, 195); 72 | 73 | page.beginText(); 74 | page.moveTextPos(60, 255); 75 | page.showText("PDF_ROUND_JOIN"); 76 | page.endText(); 77 | 78 | 79 | page.setLineJoin(HaruLineJoin.bevelJoin); 80 | page.drawHat(120, 90); 81 | 82 | page.beginText(); 83 | page.moveTextPos(60, 150); 84 | page.showText("PDF_BEVEL_JOIN"); 85 | page.endText(); 86 | 87 | /* Draw Rectangle */ 88 | page.setLineWidth(2); 89 | page.setRGBStroke(0, 0, 0); 90 | page.setCMYKStroke(0.75, 0.0, 0.0, 0.0); 91 | 92 | drawRect(page, 300, 770, "Stroke"); 93 | page.stroke; 94 | 95 | drawRect(page, 300, 720, "Fill"); 96 | page.fill; 97 | 98 | page.setCMYKFill(0.43, 0.07, 0.0, 0.01); 99 | drawRect(page, 300, 670, "Fill then Stroke"); 100 | page.fillStroke; 101 | 102 | 103 | pdf.saveToFile("./line.pdf"); 104 | } catch (Exception exc) { 105 | writeln(exc); 106 | } 107 | } 108 | 109 | private void testLineDashPattern(Page page) { 110 | /* Line dash pattern */ 111 | page.setLineWidth(1.0); 112 | 113 | enum ushort[] NN = [0, 0, 0, 0, 0, 0, 0, 0]; 114 | enum ushort[] DASH_MODE1 = [3]; 115 | enum ushort[] DASH_MODE2 = [3, 7]; 116 | enum ushort[] DASH_MODE3 = [8, 7, 2, 7]; 117 | 118 | page.setDash(DASH_MODE1, 1); 119 | 120 | drawLine(page, 60, 680, "dash_ptn=[3], phase=1 -- 2 on, 3 off, 3 on..."); 121 | 122 | page.setDash(DASH_MODE2, 2); 123 | drawLine(page, 60, 650, "dash_ptn=[7, 3], phase=2 -- 5 on 3 off, 7 on,..."); 124 | 125 | page.setDash(DASH_MODE3, 0); 126 | drawLine(page, 60, 620, "dash_ptn=[8, 7, 2, 7], phase=0"); 127 | page.setSolid(); 128 | } 129 | 130 | void drawBorder(Page page) { 131 | page.setLineWidth(1); 132 | page.rectangle(50, 50, page.getWidth - 100, page.getHeight - 110); 133 | page.stroke(); 134 | } 135 | 136 | void drawHat(Page page, float x, float y) { 137 | page.moveTo(x, y); 138 | page.lineTo(x + 40, y + 40); 139 | page.lineTo(x + 40 * 2, y); 140 | page.stroke(); 141 | } 142 | 143 | void drawLine(Page page, float x, float y, string label) { 144 | writeln(label); 145 | 146 | page.beginText(); 147 | page.moveTextPos( x, y - 10); 148 | page.showText(label); 149 | page.endText(); 150 | 151 | page.moveTo(x, y - 15); 152 | page.lineTo(x + 220, y - 15); 153 | page.stroke(); 154 | } 155 | 156 | void drawLine2(Page page, float x, float y, string label) { 157 | page.beginText(); 158 | page.moveTextPos(x, y); 159 | page.showText(label); 160 | page.endText(); 161 | 162 | page.moveTo(x + 30, y - 25); 163 | page.lineTo(x + 160, y - 25); 164 | page.stroke(); 165 | } 166 | 167 | void drawRect(Page page, float x, float y, string label) { 168 | page.beginText(); 169 | page.moveTextPos(x, y - 10); 170 | page.showText(label); 171 | page.endText(); 172 | page.rectangle(x, y - 40, 220, 25); 173 | } 174 | 175 | -------------------------------------------------------------------------------- /examples/line_cmyk/dub.sdl: -------------------------------------------------------------------------------- 1 | name "linecmyk" 2 | targetType "executable" 3 | dependency "harud" path="../../" 4 | sourceFiles "app.d" 5 | -------------------------------------------------------------------------------- /examples/table/app.d: -------------------------------------------------------------------------------- 1 | import std.stdio: writeln; 2 | 3 | import harud; 4 | void main() { 5 | try { 6 | Doc pdf = new Doc(); /// New pdf document 7 | 8 | Page page = pdf.addPage(); /// Add a new page to the document 9 | page.setSize(PageSizes.A4, PageDirection.portrait); 10 | Font helvetica = pdf.getFont("Helvetica"); 11 | Font helveticaBold = getFont(pdf, StandardFont.helveticaBold); 12 | helvetica.printFontInfo; 13 | auto status = page.setFontAndSize(helvetica, 10); 14 | helvetica.printFontInfo; 15 | 16 | // col size = 516 /12 = 43 17 | Table table = new Table(page, createTopLeftRect(50, 800, 528 , 200)); 18 | 19 | table.addRow(18); 20 | page.setFontAndSize(helveticaBold, 12); 21 | 22 | //page.setCMYKFill(0.43, 0.07, 0.0, 0.01); 23 | 24 | table.addCol(Column(3, "Supply", HaruTextAlignment.left, CellBorder.all, 5, 0, 0, 0, HaruCMYKColor(0.47, 0., 0.47, 0.03))); 25 | 26 | page.setFontAndSize(helvetica, 12); 27 | //table.addCol(Column(1, "Set", HaruTextAlignment.center, CellBorder.all)); 28 | Column c0 ={colSpan: 1, text:"Set", alignment: HaruTextAlignment.center, border:CellBorder.all, fillColor: HaruCMYKColor(0.47, 0.3, 0.47, 0.03)}; 29 | table.addCol(c0); 30 | table.addCol(Column(2, "Measure", HaruTextAlignment.center, CellBorder.all)); 31 | page.setFontAndSize(helveticaBold, 12); 32 | table.addCol(Column(4, "Compressor power supply", HaruTextAlignment.left, CellBorder.all, 5)); 33 | page.setFontAndSize(helvetica, 12); 34 | table.addCol(Column(2, "Measure", HaruTextAlignment.center, CellBorder.all)); 35 | page.setFontAndSize(helvetica, 10); 36 | 37 | table.addRow(15); 38 | table.addCol(Column(3, "Voltage", HaruTextAlignment.left, CellBorder.all, 5)); 39 | table.addCol(Column(1, "", HaruTextAlignment.left, CellBorder.all, 5)); 40 | table.addCol(Column(2, "V", HaruTextAlignment.left, CellBorder.all, 5)); 41 | table.addCol(Column(4, "Voltage", HaruTextAlignment.left, CellBorder.all, 5)); 42 | table.addCol(Column(2, "V", HaruTextAlignment.left, CellBorder.all, 5)); 43 | 44 | table.addRow(15); 45 | table.addCol(Column(3, "Current", HaruTextAlignment.left, CellBorder.all, 5)); 46 | table.addCol(Column(1, "", HaruTextAlignment.left, CellBorder.all, 5)); 47 | table.addCol(Column(2, "A", HaruTextAlignment.left, CellBorder.all, 5)); 48 | table.addCol(Column(4, "Current", HaruTextAlignment.left, CellBorder.all, 5)); 49 | table.addCol(Column(2, "A", HaruTextAlignment.left, CellBorder.all, 5)); 50 | 51 | table.addRow(15); 52 | table.addCol(Column(3, "Power", HaruTextAlignment.left, CellBorder.all, 5)); 53 | table.addCol(Column(1, "", HaruTextAlignment.left, CellBorder.all, 5)); 54 | table.addCol(Column(2, "W", HaruTextAlignment.left, CellBorder.all, 5)); 55 | table.addCol(Column(4, "Power", HaruTextAlignment.left, CellBorder.all, 5)); 56 | table.addCol(Column(2, "W", HaruTextAlignment.left, CellBorder.all, 5)); 57 | 58 | table.addRow(15); 59 | table.addCol(Column(3, "Power factor", HaruTextAlignment.left, CellBorder.all, 5)); 60 | table.addCol(Column(1, "", HaruTextAlignment.left, CellBorder.all, 5)); 61 | table.addCol(Column(2, "", HaruTextAlignment.left, CellBorder.all, 5)); 62 | table.addCol(Column(4, "Power factor", HaruTextAlignment.left, CellBorder.all, 5)); 63 | table.addCol(Column(2, "", HaruTextAlignment.left, CellBorder.all, 5)); 64 | 65 | table.addRow(15); 66 | table.addCol(Column(3, "Frequency", HaruTextAlignment.left, CellBorder.all, 5)); 67 | table.addCol(Column(1, "", HaruTextAlignment.left, CellBorder.all, 5)); 68 | table.addCol(Column(2, "Hz", HaruTextAlignment.left, CellBorder.all, 5)); 69 | table.addCol(Column(4, "Frequency", HaruTextAlignment.left, CellBorder.all, 5)); 70 | table.addCol(Column(2, "Hz", HaruTextAlignment.left, CellBorder.all, 5)); 71 | 72 | 73 | table.addRow(10); 74 | table.addCol(Column(12, "", HaruTextAlignment.left, CellBorder.none)); 75 | 76 | table.addRow(18); 77 | page.setFontAndSize(helveticaBold, 12); 78 | table.addCol(Column(3, "Temperarure data", HaruTextAlignment.left, CellBorder.all, 5)); 79 | 80 | page.setFontAndSize(helvetica, 12); 81 | table.addCol(Column(1, "Set", HaruTextAlignment.center, CellBorder.all)); 82 | table.addCol(Column(2, "Measure", HaruTextAlignment.center, CellBorder.all)); 83 | page.setFontAndSize(helveticaBold, 12); 84 | table.addCol(Column(4, "Pressure data", HaruTextAlignment.left, CellBorder.all, 5)); 85 | page.setFontAndSize(helvetica, 12); 86 | table.addCol(Column(2, "Measure", HaruTextAlignment.center, CellBorder.all)); 87 | page.setFontAndSize(helvetica, 10); 88 | 89 | table.addRow(15); 90 | table.addCol(Column(3, "Voltage", HaruTextAlignment.left, CellBorder.all, 5)); 91 | table.addCol(Column(1, "", HaruTextAlignment.left, CellBorder.all, 5)); 92 | table.addCol(Column(2, "V", HaruTextAlignment.left, CellBorder.all, 5)); 93 | table.addCol(Column(4, "Voltage", HaruTextAlignment.left, CellBorder.all, 5)); 94 | table.addCol(Column(2, "V", HaruTextAlignment.left, CellBorder.all, 5)); 95 | 96 | pdf.saveToFile("./table.pdf"); /// Write to disk 97 | } catch(HarudException e) { 98 | writeln("exp:", e.msg, " num:", e.errCode); 99 | } catch (Exception e) { 100 | writeln("unknow error ", e.msg); 101 | } 102 | } 103 | 104 | void printFontInfo(Font f) { 105 | import std.stdio; 106 | writefln("getAscent : %s", f.getAscent );// Gets the vertical ascent of the font. 107 | writefln("getBBox : %s", f.getBBox );// Gets the bounding box of the font. 108 | writefln("getCapHeight : %s", f.getCapHeight );// Gets the distance from the baseline of uppercase letters. 109 | writefln("getDescent : %s", f.getDescent );// Gets the vertical descent of the font. 110 | writefln("getEncodingName: %s", f.getEncodingName );// Gets the encoding name of the font. 111 | writefln("getFontName : %s", f.getFontName );// Gets the name of the font. 112 | //writefln("getUnicodeWidth: %s", f.getUnicodeWidth );// Gets the width of a Unicode character in a specific font. 113 | writefln("getXHeight : %s pt", f.getXHeight );// Gets the distance from the baseline of lowercase letters. 114 | } 115 | -------------------------------------------------------------------------------- /examples/table/dub.sdl: -------------------------------------------------------------------------------- 1 | name "table" 2 | description "Simple example with tabel" 3 | targetType "executable" 4 | authors "Orfeo Da Viá" 5 | copyright "Copyright © 2015, o3o" 6 | license "Boost License" 7 | 8 | dependency "harud" path="../../" 9 | libs "hpdf" platform="posix" 10 | sourceFiles "../../lib/libhpdf.lib" platform="windows" 11 | sourceFiles "app.d" 12 | sourcePaths "." 13 | sourcePaths "../../lib/" platform="windows" 14 | -------------------------------------------------------------------------------- /lib/libhpdf.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/o3o/harud/256e91de90bf152b8628c2af7ef231d2ca9a8bef/lib/libhpdf.lib -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | # makefile release 0.4.0 2 | PROJECT_VERSION = $(getVer) 3 | 4 | ############# 5 | # Dirs # 6 | ############# 7 | ROOT_SOURCE_DIR = src 8 | BIN = bin 9 | 10 | ############# 11 | # Sources # 12 | ############# 13 | SRC = $(getSources) 14 | 15 | ############# 16 | # Names # 17 | ############# 18 | SDL_FILE = dub.sdl 19 | ifneq ("$(wildcard $(SDL_FILE))","") 20 | NAME = $(getNameSdl) 21 | else 22 | NAME = $(getNameJson) 23 | SDL_FILE = dub.json 24 | endif 25 | 26 | BIN_NAME = $(BIN)/lib$(NAME).a 27 | 28 | ############# 29 | # Packages # 30 | ############# 31 | ZIP_BIN = $(BIN_NAME) 32 | ZIP_SRC = $(ZIP_BIN) $(SRC) $(SDL_FILE) README.md CHANGELOG.md makefile 33 | ZIP_SRC += tests/*.d 34 | ZIP_PREFIX = $(NAME)-$(PROJECT_VERSION) 35 | 36 | 37 | getSources = $(shell find $(ROOT_SOURCE_DIR) -name "*.d") 38 | 39 | getVer = $(shell ag -o --nofilename '\d+\.\d+\.\d+(-\w+\.\d)?' $(ROOT_SOURCE_DIR)/$(NAME)/semver.d) 40 | #http://stackoverflow.com/questions/1546711/can-grep-show-only-words-that-match-search-pattern#1546735 41 | getNameSdl = $(shell ag -m1 --silent -o 'name\s+\"\K\w+' dub.sdl) 42 | getNameJson = $(shell ag -o -m1 '\"name\":\s+\"\K[[:alpha:]]+' dub.json) 43 | 44 | ############# 45 | # Commands # 46 | ############# 47 | DUB = dub 48 | DSCAN = $(D_DIR)/Dscanner/bin/dscanner 49 | MKDIR = mkdir -p 50 | RM = -rm -f 51 | UPX = upx --no-progress 52 | 53 | ############# 54 | # Flags # 55 | ############# 56 | # per impostatare la configurazione conf 57 | # make c=conf 58 | # per debug 59 | # make b=debug 60 | CONFIG += $(if $(c), -c$(c)) 61 | BUILD += $(if $(b), -b$(b)) 62 | # make run s=timer:countdown 63 | SUB += $(if $(s), $(NAME):$(s)) 64 | DUBFLAGS = -q $(CONFIG) $(BUILD) $(SUB) 65 | 66 | # si usa cosi: 67 | # make test W=tests.common.testRunOnce 68 | # oppure con piu' parametri 69 | # make test W='tests.common.testRunOnce -d' 70 | WHERE += $(if $(W), $(W)) 71 | SEP = $(if $(WHERE), -- ) 72 | 73 | .PHONY: all release force run run-rel test btest upx dx rx pkgall pkg pkgtar pkgsrc up tags style syn loc clean clobber pb pc pp ver var help 74 | 75 | DEFAULT: all 76 | 77 | all: 78 | $(DUB) build $(DUBFLAGS) 79 | 80 | build-ldc: 81 | $(DUB) build $(DUBFLAGS) --compiler=ldc 82 | 83 | release: 84 | $(DUB) build -brelease $(DUBFLAGS) 85 | 86 | rel-ldc: 87 | $(DUB) build -brelease --compiler=ldc $(DUBFLAGS) 88 | 89 | force: 90 | $(DUB) build --force --combined $(DUBFLAGS) 91 | 92 | run: 93 | $(DUB) run $(DUBFLAGS) 94 | run-rel: 95 | $(DUB) run -brelease $(DUBFLAGS) 96 | 97 | test: 98 | $(DUB) test -q $(SEP) $(WHERE) 99 | testd: 100 | $(DUB) test -q -- -d $(WHERE) 101 | testc: 102 | $(DUB) test -q -- -c $(WHERE) 103 | testl: 104 | $(DUB) test -q -- -l 105 | 106 | btest: 107 | $(DUB) build -cunittest -q 108 | 109 | dx: all upx 110 | rx: release upx 111 | upx: $(BIN)/$(NAME) 112 | $(UPX) $^ 113 | 114 | pkgdir: 115 | $(MKDIR) pkg 116 | 117 | pkgall: pkg pkgtar pkgsrc 118 | 119 | pkg: pkgdir | pkg/$(ZIP_PREFIX).zip 120 | 121 | pkg/$(ZIP_PREFIX).zip: $(ZIP_BIN) 122 | zip $@ $(ZIP_BIN) 123 | 124 | pkgtar: pkgdir | pkg/$(ZIP_PREFIX).tar.bz2 125 | 126 | pkg/$(ZIP_PREFIX).tar.bz2: $(ZIP_BIN) 127 | tar -jcf $@ $^ 128 | 129 | pkgsrc: pkgdir | pkg/$(ZIP_PREFIX)-src.tar.bz2 130 | 131 | pkg/$(ZIP_PREFIX)-src.tar.bz2: $(ZIP_SRC) 132 | tar -jcf $@ $^ 133 | 134 | up: 135 | $(DUB) upgrade 136 | 137 | tags: $(SRC) 138 | $(DSCAN) --ctags $^ > tags 139 | 140 | style: $(SRC) 141 | $(DSCAN) --styleCheck $^ 142 | 143 | syn: $(SRC) 144 | $(DSCAN) --syntaxCheck $^ 145 | 146 | loc: $(SRC) 147 | $(DSCAN) --sloc $^ 148 | 149 | imp: $(SRC) 150 | $(DSCAN) -i $^ 151 | 152 | clean: 153 | $(DUB) clean 154 | 155 | clobber: clean 156 | $(RM) $(BIN_NAME) 157 | $(RM) $(BIN)/*.log 158 | $(RM) $(BIN)/test-runner 159 | 160 | pb: 161 | @$(DUB) build --print-builds 162 | pc: 163 | $(DUB) build --print-configs 164 | pp: 165 | $(DUB) build --print-platform 166 | 167 | changelog: CHANGELOG.txt 168 | CHANGELOG.txt: CHANGELOG.md 169 | pandoc -f markdown_github -t plain $^ > $@ 170 | 171 | ver: 172 | @echo $(PROJECT_VERSION) 173 | 174 | var: 175 | @echo 176 | @echo "General" 177 | @echo "--------------------" 178 | @echo "NAME :" $(NAME) 179 | @echo "BIN_NAME :" $(BIN_NAME) 180 | @echo "PRJ_VER :" $(PROJECT_VERSION) 181 | @echo "DUBFLAGS :" $(DUBFLAGS) 182 | @echo "DUB FILE :" $(SDL_FILE) 183 | @echo 184 | @echo "Directory" 185 | @echo "--------------------" 186 | @echo "D_DIR :" $(D_DIR) 187 | @echo "BIN :" $(BIN) 188 | @echo "ROOT_SOURCE_DIR :" $(ROOT_SOURCE_DIR) 189 | @echo "TEST_SOURCE_DIR :" $(TEST_SOURCE_DIR) 190 | @echo 191 | @echo "Zip" 192 | @echo "--------------------" 193 | @echo "ZIP_BIN : " $(ZIP_BIN) 194 | @echo "ZIP_PREFIX :" $(ZIP_PREFIX) 195 | @echo 196 | @echo "Zip source" 197 | @echo "--------------------" 198 | @echo $(ZIP_SRC) 199 | @echo 200 | @echo "Source" 201 | @echo "--------------------" 202 | @echo $(SRC) 203 | @echo 204 | 205 | # Help Target 206 | help: 207 | @echo "The following are some of the valid targets for this Makefile:" 208 | @echo "Compile" 209 | @echo "--------------------" 210 | @echo " all : (the default if no target is provided)" 211 | @echo " release : Compiles in release mode" 212 | @echo " rel-ldc : Compiles in release mode with ldc compiler" 213 | @echo " force : Forces a recompilation" 214 | @echo " run : Builds and runs" 215 | @echo " test : Build and executes the tests" 216 | @echo " testd : Build and executes the tests in debug mode" 217 | @echo " testc : Build and executes the tests with execution time" 218 | @echo " btest : Build the tests" 219 | @echo " upx : Compress using upx" 220 | @echo " dx : Make debug and compress using upx" 221 | @echo " rx : Make release and compress using upx" 222 | @echo "" 223 | @echo "Pack" 224 | @echo "--------------------" 225 | @echo " pkgall : Executes pkg, pkgtar, pkgsrc" 226 | @echo " pkg : Zip binary" 227 | @echo " pkgtar : Tar binary" 228 | @echo " pkgsrc : Tar source" 229 | @echo "" 230 | @echo "Utility" 231 | @echo "--------------------" 232 | @echo " up : Forces an upgrade of all dub dependencies" 233 | @echo " tags : Generates tag file" 234 | @echo " style : Checks programming style" 235 | @echo " syn : Syntax check" 236 | @echo " loc : Counts lines of code" 237 | @echo " clean : Removes intermediate build files" 238 | @echo " clobber : Removes all" 239 | @echo "" 240 | @echo "Print" 241 | @echo "--------------------" 242 | @echo " pb : Prints the list of available build types" 243 | @echo " pc : Prints the list of available configurations" 244 | @echo " pp : Prints the identifiers for the current build platform as used for the build fields" 245 | @echo " ver : Prints version" 246 | @echo " var : Lists all variables" 247 | @echo "" 248 | @echo "Common options" 249 | @echo "--------------------" 250 | @echo " make c=conf : Uses 'conf' configuration" 251 | @echo " make b=debug : Uses 'debug' build" 252 | @echo " make s=y : Uses 'y' subpakages" 253 | -------------------------------------------------------------------------------- /src/harud/annotation.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Describes an annotation. 3 | */ 4 | module harud.annotation; 5 | 6 | import harud; 7 | import harud.c.capi; 8 | 9 | /** 10 | * Haru PDF Annotation class. 11 | */ 12 | class Annotation : IHaruObject { 13 | protected HPDF_Annotation _annotation; 14 | 15 | this(HPDF_Annotation annotation) { 16 | _annotation = annotation; 17 | } 18 | 19 | /** 20 | * Defines the appearance when a mouse clicks on a link annotation. 21 | * 22 | * Params: 23 | * mode = mode for highlighting 24 | */ 25 | HPDF_STATUS setHighlightMode(HaruAnnotHighlightMode mode) { 26 | return HPDF_LinkAnnot_SetHighlightMode(this._annotation, mode); 27 | } 28 | 29 | /** 30 | * Defines the style of the annotation's border. 31 | * 32 | * Params: 33 | * width = The width of an annotation's border. 34 | * dashOn = The dash style. 35 | * dashOff = The dash style 36 | */ 37 | HPDF_STATUS setBorderStyle(float width, ushort dashOn, ushort dashOff) { 38 | return HPDF_LinkAnnot_SetBorderStyle(this._annotation, width, dashOn, dashOff); 39 | } 40 | 41 | /** 42 | * Defines the style of the annotation's icon 43 | * 44 | * Params: 45 | * icon = a [HaruAnnotIcon] value 46 | */ 47 | HPDF_STATUS setIcon(HaruAnnotIcon icon) { 48 | return HPDF_TextAnnot_SetIcon(this._annotation, icon); 49 | } 50 | 51 | /** 52 | * Defines whether the text-annotation is initially open. 53 | * 54 | * Params: 55 | * open = true means the annotation initially displayed open. 56 | */ 57 | HPDF_STATUS setOpened(bool open) { 58 | return HPDF_TextAnnot_SetOpened(this._annotation, cast(uint)open); 59 | } 60 | 61 | public HPDF_HANDLE getHandle() { 62 | return this._annotation; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/harud/c/package.d: -------------------------------------------------------------------------------- 1 | module harud.c; 2 | 3 | public import harud.c.capi; 4 | public import harud.c.consts; 5 | -------------------------------------------------------------------------------- /src/harud/destination.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Describes a destination 3 | */ 4 | module harud.destination; 5 | 6 | import harud; 7 | import harud.c.capi; 8 | 9 | /** 10 | * Haru PDF Destination Class. 11 | */ 12 | class Destination { 13 | private HPDF_Destination _destination; 14 | 15 | this(HPDF_Destination destination) { 16 | _destination = destination; 17 | } 18 | 19 | @property HPDF_Destination destinationHandle() { 20 | return this._destination; 21 | } 22 | 23 | /** 24 | * Defines the appearance of a page with three parameters which are left, top and zoom. 25 | * 26 | * Params: 27 | * left = The left coordinates of the page. 28 | * top = The top coordinates of the page. 29 | * zoom = The page magnified factor. The value must be between 0.08(8%) to 32(%). 30 | */ 31 | HPDF_STATUS setXYZ(float left, float top, float zoom) { 32 | return HPDF_Destination_SetXYZ(this._destination, left, top, zoom); 33 | } 34 | 35 | /** 36 | * Sets the appearance of the page to displadescriptionying entire page within the window 37 | */ 38 | HPDF_STATUS setFit() { 39 | return HPDF_Destination_SetFit(this._destination); 40 | } 41 | 42 | /** 43 | * Defines the appearance of a page to magnifying to fit the width of the page within the window and setting 44 | * the top position of the page to the value of the "top" parameter. 45 | * 46 | * Params: 47 | * top = The top coordinates of the page. 48 | */ 49 | HPDF_STATUS setFitH(float top) { 50 | return HPDF_Destination_SetFitH(this._destination, top); 51 | } 52 | 53 | /** 54 | * Defines the appearance of a page to magnifying to fit the 55 | * height of the page within the window and setting the left 56 | * position of the page to the value of the "left" parameter. 57 | * 58 | * Params: 59 | * left = The left coordinates of the page. 60 | */ 61 | HPDF_STATUS setFitV(float left) { 62 | return HPDF_Destination_SetFitV(this._destination, left); 63 | } 64 | 65 | /** 66 | * Defines the appearance of a page to magnifying the page to fit a rectangle specified by left, bottom, right and top. 67 | * 68 | * Params: 69 | * left = The left coordinates of the page. 70 | * bottom = The bottom coordinates of the page. 71 | * right = The right coordinates of the page. 72 | * top = The top coordinates of the page. 73 | * 74 | */ 75 | HPDF_STATUS setFitR(float left, float bottom, float right, float top) { 76 | return HPDF_Destination_SetFitR(this._destination, left, bottom, right, top); 77 | } 78 | 79 | /** 80 | * Sets the appearance of the page to magnifying to fit the bounding box of the page within the window. 81 | * 82 | */ 83 | HPDF_STATUS setFitB() { 84 | return HPDF_Destination_SetFitB(this._destination); 85 | } 86 | 87 | /** 88 | * Defines the appearance of a page to magnifying to fit the width of the bounding box of the page within the window 89 | * and setting the top position of the page to the value of the "top" parameter. 90 | * 91 | * Params: 92 | * top = The top coordinates of the page. 93 | */ 94 | HPDF_STATUS setFitBH(float top) { 95 | return HPDF_Destination_SetFitBH(this._destination, top); 96 | } 97 | 98 | /** 99 | * Defines the appearance of a page to magnifying to fit the height of the bounding box of the page within the window 100 | * and setting the left position of the page to the value of the "left" parameter. 101 | * 102 | * Params: 103 | * left = The left coordinates of the page. 104 | */ 105 | HPDF_STATUS setFitBV(float left) { 106 | return HPDF_Destination_SetFitBV(this._destination, left); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/harud/encoder.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Describes an encoder 3 | */ 4 | module harud.encoder; 5 | 6 | import harud.c; 7 | import harud.haruobject; 8 | import harud.types; 9 | 10 | /** 11 | * Encoder class 12 | */ 13 | class Encoder : IHaruObject { 14 | protected HPDF_Encoder _encoder; 15 | 16 | this(HPDF_Encoder encoder) { 17 | _encoder = encoder; 18 | } 19 | 20 | /** 21 | * Gets the type of an encoding object. 22 | * 23 | * Returns: 24 | * a Encoder value 25 | */ 26 | HaruEncoderType getType() { 27 | return HPDF_Encoder_GetType(this._encoder); 28 | } 29 | 30 | /** 31 | * Get the type of byte in the text at position index. 32 | * 33 | * Returns: 34 | * a $(LINK2 harud/c/types/HaruByteType.html, HaruByteType) value 35 | */ 36 | HaruByteType getByteType(char[] text, uint index) { 37 | return HPDF_Encoder_GetByteType(this._encoder, cast(char*)text, index); 38 | } 39 | 40 | /** 41 | * Converts a specified character code to unicode. 42 | * 43 | * Params: 44 | * code = A character code to convert. 45 | * 46 | * Returns: 47 | * the converted character to unicode 48 | */ 49 | HPDF_UNICODE getUnicode(ushort code) { 50 | return HPDF_Encoder_GetUnicode(this._encoder, code); 51 | } 52 | 53 | unittest { 54 | 55 | } 56 | 57 | /** 58 | * Gets the writing mode for the encoding object. 59 | * 60 | * Returns: 61 | * a $(LINK2 harud/c/types/HaruWritingMode.html, HaruWritingMode) value 62 | */ 63 | HaruWritingMode getWritingMode() { 64 | return HPDF_Encoder_GetWritingMode(this._encoder); 65 | } 66 | 67 | public HPDF_HANDLE getHandle() { 68 | return _encoder; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/harud/extension.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Uniform Function Call Syntax (UFCS) extensions 3 | * 4 | */ 5 | module harud.extension; 6 | 7 | import harud.page : Page; 8 | import harud.types : Rect, HaruTextAlignment, HaruCMYKColor; 9 | 10 | uint addRect(Page page, Rect rect) { 11 | return page.rectangle(rect.left, rect.bottom, rect.right - rect.left, rect.top - rect.bottom); 12 | } 13 | 14 | uint addTextRect(Page page, Rect rect, string text, HaruTextAlignment alignment) { 15 | uint len; 16 | page.textRect(rect.left, rect.top, rect.right, rect.bottom, text, alignment, &len); 17 | return len; 18 | } 19 | 20 | uint setFillColor(Page page, HaruCMYKColor color) { 21 | if (color.isValidCMYKColor) { 22 | return page.setCMYKFill(color.cyan, color.magenta, color.yellow, color.key); 23 | } else { 24 | return -1; 25 | } 26 | } 27 | 28 | uint setStrokeColor(Page page, HaruCMYKColor color) { 29 | if (color.isValidCMYKColor) { 30 | return page.setCMYKStroke(color.cyan, color.magenta, color.yellow, color.key); 31 | } else { 32 | return -1; 33 | } 34 | } 35 | 36 | bool isValidCMYKColor(HaruCMYKColor color) { 37 | import std.math; 38 | return !color.cyan.isNaN && !color.magenta.isNaN && !color.yellow.isNaN && !color.key.isNaN && color.cyan >= 0 39 | && color.magenta >= 0 && color.yellow >= 0 && color.key >= 0 && color.cyan <= 1 && color.magenta <= 1 40 | && color.yellow <= 1 && color.key <= 1; 41 | } 42 | 43 | unittest { 44 | HaruCMYKColor color; 45 | assert(!color.isValidCMYKColor); 46 | HaruCMYKColor fillColor = HaruCMYKColor(0, 0, 0, 0); 47 | assert(fillColor.isValidCMYKColor); 48 | } 49 | -------------------------------------------------------------------------------- /src/harud/font.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Describes fonts objects 3 | */ 4 | module harud.font; 5 | 6 | import harud.c.capi; 7 | import harud.c.consts; 8 | import harud.haruobject; 9 | import harud.types; 10 | import std.conv; 11 | import std.string; 12 | 13 | /** 14 | * Font class 15 | */ 16 | class Font : IHaruObject { 17 | protected HPDF_Font _font; 18 | 19 | this(HPDF_Font font) { 20 | _font = font; 21 | } 22 | 23 | /** 24 | * Gets the name of the font. 25 | * 26 | * Returns: 27 | * the font name on success. Otherwise, returns null. 28 | */ 29 | string getFontName() { 30 | return to!string(HPDF_Font_GetFontName(this._font)); 31 | } 32 | 33 | /** 34 | * Gets the encoding name of the font. 35 | * 36 | * Returns: 37 | * the encoding name of the font on success. Otherwise, returns null. 38 | */ 39 | string getEncodingName() { 40 | return to!string(HPDF_Font_GetEncodingName(this._font)); 41 | } 42 | 43 | /** 44 | * Gets the width of a Unicode character in a specific font. 45 | * 46 | * Actual width of the character on the page can be calculated as follows: 47 | * 48 | * Examples: 49 | * -------------------- 50 | * char_width = font.getUnicodeWidth(UNICODE); 51 | * float actual_width = char_width * FONT_SIZE / 1000; 52 | * -------------------- 53 | * 54 | * Params: 55 | * code = A Unicode character. 56 | * 57 | * Returns: 58 | * the character width on success. Otherwise, returns null. 59 | */ 60 | int getUnicodeWidth(HPDF_UNICODE code) { 61 | return HPDF_Font_GetUnicodeWidth(this._font, code); 62 | } 63 | 64 | /** 65 | * Gets the bounding box of the font. 66 | * 67 | * Returns: 68 | * On success, returns Rect struct specifying the font bounding box. 69 | * Otherwise, returns a HaruBox struct of {0, 0, 0, 0}. 70 | */ 71 | Rect getBBox() { 72 | return HPDF_Font_GetBBox(this._font); 73 | } 74 | 75 | /** 76 | * Gets the vertical ascent of the font. 77 | * 78 | * Returns: 79 | * the font vertical ascent on success. Otherwise, returns 0. 80 | */ 81 | int getAscent() { 82 | return HPDF_Font_GetAscent(this._font); 83 | } 84 | 85 | /** 86 | * Gets the vertical descent of the font. 87 | * 88 | * Returns: 89 | * the font vertical descent on success. Otherwise, returns 0. 90 | */ 91 | int getDescent() { 92 | return HPDF_Font_GetDescent(this._font); 93 | } 94 | 95 | /** 96 | * Gets the distance from the baseline of lowercase letters. 97 | * 98 | * Returns: 99 | * the font x-height value on success. Otherwise, returns 0. 100 | */ 101 | uint getXHeight() { 102 | return HPDF_Font_GetXHeight(this._font); 103 | } 104 | 105 | /** 106 | * Gets the distance from the baseline of uppercase letters. 107 | * 108 | * Returns: 109 | * the font cap height on success. Otherwise, returns 0. 110 | */ 111 | uint getCapHeight() { 112 | return HPDF_Font_GetCapHeight(this._font); 113 | } 114 | 115 | /** 116 | * Gets total width of the text, number of characters, and number of words. 117 | * 118 | * Params: 119 | * text = The text to get width. 120 | * len = The byte length of the text. 121 | * 122 | * Returns: 123 | * On success, returns a TextWidth struct including calculation result.
124 | * Otherwise, returns TextWidth struct whose attributes are all 0. 125 | */ 126 | TextWidth textWidth(string text, uint len) { 127 | return HPDF_Font_TextWidth(this._font, text.toStringz(), len); 128 | } 129 | 130 | /** 131 | * Calculates the byte length which can be included within the specified width. 132 | * 133 | * Params: 134 | * text = The text to use for calculation. 135 | * len = The length of the text. 136 | * width = The width of the area to put the text. 137 | * fontSize = The size of the font. 138 | * charSpace = The character spacing. 139 | * wordSpace = The word spacing. 140 | * wordWrap = Suppose there are three words: "ABCDE", "FGH", and "IJKL". Also, suppose the substring until "J" can be included within the width (12 bytes). If word_wrap is HPDF_FALSE the function returns 12. If word_wrap parameter is HPDF_TRUE, it returns 10 (the end of the previous word). 141 | * realWidth = If not NULL, parameter is set to the real width of the text. If NULL, parameter is ignored. 142 | * 143 | * Returns: 144 | * On success, returns byte length which can be included within specified width. Otherwise, returns 0. 145 | */ 146 | uint measureText(string text, uint len, float width, float fontSize, float charSpace, float wordSpace, 147 | bool wordWrap, float* realWidth) { 148 | return HPDF_Font_MeasureText(this._font, text.toStringz, len, width, fontSize, charSpace, wordSpace, wordWrap 149 | ? HPDF_TRUE : HPDF_FALSE, realWidth); 150 | } 151 | 152 | HPDF_HANDLE getHandle() { 153 | return _font; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/harud/haruobject.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Generic haru object interface 3 | */ 4 | module harud.haruobject; 5 | 6 | import harud; 7 | 8 | interface IHaruObject { 9 | protected HPDF_HANDLE getHandle(); 10 | } 11 | -------------------------------------------------------------------------------- /src/harud/image.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Describes an image 3 | */ 4 | module harud.image; 5 | 6 | import harud.c; 7 | import harud.haruobject; 8 | import harud.types; 9 | import std.conv; 10 | 11 | /** 12 | * Image class 13 | */ 14 | class Image : IHaruObject { 15 | protected HPDF_Image _image; 16 | 17 | this(HPDF_Image image) { 18 | _image = image; 19 | } 20 | 21 | /** 22 | * Gets the size of the image of an image object. 23 | * 24 | * Returns: 25 | * When succeed, it returns a $(LINK2 harud/c/types/Point.html, Point) struct which includes the size of the image. 26 | * Otherwise, it returns a $(LINK2 harud/c/types/Point.html, Point) struct whose value is (0, 0). 27 | */ 28 | Point getSize() { 29 | return HPDF_Image_GetSize(this._image); 30 | } 31 | 32 | /** 33 | * Gets the width of the image of an image object. 34 | * 35 | * Returns: 36 | * When succeed, it returns the width of the image. Otherwise, it returns 0. 37 | */ 38 | uint getWidth() { 39 | return HPDF_Image_GetWidth(this._image); 40 | } 41 | 42 | /** 43 | * Gets the height of the image of an image object. 44 | * 45 | * Returns: 46 | * when succeed, it returns the height of the image. Otherwise, it returns 0. 47 | */ 48 | uint getHeight() { 49 | return HPDF_Image_GetHeight(this._image); 50 | } 51 | 52 | /** 53 | * Gets the number of bits used to describe each color component. 54 | */ 55 | uint getBitsPerComponent() { 56 | return HPDF_Image_GetBitsPerComponent(this._image); 57 | } 58 | 59 | /** 60 | * Gets the name of the image's color space. 61 | * 62 | * Returns: 63 | * when getColorSpace() succeed, it returns the following values. Otherwise, it returns null. 64 | * $(UL 65 | * $(LI DeviceGray) 66 | * $(LI DeviceRGB) 67 | * $(LI DeviceCMYK) 68 | * $(LI Indexed) 69 | * ) 70 | */ 71 | string getColorSpace() { 72 | return to!string(HPDF_Image_GetColorSpace(this._image)); 73 | } 74 | 75 | /** 76 | * Sets the transparent color of the image by the RGB range values. 77 | * 78 | * The color within the range is displayed as a transparent color. The Image must be RGB color space. 79 | * 80 | * Params: 81 | * rmin = The lower limit of Red. It must be between 0 and 255. 82 | * rmax = The upper limit of Red. It must be between 0 and 255. 83 | * gmin = The lower limit of Green. It must be between 0 and 255. 84 | * gmax = The upper limit of Green. It must be between 0 and 255. 85 | * bmin = The lower limit of Blue. It must be between 0 and 255. 86 | * bmax = The upper limit of Blue. It must be between 0 and 255. 87 | */ 88 | HPDF_STATUS setColorMask(uint rmin, uint rmax, uint gmin, uint gmax, uint bmin, uint bmax) 89 | 90 | in { 91 | assert(rmin < 256, "rmin should less than 256"); 92 | assert(rmax < 256, "rmax should less than 256"); 93 | assert(gmin < 256, "gmin should less than 256"); 94 | assert(gmax < 256, "gmax should less than 256"); 95 | assert(bmin < 256, "bmin should less than 256"); 96 | assert(bmax < 256, "bmax should less than 256"); 97 | } 98 | do { 99 | return HPDF_Image_SetColorMask(this._image, rmin, rmax, gmin, gmax, bmin, bmax); 100 | } 101 | 102 | void setMaskImage(Image maskImage) { 103 | HPDF_Image_SetMaskImage(this._image, maskImage.getHandle()); 104 | } 105 | 106 | public HPDF_HANDLE getHandle() { 107 | return _image; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/harud/outline.d: -------------------------------------------------------------------------------- 1 | /// 2 | module harud.outline; 3 | 4 | import harud.haruobject; 5 | import harud.destination; 6 | import harud.c; 7 | import harud.types; 8 | 9 | /** 10 | * Outline class 11 | */ 12 | class Outline : IHaruObject { 13 | private HPDF_Outline _outline; 14 | 15 | this(HPDF_Outline outline) { 16 | _outline = outline; 17 | } 18 | 19 | /** 20 | * Sets whether this node is opened or not when the outline is displayed for the first time. 21 | * 22 | * Params: 23 | * opened = Specify whether the node is opened or not. 24 | */ 25 | HPDF_STATUS setOpened(bool opened) { 26 | return HPDF_Outline_SetOpened(this._outline, cast(uint)opened); 27 | } 28 | 29 | /** 30 | * Sets a destination object which becomes to a target to jump when the outline is clicked. 31 | * 32 | * Params: 33 | * dst = Specify the handle of an destination object. 34 | */ 35 | HPDF_STATUS setDestination(Destination dst) { 36 | assert(dst !is null, "dst should be not null"); 37 | return HPDF_Outline_SetDestination(this._outline, dst.destinationHandle); 38 | } 39 | 40 | public HPDF_HANDLE getHandle() { 41 | return _outline; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/harud/package.d: -------------------------------------------------------------------------------- 1 | module harud; 2 | 3 | public import harud.haruobject; 4 | public import harud.types; 5 | public import harud.annotation; 6 | public import harud.destination; 7 | public import harud.doc; 8 | public import harud.encoder; 9 | public import harud.error; 10 | public import harud.font; 11 | public import harud.image; 12 | public import harud.outline; 13 | public import harud.page; 14 | public import harud.util; 15 | public import harud.table; 16 | -------------------------------------------------------------------------------- /src/harud/semver.d: -------------------------------------------------------------------------------- 1 | module harud.semver; 2 | enum VERSION = "1.0.3"; 3 | -------------------------------------------------------------------------------- /src/harud/table.d: -------------------------------------------------------------------------------- 1 | /** 2 | * Table support 3 | */ 4 | module harud.table; 5 | 6 | import harud.page: Page; 7 | import harud.types: Rect, HaruTextAlignment, HaruCMYKColor; 8 | 9 | 10 | /** 11 | * Describe a table. 12 | * 13 | * A `Table` is a layout element that represents data in a two-dimensional grid 14 | */ 15 | class Table { 16 | private Page page; 17 | this(Page page, Rect rect) { 18 | assert(page !is null); 19 | this.page = page; 20 | x0 = x = rect.left; 21 | y0 = y = rect.top; 22 | width = rect.right - rect.left; 23 | height = rect.top - rect.bottom; 24 | _divSize = width / 12; 25 | currentHeight = 0.; 26 | } 27 | 28 | private float x0; 29 | private float y0; 30 | private float x; 31 | private float y; 32 | private float height; 33 | private float width; 34 | /** 35 | * Add a [Column] to table. 36 | */ 37 | void addCol(Column col) { 38 | import harud.extension: addTextRect, addRect, setFillColor, setStrokeColor; 39 | import harud.util: createTopLeftRect; 40 | 41 | drawBorder(col); 42 | fillCell(col); 43 | 44 | page.beginText; 45 | float w = col.colSpan * _divSize; 46 | Rect r = createTopLeftRect(x + col.paddingLeft, y - col.paddingBottom, w - col.paddingLeft - col.paddingRight, currentHeight - col.paddingTop - col.paddingBottom); 47 | page.addTextRect(r, col.text, col.alignment); 48 | page.endText; 49 | 50 | x += col.colSpan * _divSize; 51 | } 52 | 53 | private void fillCell(Column col) { 54 | import harud.extension: addRect, setFillColor, setStrokeColor; 55 | import harud.util: createTopLeftRect; 56 | 57 | page.graphicSave(); 58 | 59 | page.setFillColor(col.fillColor); 60 | Rect border = createTopLeftRect(x, y, col.colSpan * _divSize, currentHeight); 61 | page.addRect(border); 62 | page.fill; 63 | 64 | page.graphicRestore; 65 | } 66 | 67 | private void drawBorder(Column col) { 68 | import std.stdio; 69 | import harud.extension: addTextRect, addRect, setFillColor, setStrokeColor; 70 | 71 | page.graphicSave(); 72 | 73 | page.setStrokeColor(col.borderColor); 74 | float w = col.colSpan * _divSize; 75 | float h = currentHeight; 76 | if (col.border & CellBorder.top) { 77 | page.moveTo(x, y); 78 | page.lineTo(x + w, y); 79 | } 80 | if (col.border & CellBorder.right) { 81 | page.moveTo(x + w, y); 82 | page.lineTo(x + w, y - h); 83 | } 84 | if (col.border & CellBorder.bottom) { 85 | page.moveTo(x + w, y - h); 86 | page.lineTo(x, y - h); 87 | } 88 | if (col.border & CellBorder.left) { 89 | page.moveTo(x, y - h); 90 | page.lineTo(x, y); 91 | } 92 | page.moveTo(x, y); 93 | page.stroke; 94 | 95 | page.graphicRestore; 96 | } 97 | 98 | private float currentHeight; 99 | void addRow(float height) { 100 | x = x0; 101 | y -= currentHeight; 102 | currentHeight = height; 103 | } 104 | 105 | private float _divSize; 106 | float divSize() { 107 | return _divSize; 108 | } 109 | } 110 | 111 | /** 112 | * Describes a table colums (cell). 113 | * 114 | * Table divide horizontal space into indivisible units called "columns". 115 | * All columns in a table must specify their width as proportion of the total available row width. 116 | * harud uses 12 columns 117 | */ 118 | struct Column { 119 | /** 120 | * Specifies the column width 121 | */ 122 | int colSpan; 123 | /** 124 | * Text 125 | */ 126 | string text; 127 | HaruTextAlignment alignment = HaruTextAlignment.left; 128 | CellBorder border = CellBorder.none; 129 | 130 | /// padding left 131 | float paddingLeft = 0; 132 | /// padding top 133 | float paddingTop = 0; 134 | /// padding right 135 | float paddingRight = 0; 136 | /// padding bottom 137 | float paddingBottom = 0; 138 | 139 | HaruCMYKColor fillColor = HaruCMYKColor(0, 0, 0, 0); // white 140 | HaruCMYKColor borderColor = HaruCMYKColor(0, 0, 0, 1); // black 141 | } 142 | 143 | /** 144 | * Cell border 145 | */ 146 | enum CellBorder { 147 | none = 0x0, 148 | top = 0x01, 149 | right = 0x02, 150 | bottom = 0x04, 151 | left = 0x08, 152 | all = 0x0F 153 | } 154 | -------------------------------------------------------------------------------- /src/harud/types.d: -------------------------------------------------------------------------------- 1 | /// 2 | module harud.types; 3 | 4 | alias HPDF_HANDLE = void*; 5 | alias HPDF_Doc = HPDF_HANDLE; 6 | alias HPDF_Page = HPDF_HANDLE; 7 | alias HPDF_Pages = HPDF_HANDLE; 8 | alias HPDF_Stream = HPDF_HANDLE; 9 | alias HPDF_Image = HPDF_HANDLE; 10 | alias HPDF_Font = HPDF_HANDLE; 11 | alias HPDF_Outline = HPDF_HANDLE; 12 | alias HPDF_Encoder = HPDF_HANDLE; 13 | alias HPDF_Destination = HPDF_HANDLE; 14 | alias HPDF_XObject = HPDF_HANDLE; 15 | alias HPDF_Annotation = HPDF_HANDLE; 16 | alias HPDF_ExtGState = HPDF_HANDLE; 17 | 18 | /* boolean type (0: False, !0: True) */ 19 | alias HPDF_BOOL = int; 20 | 21 | /** errorNo type (32bit unsigned integer) */ 22 | alias HPDF_STATUS = uint; 23 | 24 | /** charactor-code type (16bit) */ 25 | alias HPDF_CID = ushort; 26 | alias HPDF_UNICODE = ushort; 27 | 28 | /** Point struct */ 29 | struct Point { 30 | /// x coordinate 31 | float x; 32 | /// y coordinate 33 | float y; 34 | } 35 | 36 | /** 37 | * Rectangle 38 | * 39 | * -------------------- 40 | * ^ 41 | * top | +--------+ 42 | * | | | 43 | * bottom | +--------+ 44 | * +--------------> 45 | * left right 46 | * 47 | * -------------------- 48 | */ 49 | struct Rect { 50 | /** 51 | * The x-coordinates of bottom left corner 52 | */ 53 | float left; 54 | /** 55 | * The y-coordinates of bottom left corner 56 | */ 57 | float bottom; 58 | /** 59 | * The x-coordinates of top right corner 60 | */ 61 | float right; 62 | 63 | /** 64 | * The y-coordinates of top right corner 65 | */ 66 | float top; 67 | } 68 | 69 | alias HaruBox = Rect; 70 | 71 | /** 72 | * Datetime attribute in the info dictionary. 73 | */ 74 | struct HaruDate { 75 | int year; 76 | int month; 77 | int day; 78 | int hour; 79 | int minutes; 80 | int seconds; 81 | byte ind; 82 | int offHour; 83 | int offMinutes; 84 | } 85 | 86 | /** 87 | * Info dictionary types 88 | */ 89 | enum HaruInfoType { 90 | /** date-time type parameters */ 91 | creationDate = 0, 92 | modDate, 93 | 94 | /* string type parameters */ 95 | author, 96 | creator, 97 | producer, 98 | title, 99 | subject, 100 | keywords 101 | } 102 | 103 | enum PdfVer { 104 | V12 = 0, 105 | V13, 106 | V14, 107 | V15, 108 | V16, 109 | V17 110 | } 111 | 112 | /** 113 | * Encrypt mode 114 | */ 115 | enum HaruEncryptMode { 116 | /// Use "Revision 2" algorithm. "keyLen" automatically set to 5 (40 bits). 117 | R2 = 2, 118 | /// Use "Revision 3" algorithm. "keyLen" can be 5 (40 bits) to 16 (128bits). 119 | R3 = 3 120 | } 121 | 122 | /** 123 | * Describes a text width 124 | */ 125 | struct TextWidth { 126 | uint numchars; 127 | 128 | /** don't use this value (it may be change in the feature). 129 | use numspace as alternated. */ 130 | uint numwords; 131 | 132 | uint width; 133 | uint numspace; 134 | } 135 | 136 | struct DashMode { 137 | ushort[8] ptn; 138 | uint numPtn; 139 | uint phase; 140 | } 141 | 142 | 143 | /** 144 | * For certain types of drawing operations you may want to adjust (or transform, which is the proper term) the coordinates in some way. 145 | * The part of the graphic state that tracks this is called the current transformation matrix (CTM). 146 | * 147 | * To apply a transformation, you use the cm operator, which takes six operands 148 | * that represent a standard 3x2 matrix: 149 | * 150 | * $(TABLE_ROWS 151 | * * - a 152 | * - b 153 | * - 0 154 | * * - c 155 | * - d 156 | * - 0 157 | * * - x 158 | * - y 159 | * - 1 160 | * ) 161 | * 162 | * Some examples: 163 | * $(TABLE_ROWS 164 | * Translation 165 | * * - 1 166 | * - 0 167 | * - 0 168 | * * - 0 169 | * - 1 170 | * - 0 171 | * * - tx 172 | * - ty 173 | * - 1 174 | * ) 175 | * 176 | * $(TABLE_ROWS 177 | * Rotation 178 | * * - cosQ 179 | * - sinQ 180 | * - 0 181 | * * - -sinQ 182 | * - cosQ 183 | * - 0 184 | * * - 0 185 | * - 0 186 | * - 1 187 | * ) 188 | * 189 | * $(SMALL_TABLE 190 | * transformation | operand 191 | * Translation | 1 0 0 1 tx ty 192 | * Rotation | cosQ sinQ -sinQ cosQ 0 0 193 | * Skew | 1 tanA tan(B) 1 0 0 194 | * ) 195 | * 196 | */ 197 | 198 | struct TransMatrix { 199 | float a; 200 | float b; 201 | float c; 202 | float d; 203 | float x; 204 | float y; 205 | } 206 | 207 | /** 208 | * The color space of the image. 209 | */ 210 | enum ColorSpace { 211 | /** 212 | * 8 bit gray scale image.$(BR) 213 | * The gray scale describes each pixel with one byte. $(BR) 214 | * For each byte, 0X00 is maximum dark, 0XFF maximum light. The size of the 215 | * image data is (width * height) bytes.$(BR) 216 | * The sequence of bytes for an 8-pixel 8-bit image with 2 rows and 4 columns would be: 217 | * ----- 218 | * 1 2 3 4 219 | * 5 6 7 8 220 | * ---- 221 | */ 222 | deviceGray = 0, 223 | 224 | /** 225 | * The RGB color model is an additive color model in which red, green, and 226 | * blue light are added together in various ways to reproduce a broad array 227 | * of colors. $(BR) 228 | * The 24 bit RGB color image describes each pixel with three bytes (Red, 229 | * Green, Blue). $(BR) 230 | * For each byte, 0X00 is maximum dark, 0XFF maximum light. The size of the image data is (width * height * 3) bytes. 231 | * The sequence of bytes for an 8-pixel 24-bit image with 2 rows and 4 columns would be: 232 | * --- 233 | * 1R 1G 1B 2R 2G 2B 3R 3G 3B 4R 4G 4B 234 | * 5R 5G 5B 6R 6G 6B 7R 7G 7B 8R 8G 8B 235 | * --- 236 | */ 237 | deviceRGB, 238 | /** 239 | * The CMYK color model (process color, four color) is a subtractive color 240 | * model, used in color printing, and is also used to describe the printing 241 | * process itself. $(BR) 242 | * The 32 bit CMYK color image describes each pixel with four bytes (Cyan, 243 | * Magenta, Yellow, Black). $(BR) 244 | * The size of the image data is (width * height * 4) bytes. For each byte, 245 | * 0X00 is maximum dark, 0XFF maximum light.$(BR) 246 | * The sequence of bytes for an 8-pixel 32-bit image with 2 rows and 4 columns would be: 247 | * --- 248 | * 1C 1M 1Y 1K 2C 2M 2Y 2K 3C 3M 3Y 3K 4C 4M 4Y 4K 249 | * 5C 5M 5Y 5K 6C 6M 6Y 6K 7C 7M 7Y 7K 8C 8M 8Y 8K 250 | * --- 251 | */ 252 | deviceCMYK, 253 | calGray, 254 | calRGB, 255 | lab, 256 | iccBased, 257 | separation, 258 | deviceN, 259 | indexed, 260 | pattern 261 | } 262 | 263 | struct HaruRGBColor { 264 | float red; 265 | float green; 266 | float blue; 267 | } 268 | 269 | struct HaruCMYKColor { 270 | float cyan; 271 | float magenta; 272 | float yellow; 273 | float key; 274 | } 275 | 276 | /// The line cap style 277 | enum HaruLineCap { 278 | buttEnd = 0, 279 | roundEnd, 280 | projectingScuareEnd, 281 | lineCapEof 282 | } 283 | 284 | /// The line join style 285 | enum HaruLineJoin { 286 | miterJoin = 0, 287 | roundJoin, 288 | bevelJoin, 289 | } 290 | 291 | /// The text rendering mode 292 | enum HaruTextRenderingMode { 293 | fill = 0, 294 | stroke, 295 | fillThenStroke, 296 | invisible, 297 | fillClipping, 298 | strokeClipping, 299 | fillStrokeClipping, 300 | clipping 301 | } 302 | 303 | /// Writing mode 304 | enum HaruWritingMode { 305 | horizontal = 0, 306 | vertical, 307 | } 308 | 309 | /** 310 | * The page layout enum 311 | */ 312 | enum PageLayout { 313 | /// Only one page is displayed. 314 | single = 0, 315 | /// Display the pages in one column. 316 | oneColumn, 317 | /// Display in two columns. Odd page number is displayed left 318 | twoColumnLeft, 319 | /// Display in two columns. Odd page number is displayed right 320 | twoColumnRight, 321 | } 322 | 323 | /** 324 | * Compression mode 325 | */ 326 | enum CompressionMode : uint { 327 | /// No compression. 328 | none = 0x0, 329 | /// Compress the contents stream of the page. 330 | text = 0x01, 331 | /// Compress the streams of the image objects. 332 | image = 0x02, 333 | /// Other stream datas (fonts, cmaps and so on) are compressed. 334 | metadata = 0x04, 335 | /// All stream datas are compressed 336 | all = 0x0F 337 | } 338 | 339 | /** 340 | * PageMode enum 341 | */ 342 | enum PageMode : uint { 343 | /// Display the document with neither outline nor thumbnail. 344 | useNone = 0, 345 | /// Display the document with outline pane. 346 | useOutline, 347 | /// Display the document with thumbnail pane. 348 | useThumbs, 349 | /// Display the document with full screen mode. 350 | fullScreen 351 | } 352 | 353 | enum PageNumStyle { 354 | decimal = 0, 355 | upperRoman, 356 | lowerRoman, 357 | upperLetters, 358 | lowerLetters, 359 | eof 360 | } 361 | 362 | enum DestinationType { 363 | xyz = 0, 364 | fit, 365 | fitH, 366 | fitV, 367 | fitR, 368 | fitB, 369 | fitBh, 370 | fitBv, 371 | eof 372 | } 373 | 374 | enum HaruAnnotType { 375 | textNotes, 376 | link, 377 | sound, 378 | freeText, 379 | stamp, 380 | square, 381 | circle, 382 | strikeOut, 383 | hightlight, 384 | underline, 385 | ink, 386 | fileAttachment, 387 | popup, 388 | _3D 389 | } 390 | 391 | enum HaruAnnotFlgs { 392 | invisible, 393 | hidden, 394 | print, 395 | nozoom, 396 | norotate, 397 | noview, 398 | readonly 399 | } 400 | 401 | enum HaruAnnotHighlightMode { 402 | noHightlight = 0, 403 | invertBox, 404 | invertBorder, 405 | downAppearance, 406 | hightlightModeEof 407 | } 408 | 409 | enum HaruAnnotIcon { 410 | comment = 0, 411 | key, 412 | note, 413 | help, 414 | newParagraph, 415 | paragraph, 416 | insert 417 | } 418 | 419 | // border stype 420 | enum HaruBSSubtype { 421 | solid, 422 | dashed, 423 | beveled, 424 | inset, 425 | underlined 426 | } 427 | 428 | // blend modes 429 | enum HaruBlendMode { 430 | normal, 431 | multiply, 432 | screen, 433 | overlay, 434 | darken, 435 | lighten, 436 | colorDodge, 437 | colorBum, 438 | hardLight, 439 | softLight, 440 | difference, 441 | exclushon 442 | } 443 | 444 | /// slide show 445 | enum HaruTransitionStyle { 446 | wipeRight = 0, 447 | wipeUp, 448 | wipeLeft, 449 | wipeDown, 450 | barnDoorsHorizontalOut, 451 | barnDoorsHorizontalIn, 452 | barnDoorsVerticalOut, 453 | barnDoorsVerticalIn, 454 | boxOut, 455 | boxIn, 456 | blindsHorizontal, 457 | blindsVertical, 458 | dissolve, 459 | glitterRight, 460 | glitterDown, 461 | glittertoplefttobottomright, 462 | replace 463 | } 464 | 465 | enum PageSizes { 466 | letter = 0, 467 | legal, 468 | A3, 469 | A4, 470 | A5, 471 | B4, 472 | B5, 473 | executive, 474 | us4x6, 475 | us4x8, 476 | us5x7, 477 | comm10 478 | } 479 | 480 | enum PageDirection { 481 | portrait = 0, 482 | landscape 483 | } 484 | 485 | enum HaruEncoderType { 486 | singleByte, 487 | doubleByte, 488 | uninitialized, 489 | unknown 490 | } 491 | 492 | /** 493 | * Byte type enum 494 | */ 495 | enum HaruByteType { 496 | single = 0, 497 | lead, 498 | trial, 499 | unknown 500 | } 501 | 502 | /** 503 | * Text alignment 504 | */ 505 | enum HaruTextAlignment { 506 | left = 0, /** The text is aligned to left. */ 507 | right, /** The text is aligned to right. */ 508 | center, /** The text is aligned to center. */ 509 | justify /** Add spaces between the words to justify both left and right side. */ 510 | } 511 | 512 | /** 513 | * Permission flags (only Revision 2 is supported) 514 | */ 515 | enum HaruPermission : uint { 516 | /// user can read the document 517 | read = 0, 518 | /// user can print the document 519 | print = 4, 520 | /// user can add or modify the annotations and form fields of the document 521 | editAll = 8, 522 | /// user can copy the text and the graphics of the document 523 | copy = 16, 524 | /// user can edit the contents of the document other than annotations, form fields 525 | edit = 32 526 | } 527 | 528 | /** 529 | * Graphics mode 530 | * 531 | * Each page object maintains a flag named "graphics mode". 532 | * The graphics mode corresponds to the graphics-object of the PDF specification. 533 | * The graphics mode is changed by invoking particular functions. 534 | * The functions that can be invoked are decided by the value of the graphics mode. 535 | * 536 | */ 537 | enum GMode : ushort { 538 | unknown = 0, 539 | /** 540 | * Allowed operators: 541 | * $(UL 542 | * $(LI General graphic state) 543 | * $(LI Special graphic state) 544 | * $(LI Color) 545 | * $(LI Text state) 546 | * ) 547 | */ 548 | pageDescription = 0x0001, 549 | /** 550 | * Allowed operators: 551 | * $(UL 552 | * $(LI Path construction) 553 | * ) 554 | */ 555 | pathObject = 0x0002, 556 | /** 557 | * Allowed operators: 558 | * $(UL 559 | * $(LI Graphic state) 560 | * $(LI Color) 561 | * $(LI Text state) 562 | * $(LI Text-shadowing) 563 | * $(LI Text-positioning) 564 | * ) 565 | */ 566 | textObject = 0x0004, 567 | 568 | clippingPath = 0x0008, 569 | shading = 0x0010, 570 | inlineImage = 0x0020, 571 | externalObject = 0x0040 572 | } 573 | -------------------------------------------------------------------------------- /src/harud/util.d: -------------------------------------------------------------------------------- 1 | /** 2 | * This module contains some common utilities used by harud 3 | */ 4 | module harud.util; 5 | 6 | import harud.doc : Doc; 7 | import harud.font : Font; 8 | import harud.types : Rect, HaruCMYKColor; 9 | 10 | /** 11 | * Creates a rectangle starting from the top left corner. 12 | * 13 | * Params: 14 | * xLeft = X coordinates of left up corner 15 | * yTop = Y coordinates of left up corner 16 | * width = Width of rectangle 17 | * height = Height of rectangle 18 | * 19 | * Examples: 20 | * -------------------- 21 | * (x, y) 22 | * *----------+ 23 | * | | height 24 | * +----------+ 25 | * width 26 | * -------------------- 27 | */ 28 | Rect createTopLeftRect(float xLeft, float yTop, float width, float height) { 29 | return Rect(xLeft, yTop - height, xLeft + width, yTop); 30 | } 31 | 32 | unittest { 33 | Rect r = createTopLeftRect(25, 500, 150, 50); 34 | assert(r.left == 25); 35 | assert(r.top == 500); 36 | assert(r.right == 25 + 150); 37 | assert(r.bottom == 500 - 50); 38 | } 39 | 40 | /** 41 | * Creates a rectangle with the pdf convention. 42 | * 43 | * When describing a rectangle in PDF syntax, an array of four numbers is used. 44 | * The order of the numbers is: left, bottom, width, height. 45 | * 46 | * 47 | * Params: 48 | * xLeft = X coordinates of left up corner 49 | * yBottom = Y coordinates of left bottom corner 50 | * width = Width of rectangle 51 | * height = Height of rectangle 52 | * 53 | * Examples: 54 | * -------------------- 55 | * width 56 | * +----------+ 57 | * | | height 58 | * *----------+ 59 | * (left, bottom) 60 | * -------------------- 61 | */ 62 | Rect createPdfRect(float xLeft, float yBottom, float width, float height) { 63 | return Rect(xLeft, yBottom, xLeft + width, yBottom + height); 64 | } 65 | 66 | unittest { 67 | Rect r = createPdfRect(25, 200, 150, 50); 68 | assert(r.left == 25); 69 | assert(r.bottom == 200); 70 | assert(r.right == 25 + 150); 71 | assert(r.top == 200 + 50); 72 | } 73 | 74 | Font getFont(Doc pdf, StandardFont font) { 75 | final switch (font) with (StandardFont) { 76 | case courier: 77 | return pdf.getFont("Courier"); 78 | case courierBold: 79 | return pdf.getFont("Courier-Bold"); 80 | case courierOblique: 81 | return pdf.getFont("Courier-Oblique"); 82 | case courierBoldOblique: 83 | return pdf.getFont("Courier-BoldOblique"); 84 | case helvetica: 85 | return pdf.getFont("Helvetica"); 86 | case helveticaBold: 87 | return pdf.getFont("Helvetica-Bold"); 88 | case helveticaOblique: 89 | return pdf.getFont("Helvetica-Oblique"); 90 | case helveticaBoldOblique: 91 | return pdf.getFont("Helvetica-BoldOblique"); 92 | case timesRoman: 93 | return pdf.getFont("Times-Roman"); 94 | case timesBold: 95 | return pdf.getFont("Times-Bold"); 96 | case timesItalic: 97 | return pdf.getFont("Times-Italic"); 98 | case timesBoldItalic: 99 | return pdf.getFont("Times-BoldItalic"); 100 | case symbol: 101 | return pdf.getFont("Symbol"); 102 | case zapfDingbats: 103 | return pdf.getFont("ZapfDingbats"); 104 | 105 | } 106 | } 107 | 108 | enum StandardFont { 109 | courier, 110 | courierBold, 111 | courierOblique, 112 | courierBoldOblique, 113 | helvetica, 114 | helveticaBold, 115 | helveticaOblique, 116 | helveticaBoldOblique, 117 | timesRoman, 118 | timesBold, 119 | timesItalic, 120 | timesBoldItalic, 121 | symbol, 122 | zapfDingbats 123 | } 124 | 125 | enum MaterializeColor { 126 | red 127 | } 128 | 129 | HaruCMYKColor getColor(string c)() { 130 | switch (c) { 131 | case "red": 132 | return HaruCMYKColor(0, 0.73, 0.78, 0.04); 133 | case "pink": 134 | return HaruCMYKColor(0, 0.87, 0.58, 0.09); //#e91e63": 135 | case "purple": 136 | return HaruCMYKColor(0.11, 0.78, 0., 0.31); //#9c27b0": 137 | case "grey": 138 | return HaruCMYKColor(0., 0., 0., 0.38); 139 | case "grey-lighten-5": 140 | return HaruCMYKColor(0., 0., 0., 0.02); 141 | case "grey-lighten-4": 142 | return HaruCMYKColor(0., 0., 0., 0.04); 143 | case "grey-lighten-3": 144 | return HaruCMYKColor(0., 0., 0., 0.07); 145 | case "grey-lighten-2": 146 | return HaruCMYKColor(0., 0., 0., 0.12); 147 | case "grey-lighten-1": 148 | return HaruCMYKColor(0., 0., 0., 0.26); 149 | case "grey-darken-1": 150 | return HaruCMYKColor(0., 0., 0., 0.54); 151 | case "grey-darken-2": 152 | return HaruCMYKColor(0., 0., 0., 0.62); 153 | case "grey-darken-3": 154 | return HaruCMYKColor(0., 0., 0., 0.74); 155 | case "grey-darken-4": 156 | return HaruCMYKColor(0., 0., 0., 0.87); 157 | case "blue": 158 | return HaruCMYKColor(0.86, 0.71, 0.0, 0.05); //#2196F3, 159 | case "blue-lighten-5": 160 | return HaruCMYKColor(0.10, 0.04, 0.0, 0.01); //#E3F2FD, 161 | case "blue-lighten-4": 162 | return HaruCMYKColor(0.25, 0.12, 0.0, 0.02); //#BBDEFB, 163 | case "blue-lighten-3": 164 | return HaruCMYKColor(0.42, 0.19, 0.0, 0.02); //#90CAF9, 165 | case "blue-lighten-2": 166 | return HaruCMYKColor(0.59, 0.26, 0.0, 0.04); //#64B5F6, 167 | case "blue-lighten-1": 168 | return HaruCMYKColor(0.73, 0.33, 0.0, 0.04); //#42A5F5, 169 | case "blue-darken-1": 170 | return HaruCMYKColor(0.87, 0.41, 0.0, 0.10); //#1E88E5, 171 | case "blue-darken-2": 172 | return HaruCMYKColor(0.88, 0.44, 0.0, 0.18); //#1976D2, 173 | case "blue-darken-3": 174 | return HaruCMYKColor(0.89, 0.47, 0.0, 0.25); //#1565C0, 175 | case "blue-darken-4": 176 | return HaruCMYKColor(0.92, 0.56, 0.0, 0.37); //#0D47A1, 177 | case "blue-accent-1": 178 | return HaruCMYKColor(0.49, 0.31, 0.0, 0.0); //#82B1FF, 179 | case "blue-accent-2": 180 | return HaruCMYKColor(0.73, 0.46, 0.0, 0.0); //#448AFF 181 | case "blue-accent-3": 182 | return HaruCMYKColor(0.85, 0.53, 0.0, 0.0); //#2979FF 183 | case "blue-accent-4": 184 | return HaruCMYKColor(0.84, 0.62, 0.0, 0.0); //#2962FF 185 | 186 | default: 187 | assert(false); 188 | } 189 | } 190 | 191 | unittest { 192 | assert(getColor!("red").yellow == cast(float)0.78); 193 | assert(getColor!("grey-darken-2").key == cast(float)0.62); 194 | } 195 | --------------------------------------------------------------------------------