{
memcpy (u8_line_reserve (line, x0, x1, n), s, n);
}
+
+/* Changes the width of LINE to X column widths. If X is longer than LINE's
+ previous width, LINE is extended by appending spaces. If X is shorter than
+ LINE's previous width, LINE is shortened by removing trailing characters. */
+void
+u8_line_set_length (struct u8_line *line, int x)
+{
+ if (x > line->width)
+ {
+ ds_put_byte_multiple (&line->s, ' ', x - line->width);
+ line->width = x;
+ }
+ else if (x < line->width)
+ {
+ struct u8_pos pos;
+
+ u8_line_find_pos (line, x, &pos);
+ ds_truncate (&line->s, pos.ofs0);
+ line->width = pos.x0;
+ if (x > line->width)
+ {
+ ds_put_byte_multiple (&line->s, '?', x - line->width);
+ line->width = x;
+ }
+ }
+}
void u8_line_clear (struct u8_line *);
char *u8_line_reserve (struct u8_line *, int x0, int x1, int n);
void u8_line_put (struct u8_line *, int x0, int x1, const char *s, int n);
+void u8_line_set_length (struct u8_line *, int x);
#endif /* libpspp/u8-line.h */
a->y = 1;
}
+
+void
+ascii_test_set_length (struct output_driver *driver, int y, int length)
+{
+ struct ascii_driver *a = ascii_driver_cast (driver);
+
+ if (a->file == NULL && !ascii_open_page (a))
+ return;
+
+ if (y < 0 || y >= a->length)
+ return;
+ u8_line_set_length (&a->lines[y], length);
+}
\f
/* ascii_close_page () and support routines. */
/* PSPP - a program for statistical analysis.
- Copyright (C) 2011 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
void ascii_test_write (struct output_driver *,
const char *s, int x, int y, unsigned int options);
+void ascii_test_set_length (struct output_driver *, int y, int length);
#endif /* ascii.h */
])
AT_CLEANUP
+AT_SETUP([ASCII driver u8_line_set_length])
+AT_KEYWORDS([render rendering])
+AT_DATA([input], [dnl
+0 0 0 àéî
+0 1 0 àéî
+0 2 0 àéî
+0 3 0 àéî
+0 4 0 àéî
+set-length 0 4
+set-length 1 3
+set-length 2 2
+set-length 3 1
+set-length 4 0
+
+0 6 0 あい
+0 7 0 あい
+0 8 0 あい
+0 9 0 あい
+0 10 0 あい
+0 11 0 あい
+set-length 6 5
+set-length 7 4
+set-length 8 3
+set-length 9 2
+set-length 10 1
+set-length 11 0
+])
+AT_CHECK([render-test --draw-mode input], [0], [dnl
+àéî
+àéî
+àé
+à
+
+あい
+あい
+あ?
+あ
+?
+])
+AT_CLEANUP
+
AT_SETUP([ASCII driver Unicode box characters])
AT_KEYWORDS([render rendering])
AT_DATA([input], [3 3
/* PSPP - a program for statistical analysis.
- Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
while (fgets (buffer, sizeof buffer, stream))
{
char text[sizeof buffer];
+ int length;
int emph;
int x, y;
if (strchr ("#\r\n", buffer[0]))
continue;
- if (sscanf (buffer, "%d %d %d %[^\n]", &x, &y, &emph, text) != 4)
+ if (sscanf (buffer, "%d %d %d %[^\n]", &x, &y, &emph, text) == 4)
+ ascii_test_write (ascii_driver, text, x, y, emph ? TAB_EMPH : 0);
+ else if (sscanf (buffer, "set-length %d %d", &y, &length) == 2)
+ ascii_test_set_length (ascii_driver, y, length);
+ else
error (1, 0, "line %d has invalid format", line);
-
- ascii_test_write (ascii_driver, text, x, y, emph ? TAB_EMPH : 0);
}
}