Introduction
Introduction Statistics Contact Development Disclaimer Help
frutil.c - sam - An updated version of the sam text editor.
git clone git://vernunftzentrum.de/sam.git
Log
Files
Refs
LICENSE
---
frutil.c (2179B)
---
1 /* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
2 #include <u.h>
3 #include <libg.h>
4 #include <frame.h>
5
6 int
7 _frcanfit(Frame *f, Point pt, Frbox *b)
8 {
9 int left, w, nr;
10 uint8_t *p;
11 wchar_t r;
12
13 left = f->r.max.x-pt.x;
14 if(b->nrune < 0)
15 return b->a.b.minwid <= left;
16 if(left >= b->wid)
17 return b->nrune;
18 for(nr=0,p=b->a.ptr; *p; p+=w,nr++){
19 r = *p;
20 w = chartorune(&r, (char*)p);
21 left -= charwidth(f->font, r);
22 if(left < 0)
23 return nr;
24 }
25 berror("_frcanfit can't");
26 return 0;
27 }
28
29 void
30 _frcklinewrap(Frame *f, Point *p, Frbox *b)
31 {
32 if((b->nrune<0? b->a.b.minwid : b->wid) > f->r.max.x-p->x){
33 p->x = f->left;
34 p->y += f->fheight;
35 }
36 }
37
38 void
39 _frcklinewrap0(Frame *f, Point *p, Frbox *b)
40 {
41 if(_frcanfit(f, *p, b) == 0){
42 p->x = f->left;
43 p->y += f->fheight;
44 }
45 }
46
47 void
48 _fradvance(Frame *f, Point *p, Frbox *b)
49 {
50 if(b->nrune<0 && b->a.b.bc=='\n'){
51 p->x = f->left;
52 p->y += f->fheight;
53 }else
54 p->x += b->wid;
55 }
56
57 int
58 _frnewwid(Frame *f, Point pt, Frbox *b)
59 {
60 int c, x;
61
62 c = f->r.max.x;
63 x = pt.x;
64 if(b->nrune >= 0)
65 return b->wid;
66 if(b->a.b.bc == '\t'){
67 if(x+b->a.b.minwid > c)
68 x = pt.x = f->left;
69 x += f->maxtab;
70 x -= (x-f->left)%f->maxtab;
71 if(x-pt.x<b->a.b.minwid || x>c)
72 x = pt.x+b->a.b.minwid;
73 b->wid = x-pt.x;
74 }
75 return b->wid;
76 }
77
78 void
79 _frclean(Frame *f, Point pt, int n0, int n1) /* look for mergeable bo…
80 {
81 Frbox *b;
82 int nb, c;
83
84 c = f->r.max.x;
85 for(nb=n0; nb<n1-1; nb++){
86 b = &f->box[nb];
87 _frcklinewrap(f, &pt, b);
88 while(b[0].nrune>=0 && nb<n1-1 && b[1].nrune>=0 && pt.x+b[0].wid…
89 _frmergebox(f, nb);
90 n1--;
91 b = &f->box[nb];
92 }
93 _fradvance(f, &pt, &f->box[nb]);
94 }
95 for(; nb<f->nbox; nb++){
96 b = &f->box[nb];
97 _frcklinewrap(f, &pt, b);
98 _fradvance(f, &pt, &f->box[nb]);
99 }
100 f->lastlinefull = false;
101 if(pt.y >= f->r.max.y)
102 f->lastlinefull = true;
103 }
You are viewing proxied material from vernunftzentrum.de. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.