1
2#include <stdio.h>
3#include <stdlib.h>
4#include <libdk4app/dk4app.h>
5#include <libdk4pppt/dk4pppt.h>
6#include <libdk4base/dk4vers.h>
7#include <libdk4app/dk4aopt.h>
8#include <libdk4lat/dk4uc2l.h>
9#include <libdk4lata/dk4uc2la.h>
10
11
12$!trace-include
13
14
15
16/**	Text keywords, no localized.
17*/
18static const	dkChar * const		testpppt_kwnl[] = {
19$!string-table	macro=dkT
20#
21#	0	Program group name
22#
23dktools
24#
25#	1	Help file name
26#
27testpppt.txt
28$!end
29};
30
31
32
33/**	Help text.
34*/
35static const	dkChar * const		testpppt_help[] = {
36$!string-table	macro=dkT
37
38Test PPPT library.
39
40testpppt [options]
41
42Options:
43-R			Reset (ignore preferences).
44-l <string>		Output language and options.
45
46$!end
47};
48
49
50
51/**	Options recognized by the program.
52*/
53static const	dk4_option_specification_t	testpppt_options[] = {
54	{ dkT('R'),	dkT("reset"),		DK4_OPT_ARG_NONE },
55	{ dkT('l'),	dkT("language"),	DK4_OPT_ARG_STRING }
56};
57
58
59
60/**	License terms.
61*/
62static const	dkChar * const		testpppt_license[] = {
63$!string-table	macro=dkT
64List of license terms.
65$!end
66};
67
68
69
70/**	Application structure.
71*/
72static	dk4_app_t	*app = NULL;
73
74
75
76/**	Unicode to LaTeX conversion structure.
77*/
78static	dk4_uc2l_t	*uc2l	= NULL;
79
80
81
82/**	Number of elements in testpppt_options array.
83*/
84static const size_t	 sz_testpppt_options =
85sizeof(testpppt_options)/sizeof(dk4_option_specification_t);
86
87
88
89/**	Exit status code.
90*/
91static	int			 exval	= EXIT_FAILURE;
92
93
94
95static
96void
97triangle_path(
98	dk4_pppt_t	*ppppt,
99	double		 x,
100	double		 y,
101	double		 w,
102	double		 h,
103	int			*backptr,
104	dk4_er_t	*erp
105)
106{
107	dk4pppt_newpath_moveto(ppppt, x, y, NULL, backptr, erp);
108	dk4pppt_lineto(ppppt, x+w, y, NULL, backptr, erp);
109	dk4pppt_lineto(ppppt, x+w, y+h, NULL, backptr, erp);
110	dk4pppt_closepath(ppppt, backptr, erp);
111}
112
113
114static dk4_pppt_driver_t	driver	= DK4_PPPT_DR_PGF;
115static int					drflags	= 0;
116static int					isdoc	= 1;
117static int					acol	= 1;
118
119static
120void
121run_normally(void)
122{
123	dk4_pppt_t		*ppppt	= NULL;
124	int				 res	= 0;
125	int				 back	= 0;
126	int				 imgfl	= 0;
127	$? "+ run_normally"
128	if (DK4_PPPT_DR_EPS_TEX == driver) {
129		isdoc	=  0;
130		drflags |= DK4_GRA_DOC_FLAG_EPS;
131		drflags |= DK4_GRA_DOC_FLAG_PS_DSC;
132		drflags |= DK4_GRA_DOC_FLAG_PS2;
133	}
134
135	if (0 != acol) {
136		imgfl |= DK4_GRA_IMG_FLAG_COLOR;
137	}
138	imgfl |= DK4_GRA_IMG_FLAG_INTERPOLATION;
139	imgfl |= DK4_GRA_IMG_FLAG_LZW;
140	imgfl |= DK4_GRA_IMG_FLAG_DCT;
141	imgfl |= DK4_GRA_IMG_FLAG_DCT_INTERPOLATION;
142	imgfl |= DK4_GRA_IMG_FLAG_ANALYZE_BPC;
143	imgfl |= DK4_GRA_IMG_FLAG_ANALYZE_COLOR;
144	imgfl |= DK4_GRA_IMG_FLAG_ANALYZE_ALPHA;
145	ppppt = dk4pppt_open(
146		dkT("testpppt.tex"), driver, isdoc, drflags, 400, 300, NULL
147	);
148	if (NULL != ppppt) {		$? ". pppt open"
149		back = 1;
150		dk4pppt_set_fill_rgb(ppppt, 0.8, 0.0, 0.0, &back, NULL);
151		dk4pppt_set_stroke_rgb(ppppt, 0.0, 0.0, 0.0, &back, NULL);
152		dk4pppt_set_line_width(ppppt, 0.9, &back, NULL);
153		dk4pppt_set_line_style(ppppt, DK4_GRA_LS_SOLID, 0.0, &back, NULL);
154		dk4pppt_set_line_cap(ppppt, DK4_GRA_LC_ROUNDED, &back, NULL);
155		dk4pppt_set_line_join(ppppt, DK4_GRA_LJ_MITERED, 3.0, &back, NULL);
156		if (0 != dk4pppt_can_fill_and_stroke(ppppt)) {
157			$? ". can fill and stroke"
158			dk4pppt_prepare_fill_and_stroke(ppppt, &back, NULL);
159			triangle_path(ppppt, 100.0, 100.0, 100.0, 100.0, &back, NULL);
160			dk4pppt_fill_and_stroke(ppppt, &back, NULL);
161		}
162		else {
163			$? ". can not fill and stroke"
164			dk4pppt_prepare_fill(ppppt, &back, NULL);
165			triangle_path(ppppt, 100.0, 100.0, 100.0, 100.0, &back, NULL);
166			dk4pppt_fill(ppppt, &back, NULL);
167
168			dk4pppt_prepare_stroke(ppppt, &back, NULL);
169			triangle_path(ppppt, 100.0, 100.0, 100.0, 100.0, &back, NULL);
170			dk4pppt_stroke(ppppt, &back, NULL);
171		}
172		/*	Set text color
173		*/
174		dk4pppt_set_fill_rgb(ppppt, 0.0, 0.0, 0.0, &back, NULL);
175		dk4pppt_special_text(
176			ppppt,
177			140.0, 150.0, 30.0,
178			"\\(c=\\sqrt{a^2+b^2}\\)",
179			"\\color{blue!50!black}",
180			DK4_TEXT_ALIGN_H_RIGHT, DK4_TEXT_ALIGN_V_BASELINE,
181			0, 12.0, 0,
182			(DK4_GRA_TEXT_FLAG_WHITE_BOX | DK4_GRA_TEXT_FLAG_OVAL_BOX),
183			&back, NULL
184		);
185		dk4pppt_special_text(
186			ppppt,
187			150.0, 90.0, 0.0,
188			"\\(a\\)",
189			NULL,
190			DK4_TEXT_ALIGN_H_CENTERED, DK4_TEXT_ALIGN_V_TOP,
191			0, 12.0, 0, 0, &back, NULL
192		);
193		dk4pppt_special_text(
194			ppppt,
195			210.0, 150.0, 0.0,
196			"\\(b\\)",
197			NULL,
198			DK4_TEXT_ALIGN_H_LEFT, DK4_TEXT_ALIGN_V_CENTERED,
199			0, 12.0, 0, 0, &back, NULL
200		);
201
202		dk4pppt_simple_text(
203			ppppt,
204			100.0, 220.0, 30.0,
205			dkT("Test"), NULL, dk4app_get_encoding(app),
206			DK4_TEXT_ALIGN_H_LEFT, DK4_TEXT_ALIGN_V_BASELINE,
207			0, 18.0, 1, uc2l, 0, &back, NULL
208		);
209
210		dk4pppt_set_fill_rgb(ppppt, 0.8, 0.8, 0.8, &back, NULL);
211		dk4pppt_set_stroke_rgb(ppppt, 0.0, 0.0, 1.0, &back, NULL);
212
213		dk4pppt_prepare_fill(ppppt, &back, NULL);
214		triangle_path(ppppt, 250.0, 100.0, 100.0, 100.0, &back, NULL);
215		dk4pppt_fill(ppppt, &back, NULL);
216
217		dk4pppt_set_gs_for_pattern_only(ppppt, 1, NULL);
218		dk4pppt_prepare_fill(ppppt, &back, NULL);
219		dk4pppt_prepare_stroke(ppppt, &back, NULL);
220		dk4pppt_gsave(ppppt, &back, NULL);
221		triangle_path(ppppt, 250.0, 100.0, 100.0, 100.0, &back, NULL);
222		dk4pppt_clip(ppppt, &back, NULL);
223		dk4pppt_set_pattern_line_width(ppppt, 0.45);
224		dk4pppt_pattern(
225			ppppt,
226			250.0, 350.0, 100.0, 200.0, DK4_GRA_PATTERN_SMALL_FISH_SCALES,
227			&back, NULL
228		);
229		dk4pppt_grestore(ppppt, &back, NULL);
230
231		dk4pppt_prepare_stroke(ppppt, &back, NULL);
232		triangle_path(ppppt, 250.0, 100.0, 100.0, 100.0, &back, NULL);
233		dk4pppt_stroke(ppppt, &back, NULL);
234
235		dk4pppt_set_fill_rgb(ppppt, 0.8, 0.8, 1.0, &back, NULL);
236		dk4pppt_set_stroke_rgb(ppppt, 0.5, 0.0, 0.0, &back, NULL);
237
238		if (0 != dk4pppt_can_fill_and_stroke(ppppt)) {
239			dk4pppt_prepare_fill_and_stroke(ppppt, &back, NULL);
240			dk4pppt_ellipse(ppppt, 350.0, 250.0, 50.0, 25.0, 30.0, NULL, &back, NULL);
241			dk4pppt_fill_and_stroke(ppppt, &back, NULL);
242		}
243		else {
244			dk4pppt_prepare_fill(ppppt, &back, NULL);
245			dk4pppt_ellipse(ppppt, 350.0, 250.0, 50.0, 25.0, 30.0, NULL, &back, NULL);
246			dk4pppt_fill(ppppt, &back, NULL);
247			dk4pppt_prepare_stroke(ppppt, &back, NULL);
248			dk4pppt_ellipse(ppppt, 350.0, 250.0, 50.0, 25.0, 30.0, NULL, &back, NULL);
249			dk4pppt_stroke(ppppt, &back, NULL);
250		}
251
252		dk4pppt_image(
253			ppppt,
254			220.0, 280.0, 220.0, 280.0,
255			dkT("../test-data/png/fbt.png"),
256			0, NULL,
257#if	0
258			1, 1, 1, 0, 0, 1, 1, 1, acol, 1, 1, 1, 0,
259#endif
260			imgfl, NULL, &back, NULL
261		);
262
263		dk4pppt_image(
264			ppppt,
265			220.0, 280.0, 120.0, 180.0,
266			dkT("../test-data/png/fbt.png"),
267			0, NULL,
268#if	0
269			1, 1, 1, 0, 0, 1, 1, 1, acol, 1, 1, 1, 0,
270#endif
271			imgfl, NULL, &back, NULL
272		);
273
274		if (DK4_PPPT_DR_PGF != ppppt->dr) {
275			dk4pppt_image(
276				ppppt,
277				160.0, 190.0, 110.0, 140.0,
278				dkT("../test-data/netpbm/testimg-rgb-alpha.pam"),
279				0, NULL,
280#if	0
281				1, 1, 1, 0, 0, 1, 1, 1, acol, 1, 1, 1, 0,
282#endif
283				imgfl, NULL, &back, NULL
284			);
285		}
286#if	0
287		dk4pppt_doc_preamble_line(
288			ppppt,
289			"\\usepackage{mathptmx}",
290			DK4_GRA_PREAMBLE_FONT, &back, NULL
291		);
292		dk4pppt_doc_preamble_line(
293			ppppt,
294			"\\usepackage{microtype}",
295			DK4_GRA_PREAMBLE_PACKAGE, &back, NULL
296		);
297#endif
298		dk4pppt_doc_preamble_line(
299			ppppt,
300			"\\DeclareMathOperator{\\intd}{\\text{d}}",
301			DK4_GRA_PREAMBLE_OTHER, &back, NULL
302		);
303		$? ". going to write output"
304		res = dk4pppt_write_and_close(ppppt, NULL);
305		$? ". output written"
306		if (0 != res) {
307			exval = EXIT_SUCCESS;
308		}
309		ppppt = NULL;
310	}
311
312	$? "- run_normally"
313	if (NULL != ppppt) {
314		dk4pppt_close(ppppt);
315	}
316}
317
318
319
320/**	The main function.
321	@param	argc	Number of command line arguments.
322	@param	argv	Command line arguments array.
323	@return	EXIT_SUCCESS on success, EXIT_FAILURE on error.
324*/
325#if	DK4_CHAR_SIZE > 1
326int
327wmain(int argc, wchar_t *argv[])
328#else
329int
330main(int argc, char *argv[])
331#endif
332{
333	$!trace-init testpppt.deb
334	$? "+ main"
335	app = dk4app_open_cmd(
336		argc, argv, testpppt_options, sz_testpppt_options,
337		testpppt_kwnl[0], DKT_VERSION_DK, testpppt_kwnl[1],
338		testpppt_help, testpppt_license
339	);
340	if (NULL != app) {
341		if (0 != dk4app_can_run_normally(app)) {
342			uc2l = dk4uc2l_open_from_app_ex1(app, 1);
343			if (NULL != uc2l) {
344				run_normally();
345				dk4uc2l_close(uc2l);
346				uc2l = NULL;
347			}
348		}
349		else {
350			if (0 != dk4app_help_version_license(app)) {
351				exval = EXIT_SUCCESS;
352			}
353		}
354		dk4app_close(app);
355	}
356	else {
357	}
358	$? "- main %d", exval
359	$!trace-end
360	return exval;
361}
362
363/* vim: set ai sw=4 ts=4 : */
364
365