+static char *
+string_guess_clip (TextChunk *chunk)
+{
+ BoundaryRect b;
+ char *s = NULL, *sp = chunk->string, *ep;
+ long start_offset, end_offset, len;
+ if (sp) {
+ AccessibleComponent *component =
+ Accessible_getComponent (chunk->source);
+ ep = sp + (strlen (sp));
+ len = g_utf8_strlen (chunk->string, -1);
+ if (component) {
+ AccessibleComponent_getExtents (component,
+ &b.x, &b.y,
+ &b.width, &b.height,
+ SPI_COORD_TYPE_SCREEN);
+ /* TODO: finish this! */
+ start_offset = len * (chunk->text_bounds.x - b.x) / b.width;
+ end_offset = len * (chunk->text_bounds.x +
+ chunk->text_bounds.width - b.x) / b.width;
+ fprintf (stderr, "String len %d, clipped to %d-%d\n",
+ len, start_offset, end_offset);
+ len = end_offset - start_offset;
+ sp = g_utf8_offset_to_pointer (chunk->string, start_offset);
+ ep = g_utf8_offset_to_pointer (chunk->string, end_offset);
+ }
+ s = g_new0 (char, ep - sp + 1);
+ s = g_utf8_strncpy (s, sp, len);
+ s [sp - ep] = '\0';
+ g_assert (g_utf8_validate (s, -1, NULL));
+ }
+ return s;
+}
+