Mercurial > mercurial > hgweb_xdwtools.cgi
comparison xdwaddpage2.cpp @ 5:55f10a3aacb0
add xdwaddpage2.
| author | pyon@macmini |
|---|---|
| date | Sun, 29 Oct 2017 14:48:51 +0900 |
| parents | |
| children | 8de5b1bd9506 |
comparison
equal
deleted
inserted
replaced
| 4:af8f454d20ed | 5:55f10a3aacb0 |
|---|---|
| 1 /* Makefile | |
| 2 debug: xdwaddpage2.c | |
| 3 #cls | |
| 4 gcc -g -O0 -I. xdwaddpage2.c xdwapi.lib | |
| 5 | |
| 6 release: xdwaddpage2.c | |
| 7 gcc -I. xdwaddpage2.c xdwapi.lib -static -o xdwaddpage2.exe | |
| 8 strip xdwaddpage2.exe | |
| 9 | |
| 10 clean: | |
| 11 rm -rf tempXXXX | |
| 12 */ | |
| 13 | |
| 14 #include <stdio.h> | |
| 15 #include <string.h> | |
| 16 #include <stdlib.h> | |
| 17 #include <time.h> | |
| 18 #include <io.h> | |
| 19 #include <windows.h> | |
| 20 #include <xdw_api.h> | |
| 21 #include <xdwapian.h> | |
| 22 | |
| 23 | |
| 24 void print_error( int code ) { | |
| 25 fprintf( stderr, "Error code : %d\n", code ); | |
| 26 switch ( code ) { | |
| 27 case XDW_E_NOT_INSTALLED: | |
| 28 fprintf( stderr, "DocuWorksがインストールされていません。" ); | |
| 29 break; | |
| 30 case XDW_E_FILE_NOT_FOUND: | |
| 31 fprintf( stderr, "指定されたファイルが見つかりません。" ); | |
| 32 break; | |
| 33 case XDW_E_FILE_EXISTS: | |
| 34 fprintf( stderr, "指定されたファイルはすでに存在します。" ); | |
| 35 break; | |
| 36 case XDW_E_ACCESSDENIED: | |
| 37 case XDW_E_INVALID_NAME: | |
| 38 case XDW_E_BAD_NETPATH: | |
| 39 fprintf( stderr, "指定されたファイルを開くことができません。" ); | |
| 40 break; | |
| 41 case XDW_E_BAD_FORMAT: | |
| 42 fprintf( stderr, "指定されたファイルは正しいフォーマットではありません。" ); | |
| 43 break; | |
| 44 case XDW_E_INVALID_ACCESS: | |
| 45 fprintf( stderr, "指定された操作をする権利がありません。" ); | |
| 46 break; | |
| 47 default: | |
| 48 fprintf( stderr, "エラーが発生しました。" ); | |
| 49 break; | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 void print_now( char const *msg ) { | |
| 54 time_t now = time( NULL ); | |
| 55 struct tm *ts = localtime( &now ); | |
| 56 | |
| 57 char buf[80]; | |
| 58 strftime( buf, sizeof( buf ), "%H:%M:%S %Z", ts ); | |
| 59 printf( "%s\t%s\n", buf, msg ); | |
| 60 } | |
| 61 | |
| 62 int add_annotation( XDW_DOCUMENT_HANDLE h, int page, int x, int y, char* string, int* sz, int tr ) | |
| 63 { | |
| 64 // テキストアノテーションを作成する | |
| 65 XDW_ANNOTATION_HANDLE annoation; | |
| 66 int api_result = XDW_AddAnnotation( h, XDW_AID_TEXT, page, x, y, NULL, &annoation, NULL ); | |
| 67 if ( api_result < 0 ) return api_result; | |
| 68 | |
| 69 // 作成したアノテーションに文字列を設定する | |
| 70 api_result = XDW_SetAnnotationAttribute( h, annoation, XDW_ATN_Text, XDW_ATYPE_STRING, string, 0, NULL ); // 文字テキスト | |
| 71 api_result = XDW_SetAnnotationAttribute( h, annoation, XDW_ATN_FontSize, XDW_ATYPE_INT, reinterpret_cast<char*>(sz), 0, NULL ); // フォントサイズ | |
| 72 if ( tr ) { | |
| 73 int color = XDW_COLOR_NONE; | |
| 74 api_result = XDW_SetAnnotationAttribute( h, annoation, XDW_ATN_BackColor, XDW_ATYPE_INT, reinterpret_cast<char*>(&color), 0, NULL ); | |
| 75 } | |
| 76 | |
| 77 return api_result; | |
| 78 } | |
| 79 | |
| 80 int main( int argc, char* argv[] ) { | |
| 81 | |
| 82 /* オプションの解析 */ | |
| 83 char prog[128]; | |
| 84 strcpy( prog, argv[0] ); | |
| 85 | |
| 86 int pnow = 0; | |
| 87 int pstart = 0; | |
| 88 int pleft = 0; | |
| 89 char c; | |
| 90 while ( --argc > 0 && ( *++argv )[0] == '-' ) { | |
| 91 while ( c = *++argv[0] ) { | |
| 92 switch ( c ) { | |
| 93 case 'v': | |
| 94 pnow = 1; | |
| 95 print_now( "start." ); | |
| 96 break; | |
| 97 case 'l': | |
| 98 pleft = 1; | |
| 99 break; | |
| 100 case 's': | |
| 101 pstart = 1; | |
| 102 break; | |
| 103 default: | |
| 104 fprintf( stderr, "error: illegal option '%c'.\n", c ); | |
| 105 exit( 1 ); | |
| 106 } | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 int sp = 1; | |
| 111 char in_path[ _MAX_PATH ]; | |
| 112 if ( argc == 1 ) { | |
| 113 _fullpath( in_path, argv[0], _MAX_PATH ); | |
| 114 } else if ( argc == 2 ) { | |
| 115 if ( pstart == 1 ) { | |
| 116 sp = atoi( argv[0] ); | |
| 117 _fullpath( in_path, argv[1], _MAX_PATH ); | |
| 118 } | |
| 119 } else { | |
| 120 fprintf( stderr, "%s infile\n", prog ); | |
| 121 fprintf( stderr, "%s -l infile\n", prog ); | |
| 122 fprintf( stderr, "%s -s S infile\n", prog ); | |
| 123 fprintf( stderr, "%s -v infile\n", prog ); | |
| 124 exit( 1 ); | |
| 125 } | |
| 126 | |
| 127 /* 本処理 */ | |
| 128 if ( pnow ) print_now( "adding pages." ); | |
| 129 | |
| 130 int api_result = 0; | |
| 131 | |
| 132 XDW_DOCUMENT_HANDLE h = NULL; // 文書ハンドルを開く | |
| 133 XDW_OPEN_MODE_EX mode = { sizeof( XDW_OPEN_MODE_EX ), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE }; | |
| 134 api_result = XDW_OpenDocumentHandle( in_path, &h, (XDW_OPEN_MODE*)&mode ); | |
| 135 if ( api_result < 0 ) { | |
| 136 print_error( api_result ); | |
| 137 return 0; | |
| 138 } | |
| 139 | |
| 140 XDW_DOCUMENT_INFO info = { sizeof( XDW_DOCUMENT_INFO ), 0 }; // XDW_GetDocumentInformationを用いて総ページ数を得る | |
| 141 XDW_GetDocumentInformation( h, &info ); | |
| 142 int last_page = info.nPages; | |
| 143 | |
| 144 int sz = 80; // 文字サイズ | |
| 145 int tr = 1; // 透明フラグ | |
| 146 char pagenum[18]; | |
| 147 | |
| 148 // アノテーションを貼り付ける | |
| 149 for ( int p = 0; p < last_page; p++ ) { | |
| 150 sprintf( pagenum, "%05d-%05d-%05d", p + sp, p + 1,last_page ); | |
| 151 if ( pleft == 1 ) | |
| 152 api_result = add_annotation( h, p + 1, 1700, 5600, pagenum, &sz, tr ); // 左上 | |
| 153 api_result = add_annotation( h, p + 1, 17500, 28500, pagenum, &sz, tr ); // 右下 | |
| 154 if ( api_result < 0 ) { | |
| 155 print_error( api_result ); | |
| 156 break; | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 if ( api_result >= 0 ) // 変更をファイルに反映する | |
| 161 api_result = XDW_SaveDocument( h, NULL ); | |
| 162 | |
| 163 XDW_CloseDocumentHandle( h, NULL ); // 文書ハンドルを閉じる | |
| 164 | |
| 165 if ( pnow ) print_now( "done." ); | |
| 166 return 0; | |
| 167 } | |
| 168 |
