summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/mocks.c17
-rw-r--r--test/olducsinit.c22
-rw-r--r--test/ucsinit.c22
3 files changed, 40 insertions, 21 deletions
diff --git a/test/mocks.c b/test/mocks.c
index 132e8ac..5edf0da 100644
--- a/test/mocks.c
+++ b/test/mocks.c
@@ -363,6 +363,7 @@ os_error *xfont_scan_string (font_f font, char const *s,
/* Consume up to length bytes of input */
while (length > 0) {
uint32_t c = 0, i;
+ int cwidth;
for (i = 0; i < advance; i++) {
c |= s[i] << (advance - i - 1);
}
@@ -374,7 +375,16 @@ os_error *xfont_scan_string (font_f font, char const *s,
break;
/* Just scale font size to millipoints and add on the width */
- width += ((h->fonts[font].xsize * 1000) >> 4);
+ cwidth = ((h->fonts[font].xsize * 1000) >> 4);
+ if ((flags & font_RETURN_CARET_POS) && x > 0 &&
+ (width + cwidth/2) > x) {
+ /* Split point is less than half way through
+ * this character: exclude it */
+ s -= advance;
+ length += advance;
+ break;
+ }
+ width += cwidth;
//XXX: how is negative x meant to work?
if (x > 0 && width > x)
break;
@@ -391,10 +401,11 @@ os_error *xfont_scan_string (font_f font, char const *s,
*x_out = width;
if (y_out != NULL)
*y_out = (h->fonts[font].ysize * 1000) >> 4;
+ if (split_point != NULL)
+ *split_point = (char *) s;
(void) y;
(void) trfm;
- (void) split_point;
(void) num_split_chars;
return NULL;
@@ -422,7 +433,7 @@ os_error *xfont_switch_output_to_buffer (font_output_flags flags,
os_error *xfont_enumerate_characters (font_f font, int character,
int *next_character, int *internal_character_code)
{
- static int extchars[] = { 0x20, 0x21, 0x30, 0x31, 0x40, -1 };
+ static int extchars[] = { 0x20, 0x21, 0x30, 0x31, 0xa0, -1 };
static int intchars[] = { -1, 1, 2, -1, 3, 4 };
int index;
diff --git a/test/olducsinit.c b/test/olducsinit.c
index ea1109d..1d5462b 100644
--- a/test/olducsinit.c
+++ b/test/olducsinit.c
@@ -72,21 +72,25 @@ int main(int argc, const char **argv)
assert(0 == uline_position);
assert(0 == uline_thickness);
- assert(rufl_OK == rufl_width("Corpus", rufl_WEIGHT_500, 10,
+ assert(rufl_OK == rufl_width("Corpus", rufl_WEIGHT_500, 160,
(const uint8_t *) "!\xc2\xa0", 3, &width));
- assert(2 == width);
+ assert(50 == width);
- assert(rufl_OK == rufl_x_to_offset("Homerton", rufl_WEIGHT_500, 10,
- (const uint8_t *) "!\xc2\xa0", 3, 1,
+ /* Place caret after first character */
+ assert(rufl_OK == rufl_x_to_offset("Homerton", rufl_WEIGHT_500, 160,
+ (const uint8_t *) "!\xc2\xa0", 3, 25,
&offset, &x));
assert(1 == offset);
- assert(1 == x);
+ assert(25 == x);
- assert(rufl_OK == rufl_split("Trinity", rufl_WEIGHT_500, 10,
- (const uint8_t *) "!\xc2\xa0", 3, 1,
+ /* Attempt to split after first character. As the split point is
+ * coincident with the start of the second character, however,
+ * the split point is placed after it. */
+ assert(rufl_OK == rufl_split("Trinity", rufl_WEIGHT_500, 160,
+ (const uint8_t *) "!\xc2\xa0", 3, 25,
&offset, &x));
- assert(1 == offset);
- assert(1 == x);
+ assert(3 == offset);
+ assert(50 == x);
rufl_dump_state(true);
diff --git a/test/ucsinit.c b/test/ucsinit.c
index 7439030..44f70cb 100644
--- a/test/ucsinit.c
+++ b/test/ucsinit.c
@@ -72,21 +72,25 @@ int main(int argc, const char **argv)
assert(0 == uline_position);
assert(0 == uline_thickness);
- assert(rufl_OK == rufl_width("Corpus", rufl_WEIGHT_500, 10,
+ assert(rufl_OK == rufl_width("Corpus", rufl_WEIGHT_500, 160,
(const uint8_t *) "!\xc2\xa0", 3, &width));
- assert(2 == width);
+ assert(50 == width);
- assert(rufl_OK == rufl_x_to_offset("Homerton", rufl_WEIGHT_500, 10,
- (const uint8_t *) "!\xc2\xa0", 3, 1,
+ /* Place caret after first character */
+ assert(rufl_OK == rufl_x_to_offset("Homerton", rufl_WEIGHT_500, 160,
+ (const uint8_t *) "!\xc2\xa0", 3, 25,
&offset, &x));
assert(1 == offset);
- assert(1 == x);
+ assert(25 == x);
- assert(rufl_OK == rufl_split("Trinity", rufl_WEIGHT_500, 10,
- (const uint8_t *) "!\xc2\xa0", 3, 1,
+ /* Attempt to split after first character. As the split point is
+ * coincident with the start of the second character, however,
+ * the split point is placed after it. */
+ assert(rufl_OK == rufl_split("Trinity", rufl_WEIGHT_500, 160,
+ (const uint8_t *) "!\xc2\xa0", 3, 25,
&offset, &x));
- assert(1 == offset);
- assert(1 == x);
+ assert(3 == offset);
+ assert(50 == x);
rufl_dump_state(true);