comparison xdwaddpage.cpp @ 0:c1ebc8b218f2

xdwtools source code.
author pyon@macmini
date Sun, 29 Mar 2015 18:11:58 +0900 (2015-03-29)
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c1ebc8b218f2
1 /*--------------------------------------------------------------------------------
2 * �@�\:
3 * DocuWorks�����Ƀy�[�W�ԍ����ӂ�
4 *-------------------------------------------------------------------------------*/
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <windows.h>
9
10 #include <xdw_api.h>
11 #include <xdwapian.h>
12
13 void print_error(int code)
14 {
15 switch (code) {
16 case XDW_E_NOT_INSTALLED:
17 fprintf(stderr, "DocuWorks���C���X�g�[������Ă��܂���B");
18 break;
19 case XDW_E_FILE_NOT_FOUND:
20 fprintf(stderr, "�w�肳�ꂽ�t�@�C�������‚���܂���B");
21 break;
22 case XDW_E_ACCESSDENIED:
23 case XDW_E_INVALID_NAME:
24 case XDW_E_BAD_NETPATH:
25 fprintf(stderr, "�w�肳�ꂽ�t�@�C�����J�����Ƃ��ł��܂���B");
26 break;
27 case XDW_E_BAD_FORMAT:
28 fprintf(stderr, "�w�肳�ꂽ�t�@�C���͐������t�H�[�}�b�g�ł͂���܂���B");
29 break;
30 case XDW_E_INVALID_ACCESS:
31 fprintf(stderr, "�w�肳�ꂽ��������錠��������܂���B");
32 break;
33 default:
34 fprintf(stderr, "�G���[�R�[�h:%x\n", code);
35 fprintf(stderr, "�G���[���������܂����B");
36 break;
37 }
38 }
39
40 int add_annotation(XDW_DOCUMENT_HANDLE h, int page, int x, int y, char* string, int* sz, int tr)
41 {
42 // �e�L�X�g�A�m�e�[�V�������쐬����
43 XDW_ANNOTATION_HANDLE annoation;
44 int api_result = XDW_AddAnnotation(
45 h, XDW_AID_TEXT, page, x, y, NULL, &annoation, NULL);
46 if (api_result < 0) return api_result;
47
48 // �쐬�����A�m�e�[�V�����ɕ������ݒ肷��
49 api_result = XDW_SetAnnotationAttribute(
50 h, annoation, XDW_ATN_Text, XDW_ATYPE_STRING, string, 0, NULL); // �����e�L�X�g
51 api_result = XDW_SetAnnotationAttribute(
52 h, annoation, XDW_ATN_FontSize, XDW_ATYPE_INT, reinterpret_cast<char*>(sz), 0, NULL); // �t�H���g�T�C�Y
53 if ( tr ) {
54 int color = XDW_COLOR_NONE;
55 api_result = XDW_SetAnnotationAttribute(
56 h, annoation, XDW_ATN_BackColor, XDW_ATYPE_INT, reinterpret_cast<char*>(&color), 0, NULL);
57 }
58
59 return api_result;
60 }
61
62 int main(int argc, char** argv)
63 {
64 int api_result = 0;
65
66 if (argc != 2) {
67 fprintf(stderr, "�g�p���@:\n");
68 fprintf(stderr, "xdwaddpage �����t�@�C����\n");
69 return 0;
70 }
71
72 char in_path[_MAX_PATH];
73 _fullpath(in_path, argv[1], _MAX_PATH);
74
75 // �����n���h�����J��
76 XDW_DOCUMENT_HANDLE h = NULL;
77 XDW_OPEN_MODE_EX mode = {
78 sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE };
79 api_result = XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode);
80 if (api_result < 0) {
81 print_error(api_result);
82 return 0;
83 }
84
85 // XDW_GetDocumentInformation��p���đ��y�[�W���𓾂�
86 XDW_DOCUMENT_INFO info = { sizeof(XDW_DOCUMENT_INFO), 0 };
87 XDW_GetDocumentInformation(h, &info);
88 int last_page = info.nPages;
89
90 int sz = 80; // �����T�C�Y
91 int tr = 1; // �����t���O
92 char pagenum[12];
93
94 // �A�m�e�[�V������\��t����
95 for (int i = 1; i <= last_page; i++) {
96 sprintf( pagenum, "%05d-%05d", i, last_page );
97 //api_result = add_annotation( h, i, 1700, 5600, pagenum, &sz, tr ); // ����
98 api_result = add_annotation( h, i, 18500, 28500, pagenum, &sz, tr ); // �E��
99 if (api_result < 0) {
100 print_error(api_result);
101 break;
102 }
103 }
104
105 // �ύX���t�@�C���ɔ��f����
106 if (api_result >= 0) {
107 api_result = XDW_SaveDocument(h, NULL);
108 }
109
110 // �����n���h����‚���
111 XDW_CloseDocumentHandle(h, NULL);
112
113 if (api_result < 0) return 0;
114
115 return 1;
116 }