string.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include <memdraw.h>
  13. #include <memlayer.h>
  14. Point
  15. memimagestring(Memimage *b, Point p, Memimage *color, Point cp, Memsubfont *f,
  16. char *cs)
  17. {
  18. int w, width;
  19. uint8_t *s;
  20. Rune c;
  21. Fontchar *i;
  22. s = (uint8_t*)cs;
  23. for(; c=*s; p.x+=width, cp.x+=width){
  24. width = 0;
  25. if(c < Runeself)
  26. s++;
  27. else{
  28. w = chartorune(&c, (char*)s);
  29. if(w == 0){
  30. s++;
  31. continue;
  32. }
  33. s += w;
  34. }
  35. if(c >= f->n)
  36. continue;
  37. i = f->info+c;
  38. width = i->width;
  39. 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),
  40. color, cp, f->bits, Pt(i->x, i->top), SoverD);
  41. }
  42. return p;
  43. }
  44. Point
  45. memsubfontwidth(Memsubfont *f, char *cs)
  46. {
  47. Rune c;
  48. Point p;
  49. uint8_t *s;
  50. Fontchar *i;
  51. int w, width;
  52. p = Pt(0, f->height);
  53. s = (uint8_t*)cs;
  54. for(; c=*s; p.x+=width){
  55. width = 0;
  56. if(c < Runeself)
  57. s++;
  58. else{
  59. w = chartorune(&c, (char*)s);
  60. if(w == 0){
  61. s++;
  62. continue;
  63. }
  64. s += w;
  65. }
  66. if(c >= f->n)
  67. continue;
  68. i = f->info+c;
  69. width = i->width;
  70. }
  71. return p;
  72. }