1 /*--------------------------------------------------------
3 --------------------------------------------------------
5 En memoria de mi querido padre
6 --------------------------------------------------------
7 Funciones para escribir texto con 'word-wrap'
8 --------------------------------------------------------*/
9 #ifndef KRONO_WORDWRAP_C
10 #define KRONO_WORDWRAP_C
19 Esta funcion imprime texto con word-wrap a 'w' caracteres...
20 NOTA: no puede usar palabras mayores a 1 Kb (1024 bytes!)
21 NOTA: no funciona muy bien con palabras muy largas (es decir, si no entran en el wrap, se salen del borde...)
22 NOTA: NO uso strtok porque se 'come' el separador de palabras!
23 NOTA: \n puede ser usado para saltar la linea
25 bmp = bitmap donde escribir
27 x, y = coordenadas en pixeles
29 w = ancho del borde, donde el texto 'cae' (wrap-edge)
30 text = texto a escribir
34 si funciona, devuelve la coordenada 'y' inferior hasta donde imprimio
36 int imprimir_wordwrap(BITMAP
*bmp
,
38 int x
, int y
, int color
, int w
,
41 char tok
[1024]; /* token actual */
42 char st
[2]; /* caracter de busqueda (lo trato como string) */
43 char *limites
= " ,;.<>()[]{}/*-+=\\|"; /* limitadores de token */
44 int i1
, i2
; /* auxiliares */
45 int xp
= 0; /* posicion actual en pantalla */
50 if (w
< text_length(f
, "X")) return 0; /* evita bucle infinito, creo... :^P */
52 while (i1
< strlen(text
))
54 /* buscar un token, e imprimirlo */
56 tok
[0] = st
[0] = st
[1] = '\0'; /* blanquear strings */
59 tok
[i2
-i1
] = text
[i2
];
61 st
[0] = text
[i2
]; /* caracter de comprobacion */
63 if (text
[i2
] == '\n') /* salto de linea */
66 y
+= text_height(f
); // + 1;
71 } while (i2
< strlen(text
) && !strstr(limites
, st
) && i2
- i1
< 1023 && x
+text_length(f
, tok
) < x
+ w
);
75 /* avanzar: el +1 evita bucles infinitos, creo... */
76 i1
+= (strlen(tok
) > 0) ? strlen(tok
) : 1;
78 /* Si la palabra llega al borde, salto */
79 if (xp
+text_length(f
, tok
) > x
+ w
)
82 y
+= text_height(f
); // + 1;
85 textprintf(bmp
, f
, xp
, y
, color
, "%s", tok
);
87 xp
+= text_length(f
, tok
);
90 return y
+= text_height(f
); // + 1;