stringsubfont.c 960 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. Point
  5. stringsubfont(Image *b, Point p, Image *color, Subfont *f, char *cs)
  6. {
  7. int w, width;
  8. uchar *s;
  9. Rune c;
  10. Fontchar *i;
  11. s = (uchar*)cs;
  12. for(; c=*s; p.x+=width){
  13. width = 0;
  14. if(c < Runeself)
  15. s++;
  16. else{
  17. w = chartorune(&c, (char*)s);
  18. if(w == 0){
  19. s++;
  20. continue;
  21. }
  22. s += w;
  23. }
  24. if(c >= f->n)
  25. continue;
  26. i = f->info+c;
  27. width = i->width;
  28. 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),
  29. color, f->bits, Pt(i->x, i->top));
  30. }
  31. return p;
  32. }
  33. Point
  34. strsubfontwidth(Subfont *f, char *cs)
  35. {
  36. Rune c;
  37. Point p;
  38. uchar *s;
  39. Fontchar *i;
  40. int w, width;
  41. p = Pt(0, f->height);
  42. s = (uchar*)cs;
  43. for(; c=*s; p.x+=width){
  44. width = 0;
  45. if(c < Runeself)
  46. s++;
  47. else{
  48. w = chartorune(&c, (char*)s);
  49. if(w == 0){
  50. s++;
  51. continue;
  52. }
  53. s += w;
  54. }
  55. if(c >= f->n)
  56. continue;
  57. i = f->info+c;
  58. width = i->width;
  59. }
  60. return p;
  61. }