Introduction
Introduction Statistics Contact Development Disclaimer Help
frptofchar.c - sam - An updated version of the sam text editor.
git clone git://vernunftzentrum.de/sam.git
Log
Files
Refs
LICENSE
---
frptofchar.c (2456B)
---
1 /* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
2 #include <u.h>
3 #include <libg.h>
4 #include <frame.h>
5
6 Point
7 _frptofcharptb(Frame *f, uint64_t p, Point pt, int bn)
8 {
9 uint8_t *s;
10 Frbox *b;
11 int w, l;
12 wchar_t r;
13
14 for(b = &f->box[bn]; bn<f->nbox; bn++,b++){
15 _frcklinewrap(f, &pt, b);
16 if(p < (l=NRUNE(b))){
17 if(b->nrune > 0)
18 for(s=b->a.ptr; p>0; s+=w, p--){
19 w = chartorune(&r, (char*)s);
20 pt.x += charwidth(f->font, r);
21 if(r==0 || pt.x>f->r.max.x)
22 berror("frptofchar");
23 }
24 break;
25 }
26 p -= l;
27 _fradvance(f, &pt, b);
28 }
29 return pt;
30 }
31
32 Point
33 frptofchar(Frame *f, uint64_t p)
34 {
35 return _frptofcharptb(f, p, Pt(f->left, f->r.min.y), 0);
36 }
37
38 Point
39 _frptofcharnb(Frame *f, uint64_t p, int nb) /* doesn't do final _frad…
40 {
41 Point pt;
42 int nbox;
43
44 nbox = f->nbox;
45 f->nbox = nb;
46 pt = _frptofcharptb(f, p, Pt(f->left, f->r.min.y), 0);
47 f->nbox = nbox;
48 return pt;
49 }
50
51 static
52 Point
53 _frgrid(Frame *f, Point p)
54 {
55 p.y -= f->r.min.y;
56 p.y -= p.y%f->fheight;
57 p.y += f->r.min.y;
58 if(p.x > f->r.max.x)
59 p.x = f->r.max.x;
60 return p;
61 }
62
63 uint64_t
64 frcharofpt(Frame *f, Point pt)
65 {
66 Point qt;
67 int w, bn;
68 uint8_t *s;
69 Frbox *b;
70 uint64_t p;
71 wchar_t r;
72
73 pt = _frgrid(f, pt);
74 qt.x = f->left;
75 qt.y = f->r.min.y;
76 for(b=f->box,bn=0,p=0; bn<f->nbox && qt.y<pt.y; bn++,b++){
77 _frcklinewrap(f, &qt, b);
78 if(qt.y >= pt.y)
79 break;
80 _fradvance(f, &qt, b);
81 p += NRUNE(b);
82 }
83 for(; bn<f->nbox && qt.x<=pt.x; bn++,b++){
84 _frcklinewrap(f, &qt, b);
85 if(qt.y > pt.y)
86 break;
87 if(qt.x+b->wid > pt.x){
88 if(b->nrune < 0)
89 _fradvance(f, &qt, b);
90 else{
91 s = b->a.ptr;
92 for(;;){
93 w = chartorune(&r, (char*)s);
94 if(r == 0)
95 berror("end of string in frcharofpt");
96 s += w;
97 qt.x += charwidth(f->font, r);
98 if(qt.x > pt.x)
99 break;
100 p++;
101 }
102 }
103 }else{
104 p += NRUNE(b);
105 _fradvance(f, &qt, b);
106 }
107 }
108 return p;
109 }
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.