stringsubfont.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <draw.h>
  12. Point
  13. stringsubfont(Image *b, Point p, Image *color, Subfont *f, char *cs)
  14. {
  15. int w, width;
  16. uint8_t *s;
  17. Rune c;
  18. Fontchar *i;
  19. s = (uint8_t*)cs;
  20. for(; (c=*s) != 0; p.x+=width){
  21. width = 0;
  22. if(c < Runeself)
  23. s++;
  24. else{
  25. w = chartorune(&c, (char*)s);
  26. if(w == 0){
  27. s++;
  28. continue;
  29. }
  30. s += w;
  31. }
  32. if(c >= f->n)
  33. continue;
  34. i = f->info+c;
  35. width = i->width;
  36. draw(b, Rect(p.x+i->left, p.y+i->top, p.x+i->left+(i[1].x-i[0].x), p.y+i->bottom),
  37. color, f->bits, Pt(i->x, i->top));
  38. }
  39. return p;
  40. }
  41. Point
  42. strsubfontwidth(Subfont *f, char *cs)
  43. {
  44. Rune c;
  45. Point p;
  46. uint8_t *s;
  47. Fontchar *i;
  48. int w, width;
  49. p = Pt(0, f->height);
  50. s = (uint8_t*)cs;
  51. for(; (c=*s) != 0; p.x+=width){
  52. width = 0;
  53. if(c < Runeself)
  54. s++;
  55. else{
  56. w = chartorune(&c, (char*)s);
  57. if(w == 0){
  58. s++;
  59. continue;
  60. }
  61. s += w;
  62. }
  63. if(c >= f->n)
  64. continue;
  65. i = f->info+c;
  66. width = i->width;
  67. }
  68. return p;
  69. }