-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextstruct.cpp
67 lines (56 loc) · 1.43 KB
/
textstruct.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "textstruct.h"
#include "servicestruct.h"
// ????????????? ????????? ??????
void initText(TextStruct * ts, WindowStruct * ws) {
ts->lines = 1;
LL xCharCount = ws->cxClient / ws->cxChar;
LL curCharCount = 0;
bool is_end = false;
// ??????? ???-?? ?????
for (LL i = 0; i < ts->length; ++i) {
if (ts->text[i] == '\n' ||
(ws->mode == LAYOUT && curCharCount >= xCharCount - 1)) {
is_end = true;
curCharCount = 0;
} else {
curCharCount++;
if (is_end) {
is_end = false;
ts->lines++;
}
}
}
ts->start_size = ts->lines + 1;
ts->start = (LL *) malloc(ts->start_size * sizeof(LL));
ts->start[0] = 0;
ts->start[ts->start_size - 1] = ts->length;
LL line = 1;
is_end = false;
// ????????????? ??????? ?????????? ?? ?????? ?????
for (LL i = 0; i < ts->length; ++i) {
if (ts->text[i] == '\n' ||
(ws->mode == LAYOUT && curCharCount >= xCharCount - 1)) {
is_end = true;
curCharCount = 0;
} else {
curCharCount++;
if (is_end) {
is_end = false;
ts->start[line] = i;
line++;
}
}
}
// ??????? ???????????? ????? ??????
for (LL i = 0; i < ts->lines; ++i) {
ts->maxLen = max(ts->maxLen, getLength(*ts, i));
}
}
// ????? ??????
LL getLength(TextStruct ts, int i) {
int len = ts.start[i + 1] - ts.start[i];
if (ts.text[ts.start[i + 1] - 2] == '\r') {
len -= 2;
}
return len;
}