Changeset 4583015 in mainline for uspace/lib/gfxfont/src/text.c
- Timestamp:
- 2022-03-07T16:10:44Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ca2680d
- Parents:
- 5c27e77
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.