0
|
1 /*--------------------------------------------------------------------------------
|
|
2 * �@�\:
|
|
3 * DocuWorks�����̂��ׂẴy�[�W�Ƀe�L�X�g�A�m�e�[�V������\��t����
|
|
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*>(XDW_COLOR_NONE), 0, NULL); // �w�i����
|
|
57 h, annoation, XDW_ATN_BackColor, XDW_ATYPE_INT, reinterpret_cast<char*>(&color), 0, NULL); // �w�i����
|
|
58 }
|
|
59
|
|
60 return api_result;
|
|
61 }
|
|
62
|
|
63 int main(int argc, char** argv)
|
|
64 {
|
|
65 int api_result = 0;
|
|
66
|
|
67 if (argc != 8) {
|
|
68 fprintf(stderr, "�g�p���@:\n");
|
|
69 fprintf(stderr, "xdwaddatn �����t�@�C���� ���������� X���W Y���W �}�������� �T�C�Y �g�����X�y�A�����g\n");
|
|
70 fprintf(stderr, " ex. : xdwaddatn hoge.xdw searchtext 500 1000 Boooo! 120 1 # �w�i����\n");
|
|
71 fprintf(stderr, " ex. : xdwaddatn hoge.xdw searchtext 500 1000 Boooo! 120 0 # �w�i��\n");
|
|
72 fprintf(stderr, " ex. : xdwaddatn hoge.xdw * 500 1000 Boooo! 120 0 # ���ׂẴy�[�W��\n");
|
|
73 return 0;
|
|
74 }
|
|
75
|
|
76 char in_path[_MAX_PATH];
|
|
77 _fullpath(in_path, argv[1], _MAX_PATH);
|
|
78
|
|
79 // �����n���h�����J��
|
|
80 XDW_DOCUMENT_HANDLE h = NULL;
|
|
81 XDW_OPEN_MODE_EX mode = {
|
|
82 sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE };
|
|
83 api_result = XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode);
|
|
84 if (api_result < 0) {
|
|
85 print_error(api_result);
|
|
86 return 0;
|
|
87 }
|
|
88
|
|
89 // XDW_GetDocumentInformation��p���đ��y�[�W����
|
|
90 XDW_DOCUMENT_INFO info = { sizeof(XDW_DOCUMENT_INFO), 0 };
|
|
91 XDW_GetDocumentInformation(h, &info);
|
|
92 int last_page = info.nPages;
|
|
93
|
|
94 XDW_FOUND_HANDLE pFoundHandle = NULL;
|
|
95
|
|
96
|
|
97 int x = atoi( argv[3] );
|
|
98 int y = atoi( argv[4] );
|
|
99 int sz = atoi( argv[6] );
|
|
100 int tr = atoi( argv[7] ); // �����t���O
|
|
101
|
|
102 // �A�m�e�[�V������\��t����
|
|
103 if ( !strcmp( "*", argv[2] ) ) { // ���ׂẴy�[�W
|
|
104 for (int i = 1; i <= last_page; i++) {
|
|
105 api_result = add_annotation(h, i, x, y, argv[5], &sz, tr);
|
|
106 if (api_result < 0) {
|
|
107 print_error(api_result);
|
|
108 break;
|
|
109 }
|
|
110 }
|
|
111 }
|
|
112 else {
|
|
113 for (int i = 1; i <= last_page; i++) {
|
|
114 api_result = XDW_FindTextInPage( h, i, argv[2], NULL, &pFoundHandle, NULL );
|
|
115 if ( pFoundHandle != NULL ) { // �����q�b�g
|
|
116 api_result = add_annotation(h, i, x, y, argv[5], &sz, tr);
|
|
117 if (api_result < 0) {
|
|
118 print_error(api_result);
|
|
119 break;
|
|
120 }
|
|
121 }
|
|
122 }
|
|
123 }
|
|
124
|
|
125 // �ύX���t�@�C���ɔ��f����
|
|
126 if (api_result >= 0) {
|
|
127 api_result = XDW_SaveDocument(h, NULL);
|
|
128 }
|
|
129
|
|
130 // �����n���h�������
|
|
131 XDW_CloseDocumentHandle(h, NULL);
|
|
132
|
|
133 if (api_result < 0) return 0;
|
|
134
|
|
135 return 1;
|
|
136 }
|