Changeset 4583015 in mainline for uspace/lib/gfxfont
- Timestamp:
- 2022-03-07T16:10:44Z (4 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ca2680d
- Parents:
- 5c27e77
- Location:
- uspace/lib/gfxfont
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/include/gfx/text.h
r5c27e77 r4583015 45 45 extern void gfx_text_fmt_init(gfx_text_fmt_t *); 46 46 extern gfx_coord_t gfx_text_width(gfx_font_t *, const char *); 47 extern errno_t gfx_puttext(gfx_font_t *, gfx_coord2_t *, gfx_text_fmt_t *, 48 const char *); 49 extern void gfx_text_start_pos(gfx_font_t *, gfx_coord2_t *, gfx_text_fmt_t *, 50 const char *, gfx_coord2_t *); 51 extern size_t gfx_text_find_pos(gfx_font_t *, gfx_coord2_t *, gfx_text_fmt_t *, 52 const char *, gfx_coord2_t *); 53 extern void gfx_text_cont(gfx_font_t *, gfx_coord2_t *, gfx_text_fmt_t *, 54 const char *, gfx_coord2_t *, gfx_text_fmt_t *); 55 extern void gfx_text_rect(gfx_font_t *, gfx_coord2_t *, gfx_text_fmt_t *, 56 const char *, gfx_rect_t *); 47 extern errno_t gfx_puttext(gfx_coord2_t *, gfx_text_fmt_t *, const char *); 48 extern void gfx_text_start_pos(gfx_coord2_t *, gfx_text_fmt_t *, const char *, 49 gfx_coord2_t *); 50 extern size_t gfx_text_find_pos(gfx_coord2_t *, gfx_text_fmt_t *, const char *, 51 gfx_coord2_t *); 52 extern void gfx_text_cont(gfx_coord2_t *, gfx_text_fmt_t *, const char *, 53 gfx_coord2_t *, gfx_text_fmt_t *); 54 extern void gfx_text_rect(gfx_coord2_t *, gfx_text_fmt_t *, const char *, 55 gfx_rect_t *); 57 56 58 57 #endif -
uspace/lib/gfxfont/include/types/gfx/text.h
r5c27e77 r4583015 67 67 /** Text formatting */ 68 68 typedef struct { 69 /** Text font */ 70 struct gfx_font *font; 69 71 /** Text color */ 70 72 gfx_color_t *color; -
uspace/lib/gfxfont/src/text.c
r5c27e77 r4583015 168 168 /** Get text starting position. 169 169 * 170 * @param font Font171 170 * @param pos Anchor position 172 171 * @param fmt Text formatting … … 174 173 * @param spos Place to store starting position 175 174 */ 176 void gfx_text_start_pos(gfx_ font_t *font, gfx_coord2_t *pos,177 gfx_text_fmt_t *fmt,const char *str, gfx_coord2_t *spos)175 void gfx_text_start_pos(gfx_coord2_t *pos, gfx_text_fmt_t *fmt, 176 const char *str, gfx_coord2_t *spos) 178 177 { 179 178 gfx_font_metrics_t fmetrics; … … 184 183 /* Adjust position for horizontal alignment */ 185 184 if (fmt->halign != gfx_halign_left) { 186 width = gfx_text_width(f ont, str);185 width = gfx_text_width(fmt->font, str); 187 186 switch (fmt->halign) { 188 187 case gfx_halign_center: … … 198 197 199 198 /* Adjust position for vertical alignment */ 200 gfx_font_get_metrics(f ont, &fmetrics);199 gfx_font_get_metrics(fmt->font, &fmetrics); 201 200 202 201 if (fmt->valign != gfx_valign_baseline) { … … 219 218 /** Render text. 220 219 * 221 * @param font Font222 220 * @param pos Anchor position 223 221 * @param fmt Text formatting … … 225 223 * @return EOK on success or an error code 226 224 */ 227 errno_t gfx_puttext(gfx_font_t *font, gfx_coord2_t *pos, 228 gfx_text_fmt_t *fmt, const char *str) 225 errno_t gfx_puttext(gfx_coord2_t *pos, gfx_text_fmt_t *fmt, const char *str) 229 226 { 230 227 gfx_glyph_metrics_t gmetrics; … … 238 235 errno_t rc; 239 236 240 gfx_text_start_pos( font,pos, fmt, str, &spos);237 gfx_text_start_pos(pos, fmt, str, &spos); 241 238 242 239 /* Text mode */ 243 if ((f ont->finfo->props.flags & gff_text_mode) != 0)244 return gfx_puttext_textmode(f ont, &spos, fmt->color, str);245 246 rc = gfx_set_color(f ont->typeface->gc, fmt->color);240 if ((fmt->font->finfo->props.flags & gff_text_mode) != 0) 241 return gfx_puttext_textmode(fmt->font, &spos, fmt->color, str); 242 243 rc = gfx_set_color(fmt->font->typeface->gc, fmt->color); 247 244 if (rc != EOK) 248 245 return rc; … … 251 248 cp = str; 252 249 while (*cp != '\0') { 253 rc = gfx_font_search_glyph(f ont, cp, &glyph, &stradv);250 rc = gfx_font_search_glyph(fmt->font, cp, &glyph, &stradv); 254 251 if (rc != EOK) { 255 252 ++cp; … … 269 266 /* Text underlining */ 270 267 if (fmt->underline) { 271 gfx_font_get_metrics(f ont, &fmetrics);268 gfx_font_get_metrics(fmt->font, &fmetrics); 272 269 273 270 rect.p0.x = spos.x; … … 276 273 rect.p1.y = spos.y + fmetrics.underline_y1; 277 274 278 rc = gfx_fill_rect(f ont->typeface->gc, &rect);275 rc = gfx_fill_rect(fmt->font->typeface->gc, &rect); 279 276 if (rc != EOK) 280 277 return rc; … … 286 283 /** Find character position in string by X coordinate. 287 284 * 288 * @param font Font289 285 * @param pos Anchor position 290 286 * @param fmt Text formatting … … 298 294 * offset of the following character. 299 295 */ 300 size_t gfx_text_find_pos(gfx_ font_t *font, gfx_coord2_t *pos,301 gfx_text_fmt_t *fmt,const char *str, gfx_coord2_t *fpos)296 size_t gfx_text_find_pos(gfx_coord2_t *pos, gfx_text_fmt_t *fmt, 297 const char *str, gfx_coord2_t *fpos) 302 298 { 303 299 gfx_glyph_metrics_t gmetrics; … … 310 306 errno_t rc; 311 307 312 gfx_text_start_pos( font,pos, fmt, str, &cpos);308 gfx_text_start_pos(pos, fmt, str, &cpos); 313 309 314 310 /* Text mode */ 315 if ((f ont->finfo->props.flags & gff_text_mode) != 0) {311 if ((fmt->font->finfo->props.flags & gff_text_mode) != 0) { 316 312 off = 0; 317 313 strsize = str_size(str); … … 329 325 off = 0; 330 326 while (*cp != '\0') { 331 rc = gfx_font_search_glyph(f ont, cp, &glyph, &stradv);327 rc = gfx_font_search_glyph(fmt->font, cp, &glyph, &stradv); 332 328 if (rc != EOK) { 333 329 ++cp; … … 355 351 * to the same objects, respectively. 356 352 * 357 * @param font Font358 353 * @param pos Anchor position 359 354 * @param fmt Text formatting … … 362 357 * @param cfmt Place to store format for continuation 363 358 */ 364 void gfx_text_cont(gfx_font_t *font, gfx_coord2_t *pos, 365 gfx_text_fmt_t *fmt, const char *str, gfx_coord2_t *cpos, 366 gfx_text_fmt_t *cfmt) 359 void gfx_text_cont(gfx_coord2_t *pos, gfx_text_fmt_t *fmt, const char *str, 360 gfx_coord2_t *cpos, gfx_text_fmt_t *cfmt) 367 361 { 368 362 gfx_coord2_t spos; … … 370 364 371 365 /* Continuation should start where the current string ends */ 372 gfx_text_start_pos( font,pos, fmt, str, &spos);373 cpos->x = spos.x + gfx_text_width(f ont, str);366 gfx_text_start_pos(pos, fmt, str, &spos); 367 cpos->x = spos.x + gfx_text_width(fmt->font, str); 374 368 cpos->y = spos.y; 375 369 … … 387 381 /** Get text bounding rectangle. 388 382 * 389 * @param font Font390 383 * @param pos Anchor position 391 384 * @param fmt Text formatting … … 393 386 * @param rect Place to store bounding rectangle 394 387 */ 395 void gfx_text_rect(gfx_ font_t *font, gfx_coord2_t *pos,396 gfx_ text_fmt_t *fmt, const char *str, gfx_rect_t *rect)388 void gfx_text_rect(gfx_coord2_t *pos, gfx_text_fmt_t *fmt, const char *str, 389 gfx_rect_t *rect) 397 390 { 398 391 gfx_coord2_t spos; 399 392 400 gfx_text_start_pos( font,pos, fmt, str, &spos);393 gfx_text_start_pos(pos, fmt, str, &spos); 401 394 402 395 rect->p0.x = spos.x; 403 rect->p0.y = spos.y - f ont->metrics.ascent;404 rect->p1.x = spos.x + gfx_text_width(f ont, str);405 rect->p1.y = spos.y + font->metrics.descent + 1;396 rect->p0.y = spos.y - fmt->font->metrics.ascent; 397 rect->p1.x = spos.x + gfx_text_width(fmt->font, str); 398 rect->p1.y = spos.y + fmt->font->metrics.descent + 1; 406 399 } 407 400 -
uspace/lib/gfxfont/test/text.c
r5c27e77 r4583015 135 135 136 136 gfx_text_fmt_init(&fmt); 137 fmt.font = font; 137 138 fmt.color = color; 138 139 pos.x = 0; 139 140 pos.y = 0; 140 141 141 rc = gfx_puttext( font,&pos, &fmt, "Hello world!");142 rc = gfx_puttext(&pos, &fmt, "Hello world!"); 142 143 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 143 144 … … 181 182 182 183 gfx_text_fmt_init(&fmt); 184 fmt.font = font; 183 185 fmt.color = color; 184 186 pos.x = 0; 185 187 pos.y = 0; 186 188 187 rc = gfx_puttext( font,&pos, &fmt, "Hello world!");189 rc = gfx_puttext(&pos, &fmt, "Hello world!"); 188 190 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 191 … … 245 247 246 248 gfx_text_fmt_init(&fmt); 249 fmt.font = font; 247 250 anchor.x = 10; 248 251 anchor.y = 0; … … 250 253 fpos.x = 9; 251 254 fpos.y = 0; 252 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);255 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 253 256 PCUT_ASSERT_INT_EQUALS(0, off); 254 257 255 258 fpos.x = 10; 256 259 fpos.y = 0; 257 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);260 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 258 261 PCUT_ASSERT_INT_EQUALS(0, off); 259 262 260 263 fpos.x = 11; 261 264 fpos.y = 0; 262 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);265 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 263 266 PCUT_ASSERT_INT_EQUALS(0, off); 264 267 265 268 fpos.x = 19; 266 269 fpos.y = 0; 267 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);270 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 268 271 PCUT_ASSERT_INT_EQUALS(1, off); 269 272 270 273 fpos.x = 20; 271 274 fpos.y = 0; 272 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);275 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 273 276 PCUT_ASSERT_INT_EQUALS(2, off); 274 277 275 278 fpos.x = 21; 276 279 fpos.y = 0; 277 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);280 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 278 281 PCUT_ASSERT_INT_EQUALS(3, off); 279 282 280 283 fpos.x = 22; 281 284 fpos.y = 0; 282 off = gfx_text_find_pos( font,&anchor, &fmt, "Aii", &fpos);285 off = gfx_text_find_pos(&anchor, &fmt, "Aii", &fpos); 283 286 PCUT_ASSERT_INT_EQUALS(3, off); 284 287 … … 318 321 anchor.y = 0; 319 322 gfx_text_fmt_init(&fmt); 323 fmt.font = font; 320 324 321 325 fpos.x = 9; 322 326 fpos.y = 0; 323 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);327 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 324 328 PCUT_ASSERT_INT_EQUALS(0, off); 325 329 326 330 fpos.x = 10; 327 331 fpos.y = 0; 328 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);332 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 329 333 PCUT_ASSERT_INT_EQUALS(0, off); 330 334 331 335 fpos.x = 11; 332 336 fpos.y = 0; 333 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);337 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 334 338 PCUT_ASSERT_INT_EQUALS(1, off); 335 339 336 340 fpos.x = 12; 337 341 fpos.y = 0; 338 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);342 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 339 343 PCUT_ASSERT_INT_EQUALS(2, off); 340 344 341 345 fpos.x = 13; 342 346 fpos.y = 0; 343 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);347 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 344 348 PCUT_ASSERT_INT_EQUALS(3, off); 345 349 346 350 fpos.x = 14; 347 351 fpos.y = 0; 348 off = gfx_text_find_pos( font,&anchor, &fmt, "Abc", &fpos);352 off = gfx_text_find_pos(&anchor, &fmt, "Abc", &fpos); 349 353 PCUT_ASSERT_INT_EQUALS(3, off); 350 354 … … 385 389 anchor.y = 20; 386 390 gfx_text_fmt_init(&fmt); 391 fmt.font = font; 387 392 fmt.color = color; 388 393 389 gfx_text_cont( font,&anchor, &fmt, "Abc", &cpos, &cfmt);394 gfx_text_cont(&anchor, &fmt, "Abc", &cpos, &cfmt); 390 395 391 396 PCUT_ASSERT_INT_EQUALS(13, cpos.x); … … 431 436 anchor.y = 20; 432 437 gfx_text_fmt_init(&fmt); 438 fmt.font = font; 433 439 fmt.color = color; 434 440 435 gfx_text_rect( font,&anchor, &fmt, "Abc", &rect);441 gfx_text_rect(&anchor, &fmt, "Abc", &rect); 436 442 437 443 PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
Note:
See TracChangeset
for help on using the changeset viewer.