Changes in uspace/lib/gfxfont/test/text.c [7470d97:4583015] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/text.c
r7470d97 r4583015 30 30 #include <gfx/context.h> 31 31 #include <gfx/font.h> 32 #include <gfx/glyph.h> 32 33 #include <gfx/text.h> 33 34 #include <gfx/typeface.h> … … 134 135 135 136 gfx_text_fmt_init(&fmt); 137 fmt.font = font; 136 138 fmt.color = color; 137 139 pos.x = 0; 138 140 pos.y = 0; 139 141 140 rc = gfx_puttext(font, &pos, &fmt, "Hello world!"); 141 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 142 rc = gfx_puttext(&pos, &fmt, "Hello world!"); 143 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 144 145 gfx_font_close(font); 146 gfx_typeface_destroy(tface); 147 gfx_color_delete(color); 148 149 rc = gfx_context_delete(gc); 150 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 151 } 152 153 /** gfx_text_start_pos() correctly computes text start position */ 154 PCUT_TEST(text_start_pos) 155 { 156 gfx_font_props_t props; 157 gfx_font_metrics_t metrics; 158 gfx_typeface_t *tface; 159 gfx_font_t *font; 160 gfx_context_t *gc; 161 gfx_color_t *color; 162 gfx_text_fmt_t fmt; 163 gfx_coord2_t pos; 164 test_gc_t tgc; 165 errno_t rc; 166 167 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 168 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 169 170 rc = gfx_color_new_rgb_i16(0, 0, 0, &color); 171 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 172 173 rc = gfx_typeface_create(gc, &tface); 174 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 175 176 gfx_font_props_init(&props); 177 gfx_font_metrics_init(&metrics); 178 metrics.ascent = 10; // XXX 179 metrics.descent = 10; // XXX 180 rc = gfx_font_create(tface, &props, &metrics, &font); 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 183 gfx_text_fmt_init(&fmt); 184 fmt.font = font; 185 fmt.color = color; 186 pos.x = 0; 187 pos.y = 0; 188 189 rc = gfx_puttext(&pos, &fmt, "Hello world!"); 190 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 191 192 gfx_font_close(font); 193 gfx_typeface_destroy(tface); 194 gfx_color_delete(color); 195 196 rc = gfx_context_delete(gc); 197 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 198 } 199 200 /** gfx_text_find_pos() finds position in text */ 201 PCUT_TEST(text_find_pos) 202 { 203 gfx_font_props_t props; 204 gfx_font_metrics_t metrics; 205 gfx_typeface_t *tface; 206 gfx_font_t *font; 207 gfx_glyph_metrics_t gmetrics; 208 gfx_glyph_t *glyph1; 209 gfx_glyph_t *glyph2; 210 gfx_context_t *gc; 211 gfx_text_fmt_t fmt; 212 gfx_coord2_t anchor; 213 gfx_coord2_t fpos; 214 size_t off; 215 test_gc_t tgc; 216 errno_t rc; 217 218 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 219 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 220 221 rc = gfx_typeface_create(gc, &tface); 222 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 223 224 gfx_font_props_init(&props); 225 gfx_font_metrics_init(&metrics); 226 rc = gfx_font_create(tface, &props, &metrics, &font); 227 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 228 229 /* Need to create some glyphs with metrics */ 230 gfx_glyph_metrics_init(&gmetrics); 231 gmetrics.advance = 10; 232 233 rc = gfx_glyph_create(font, &gmetrics, &glyph1); 234 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 235 236 rc = gfx_glyph_set_pattern(glyph1, "A"); 237 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 238 239 gfx_glyph_metrics_init(&gmetrics); 240 gmetrics.advance = 1; 241 242 rc = gfx_glyph_create(font, &gmetrics, &glyph2); 243 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 244 245 rc = gfx_glyph_set_pattern(glyph2, "i"); 246 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 247 248 gfx_text_fmt_init(&fmt); 249 fmt.font = font; 250 anchor.x = 10; 251 anchor.y = 0; 252 253 fpos.x = 9; 254 fpos.y = 0; 255 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 256 PCUT_ASSERT_INT_EQUALS(0, off); 257 258 fpos.x = 10; 259 fpos.y = 0; 260 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 261 PCUT_ASSERT_INT_EQUALS(0, off); 262 263 fpos.x = 11; 264 fpos.y = 0; 265 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 266 PCUT_ASSERT_INT_EQUALS(0, off); 267 268 fpos.x = 19; 269 fpos.y = 0; 270 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 271 PCUT_ASSERT_INT_EQUALS(1, off); 272 273 fpos.x = 20; 274 fpos.y = 0; 275 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 276 PCUT_ASSERT_INT_EQUALS(2, off); 277 278 fpos.x = 21; 279 fpos.y = 0; 280 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 281 PCUT_ASSERT_INT_EQUALS(3, off); 282 283 fpos.x = 22; 284 fpos.y = 0; 285 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 286 PCUT_ASSERT_INT_EQUALS(3, off); 287 288 gfx_glyph_destroy(glyph1); 289 gfx_glyph_destroy(glyph2); 290 291 gfx_font_close(font); 292 gfx_typeface_destroy(tface); 293 294 rc = gfx_context_delete(gc); 295 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 296 } 297 298 /** gfx_text_find_pos() finds position in text in text mode */ 299 PCUT_TEST(text_find_pos_text) 300 { 301 gfx_typeface_t *tface; 302 gfx_font_t *font; 303 gfx_context_t *gc; 304 test_gc_t tgc; 305 size_t off; 306 gfx_text_fmt_t fmt; 307 gfx_coord2_t anchor; 308 gfx_coord2_t fpos; 309 errno_t rc; 310 311 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 312 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 313 314 rc = gfx_typeface_create(gc, &tface); 315 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 316 317 rc = gfx_font_create_textmode(tface, &font); 318 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 319 320 anchor.x = 10; 321 anchor.y = 0; 322 gfx_text_fmt_init(&fmt); 323 fmt.font = font; 324 325 fpos.x = 9; 326 fpos.y = 0; 327 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 328 PCUT_ASSERT_INT_EQUALS(0, off); 329 330 fpos.x = 10; 331 fpos.y = 0; 332 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 333 PCUT_ASSERT_INT_EQUALS(0, off); 334 335 fpos.x = 11; 336 fpos.y = 0; 337 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 338 PCUT_ASSERT_INT_EQUALS(1, off); 339 340 fpos.x = 12; 341 fpos.y = 0; 342 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 343 PCUT_ASSERT_INT_EQUALS(2, off); 344 345 fpos.x = 13; 346 fpos.y = 0; 347 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 348 PCUT_ASSERT_INT_EQUALS(3, off); 349 350 fpos.x = 14; 351 fpos.y = 0; 352 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 353 PCUT_ASSERT_INT_EQUALS(3, off); 354 355 gfx_font_close(font); 356 gfx_typeface_destroy(tface); 357 358 rc = gfx_context_delete(gc); 359 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 360 } 361 362 /** gfx_text_cont() produces correct continuation parameters */ 363 PCUT_TEST(text_cont) 364 { 365 gfx_typeface_t *tface; 366 gfx_font_t *font; 367 gfx_context_t *gc; 368 gfx_color_t *color; 369 test_gc_t tgc; 370 gfx_text_fmt_t fmt; 371 gfx_coord2_t anchor; 372 gfx_coord2_t cpos; 373 gfx_text_fmt_t cfmt; 374 errno_t rc; 375 376 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 377 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 378 379 rc = gfx_typeface_create(gc, &tface); 380 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 381 382 rc = gfx_font_create_textmode(tface, &font); 383 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 384 385 rc = gfx_color_new_rgb_i16(0, 0, 0, &color); 386 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 387 388 anchor.x = 10; 389 anchor.y = 20; 390 gfx_text_fmt_init(&fmt); 391 fmt.font = font; 392 fmt.color = color; 393 394 gfx_text_cont(&anchor, &fmt, "Abc", &cpos, &cfmt); 395 396 PCUT_ASSERT_INT_EQUALS(13, cpos.x); 397 PCUT_ASSERT_INT_EQUALS(20, cpos.y); 398 PCUT_ASSERT_EQUALS(fmt.color, cfmt.color); 399 PCUT_ASSERT_EQUALS(gfx_halign_left, cfmt.halign); 400 PCUT_ASSERT_EQUALS(gfx_valign_baseline, cfmt.valign); 401 402 gfx_font_close(font); 403 gfx_typeface_destroy(tface); 404 gfx_color_delete(color); 405 406 rc = gfx_context_delete(gc); 407 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 408 } 409 410 /** gfx_text_rect() computes bounding rectangle */ 411 PCUT_TEST(text_rect) 412 { 413 gfx_typeface_t *tface; 414 gfx_font_t *font; 415 gfx_context_t *gc; 416 gfx_color_t *color; 417 test_gc_t tgc; 418 gfx_text_fmt_t fmt; 419 gfx_coord2_t anchor; 420 gfx_rect_t rect; 421 errno_t rc; 422 423 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 424 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 425 426 rc = gfx_typeface_create(gc, &tface); 427 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 428 429 rc = gfx_font_create_textmode(tface, &font); 430 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 431 432 rc = gfx_color_new_rgb_i16(0, 0, 0, &color); 433 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 434 435 anchor.x = 10; 436 anchor.y = 20; 437 gfx_text_fmt_init(&fmt); 438 fmt.font = font; 439 fmt.color = color; 440 441 gfx_text_rect(&anchor, &fmt, "Abc", &rect); 442 443 PCUT_ASSERT_INT_EQUALS(10, rect.p0.x); 444 PCUT_ASSERT_INT_EQUALS(20, rect.p0.y); 445 PCUT_ASSERT_INT_EQUALS(13, rect.p1.x); 446 PCUT_ASSERT_INT_EQUALS(21, rect.p1.y); 142 447 143 448 gfx_font_close(font);
Note:
See TracChangeset
for help on using the changeset viewer.