string.c 1.0 KB

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