stringsubfont.c 945 B

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