Rev 6806 | Rev 6997 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6806 | Rev 6808 | ||
---|---|---|---|
- | 1 | // Сам шрифт представляет. |
|
- | 2 | ||
- | 3 | // Голова: |
|
- | 4 | // [2 байта символы:KF] |
|
- | 5 | // [4 байта:указатель на название шрифта] |
|
- | 6 | // [1 байт:размер массива указателей на размеры шрифтов, указатель 4 байта, т.е. размер = размер массива*4] |
|
- | 7 | // [размер массива*4 байт:указатели..] |
|
- | 8 | ||
- | 9 | // Тело файла: |
|
- | 10 | // [4 байта:масштаб ширина][4 байта:масштаб высота][255*4 байт:указатели на символы][масштаб ширина*масштаб высота байт: данные символов..] |
|
- | 11 | ||
- | 12 | // Конец: |
|
- | 13 | // [Название шрифта:"Times New Roman"] |
|
- | 14 | ||
- | 15 | ||
1 | #ifndef INCLUDE_LABEL_H |
16 | #ifndef INCLUDE_LABEL_H |
2 | #define INCLUDE_LABEL_H |
17 | #define INCLUDE_LABEL_H |
3 | 18 | ||
4 | #ifndef INCLUDE_MATH_H |
19 | #ifndef INCLUDE_MATH_H |
5 | #include "../lib/math.h" |
20 | #include "../lib/math.h" |
6 | #endif |
21 | #endif |
7 | 22 | ||
8 | #ifndef INCLUDE_IO_H |
23 | #ifndef INCLUDE_IO_H |
9 | #include "../lib/io.h" |
24 | #include "../lib/io.h" |
10 | #endif |
25 | #endif |
11 | 26 | ||
12 | #include "../lib/patterns/rgb.h" |
27 | #include "../lib/patterns/rgb.h" |
13 | 28 | ||
14 | 29 | ||
15 | #define DEFAULT_FONT "/sys/fonts/Tahoma.kf" |
30 | #define DEFAULT_FONT "/sys/fonts/Tahoma.kf" |
- | 31 | ||
- | 32 | #ifndef KFONT_BPP |
|
- | 33 | #define KFONT_BPP 4 |
|
- | 34 | #endif |
|
16 | 35 | ||
17 | :struct __SIZE |
36 | :struct __SIZE |
18 | { |
37 | { |
19 | dword width,height; |
38 | dword width,height; |
20 | signed offset_x, offset_y; |
39 | signed offset_x, offset_y; |
21 | byte pt; |
40 | byte pt; |
22 | }; |
41 | }; |
23 | :struct LABEL |
42 | :struct LABEL |
24 | { |
43 | { |
25 | __SIZE size; |
44 | __SIZE size; |
26 | int width,height; |
45 | int width,height; |
27 | byte bold,smooth; |
46 | byte bold,smooth; |
28 | dword color, background; |
47 | dword color, background; |
29 | dword font,font_begin; |
48 | dword font,font_begin; |
30 | word block; |
49 | word block; |
31 | dword raw; |
50 | dword raw; |
32 | dword raw_size; |
51 | dword raw_size; |
- | 52 | //dword palette[256]; |
|
33 | 53 | ||
34 | bool init(); |
54 | bool init(); |
35 | bool changeSIZE(); |
55 | bool changeSIZE(); |
36 | byte symbol(); |
56 | byte symbol(); |
37 | byte symbol_size(); |
57 | byte symbol_size(); |
38 | dword getsize(); |
58 | dword getsize(); |
39 | 59 | ||
40 | void ApplySmooth(); |
60 | void ApplySmooth(); |
41 | int WriteIntoWindow(); |
61 | int WriteIntoWindow(); |
42 | int WriteIntoWindowCenter(); |
62 | int WriteIntoWindowCenter(); |
43 | void WriteIntoBuffer(); |
63 | void WriteIntoBuffer(); |
44 | void ShowBuffer(); |
64 | void ShowBuffer(); |
- | 65 | void ShowBufferPart(); |
|
45 | } kfont; |
66 | } kfont; |
- | 67 | ||
- | 68 | :bool LABEL::init(dword font_path) |
|
- | 69 | { |
|
- | 70 | IO label_io; |
|
- | 71 | if(font)free(font); |
|
- | 72 | label_io.read(font_path); |
|
- | 73 | if(!EAX) { |
|
- | 74 | debugln(font_path); |
|
- | 75 | label_io.run("/sys/@notify", "'Error: KFONT is not loaded.' -E"); |
|
- | 76 | return false; |
|
- | 77 | } |
|
- | 78 | font_begin = label_io.buffer_data; |
|
- | 79 | changeSIZE(); |
|
- | 80 | smooth = true; |
|
- | 81 | return true; |
|
- | 82 | } |
|
46 | 83 | ||
47 | :bool LABEL::changeSIZE() |
84 | :bool LABEL::changeSIZE() |
48 | { |
85 | { |
49 | dword file_size; |
86 | dword file_size; |
50 | dword ofs; |
87 | dword ofs; |
51 | if(size.pt<9) size.pt = 9; |
88 | if(size.pt<9) size.pt = 9; |
52 | font = font_begin; |
89 | font = font_begin; |
53 | ofs = DSDWORD[calc(size.pt-8<<2+font_begin)]; |
90 | ofs = DSDWORD[calc(size.pt-8<<2+font_begin)]; |
54 | if(ofs==-1)return false; |
91 | if(ofs==-1)return false; |
55 | font += ofs + 156; |
92 | font += ofs + 156; |
56 | file_size = DSDWORD[calc(font)]; |
93 | file_size = DSDWORD[calc(font)]; |
57 | height = DSBYTE[calc(font+file_size) - 1]; |
94 | height = DSBYTE[calc(font+file_size) - 1]; |
58 | width = DSBYTE[calc(font+file_size) - 2]; |
95 | width = DSBYTE[calc(font+file_size) - 2]; |
59 | block = math.ceil(height*width/32); |
96 | block = math.ceil(height*width/32); |
60 | return true; |
97 | return true; |
61 | } |
98 | } |
62 | 99 | ||
63 | :dword LABEL::getsize(byte fontSizePoints, dword text1) |
100 | :dword LABEL::getsize(byte fontSizePoints, dword text1) |
64 | { |
101 | { |
65 | size.height = size.width = 0; |
102 | size.height = size.width = 0; |
66 | size.offset_x = size.offset_y = -1; |
103 | size.offset_x = size.offset_y = -1; |
67 | size.pt = fontSizePoints; |
104 | size.pt = fontSizePoints; |
68 | if(size.pt)if(!changeSIZE())return 0; |
105 | if(size.pt)if(!changeSIZE())return 0; |
69 | WHILE(DSBYTE[text1]) |
106 | WHILE(DSBYTE[text1]) |
70 | { |
107 | { |
71 | size.width += symbol_size(DSBYTE[text1]); |
108 | size.width += symbol_size(DSBYTE[text1]); |
72 | text1++; |
109 | text1++; |
73 | } |
110 | } |
74 | $neg size.offset_y |
111 | $neg size.offset_y |
75 | $neg size.offset_x |
112 | $neg size.offset_x |
76 | size.height += size.offset_y+1; |
113 | size.height += size.offset_y+1; |
77 | size.width += size.offset_x+1; |
114 | size.width += size.offset_x+1; |
78 | return size.width; |
115 | return size.width; |
79 | } |
116 | } |
80 | 117 | ||
81 | :byte LABEL::symbol_size(byte s) |
118 | :byte LABEL::symbol_size(byte s) |
82 | { |
119 | { |
83 | int chaw_width; |
120 | int chaw_width; |
84 | chaw_width = symbol(0,0, s, 0); |
121 | chaw_width = symbol(0,0, s, 0); |
85 | if(bold) chaw_width += math.ceil(size.pt/17); |
122 | if(bold) chaw_width += math.ceil(size.pt/17); |
86 | return chaw_width; |
123 | return chaw_width; |
87 | } |
124 | } |
88 | 125 | ||
89 | :byte LABEL::symbol(signed x,y; byte s; dword image_raw) |
126 | :byte LABEL::symbol(signed x,y; byte s; dword image_raw) |
90 | { |
127 | { |
91 | dword xi,yi; |
128 | dword xi,yi; |
92 | dword iii = 0; |
129 | dword iii = 0; |
93 | dword offs; |
130 | dword offs; |
94 | dword tmp, _; |
131 | dword tmp, _; |
95 | byte X; |
132 | byte X; |
96 | byte chaw_width=0; |
133 | byte chaw_width=0; |
97 | if(s==32)return width/4; |
134 | if(s==32)return width/4; |
98 | if(s==9)return width; |
135 | if(s==9)return width; |
99 | s = Cp866ToAnsi(s); |
136 | s = Cp866ToAnsi(s); |
100 | tmp = block*s << 2 + font; |
137 | tmp = block*s << 2 + font; |
101 | for(yi=0; yi |
138 | for(yi=0; yi |
102 | { |
139 | { |
103 | EDI = size.offset_y + yi + y * size.width * 3 + image_raw; |
140 | EDI = size.offset_y + yi + y * size.width * KFONT_BPP + image_raw; |
104 | for(xi=0; xi |
141 | for(xi=0; xi |
105 | { |
142 | { |
106 | if(iii%32) _ >>= 1; |
143 | if(iii%32) _ >>= 1; |
107 | else |
144 | else |
108 | { |
145 | { |
109 | tmp += 4; |
146 | tmp += 4; |
110 | _ = DSDWORD[tmp]; |
147 | _ = DSDWORD[tmp]; |
111 | } |
148 | } |
112 | if(_&1) //check does the pixel set |
149 | if(_&1) //check does the pixel set |
113 | { |
150 | { |
114 | if(xi>chaw_width)chaw_width=xi; |
151 | if(xi>chaw_width)chaw_width=xi; |
- | 152 | //in case of image_raw!=0 draw font into bug |
|
- | 153 | //in case of image_raw==0 calculate size |
|
115 | if (image_raw) |
154 | if (image_raw) |
116 | { |
155 | { |
117 | offs = x + xi *3 + EDI; |
156 | offs = x + xi * KFONT_BPP + EDI; |
118 | DSDWORD[offs] = DSDWORD[offs] & 0xFF000000 | color; |
157 | DSDWORD[offs] = color; |
119 | if(bold) DSDWORD[offs+3] = DSDWORD[offs+3] & 0xFF000000 | color; |
158 | if(bold) DSDWORD[offs+KFONT_BPP] = color; |
120 | } |
159 | } |
121 | else |
160 | else |
122 | { |
161 | { |
123 | if(size.height |
162 | if(size.height |
124 | if(size.offset_y<0)size.offset_y = yi; else if(yi |
163 | if(size.offset_y<0)size.offset_y = yi; else if(yi |
125 | if(!X) X = xi; else if(X>xi)X = xi; |
164 | if(!X) X = xi; else if(X>xi)X = xi; |
126 | if(size.offset_x<0)size.offset_x = X; |
165 | if(size.offset_x<0)size.offset_x = X; |
127 | } |
166 | } |
128 | } |
167 | } |
129 | iii++; |
168 | iii++; |
130 | } |
169 | } |
131 | } |
170 | } |
132 | return chaw_width; |
171 | return chaw_width; |
133 | } |
172 | } |
134 | 173 | ||
135 | inline fastcall Cp866ToAnsi(AL) { |
174 | inline fastcall Cp866ToAnsi(AL) { |
136 | if (AL>=128)&&(AL<=175) return AL+64; |
175 | if (AL>=128)&&(AL<=175) return AL+64; |
137 | if (AL>=224)&&(AL<=239) return AL+16; |
176 | if (AL>=224)&&(AL<=239) return AL+16; |
138 | if (AL==241) return 184; //e ruAL with dotAL (yo) |
177 | if (AL==241) return 184; //e ruAL with dotAL (yo) |
139 | if (AL==240) return 168; //E ruAL with dotAL (yo) |
178 | if (AL==240) return 168; //E ruAL with dotAL (yo) |
140 | if (AL==242) return 'E'; //E ukr (ye) |
179 | if (AL==242) return 'E'; //E ukr (ye) |
141 | if (AL==243) return 186; //e ukr (ye) |
180 | if (AL==243) return 186; //e ukr (ye) |
142 | if (AL==244) return 'I'; //I ukr (yi) |
181 | if (AL==244) return 'I'; //I ukr (yi) |
143 | if (AL==245) return 191; //i ukr (yi) |
182 | if (AL==245) return 191; //i ukr (yi) |
144 | return AL; |
183 | return AL; |
145 | } |
184 | } |
146 | - | ||
147 | :bool LABEL::init(dword font_path) |
- | |
148 | { |
- | |
149 | IO label_io; |
- | |
150 | if(font)free(font); |
- | |
151 | label_io.read(font_path); |
- | |
152 | if(!EAX) { |
- | |
153 | debugln(font_path); |
- | |
154 | label_io.run("/sys/@notify", "'Error: KFONT is not loaded.' -E"); |
- | |
155 | return false; |
- | |
156 | } |
- | |
157 | font_begin = label_io.buffer_data; |
- | |
158 | changeSIZE(); |
- | |
159 | smooth = true; |
- | |
160 | return true; |
- | |
161 | } |
- | |
162 | - | ||
163 | 185 | ||
164 | /*===================================================================================== |
186 | /*===================================================================================== |
165 | =========================== =========================== |
187 | =========================== =========================== |
166 | =========================== RAW =========================== |
188 | =========================== RAW =========================== |
167 | =========================== =========================== |
189 | =========================== =========================== |
168 | =====================================================================================*/ |
190 | =====================================================================================*/ |
169 | - | ||
170 | 191 | ||
171 | inline fastcall dword b24(EAX) { return DSDWORD[EAX] & 0x00FFFFFF; } |
192 | inline fastcall dword b32(EAX) { return DSDWORD[EAX]; } |
172 | :void LABEL::ApplySmooth() |
193 | :void LABEL::ApplySmooth() |
173 | { |
194 | { |
174 | dword i,line_w,to,dark_background; |
195 | dword i,line_w,to,dark_background; |
175 | line_w = size.width * 3; |
196 | line_w = size.width * KFONT_BPP; |
176 | to = size.height - 1 * line_w + raw - 3; |
197 | to = size.height - 1 * line_w + raw - KFONT_BPP; |
177 | for(i=raw; i < to; i+=3) |
198 | for(i=raw; i < to; i+=KFONT_BPP) |
178 | { |
199 | { |
179 | if(i-raw%line_w +3 == line_w) continue; |
200 | if(i-raw%line_w +KFONT_BPP == line_w) continue; |
180 | // pixels position, where b - black, w - write |
201 | // pixels position, where b - black, w - write |
181 | // bw |
202 | // bw |
182 | // wb |
203 | // wb |
- | 204 | if(b32(i)!=background) { |
|
- | 205 | if (b32(i+KFONT_BPP)==background) |
|
183 | if(b24(i)!=background) && (b24(i+3)==background) && (b24(i+line_w)==background) && (b24(i+3+line_w)!=background) |
206 | && (b32(i+line_w)==background) && (b32(i+KFONT_BPP+line_w)!=background) |
184 | { |
207 | { |
185 | dark_background = MixColors(background,b24(i),200); |
208 | dark_background = MixColors(background,b32(i),200); |
186 | DSDWORD[i+3] = DSDWORD[i+3] & 0xFF000000 | dark_background; |
209 | DSDWORD[i+KFONT_BPP] = dark_background; |
187 | DSDWORD[i+line_w] = DSDWORD[i+line_w] & 0xFF000000 | dark_background; |
210 | DSDWORD[i+line_w] = dark_background; |
- | 211 | } |
|
188 | } |
212 | } |
189 | // wb |
213 | // wb |
190 | // bw |
214 | // bw |
- | 215 | else if (b32(i+KFONT_BPP)!=background) |
|
191 | else if(b24(i)==background) && (b24(i+3)!=background) && (b24(i+line_w)!=background) && (b24(i+3+line_w)==background) |
216 | && (b32(i+line_w)!=background) && (b32(i+KFONT_BPP+line_w)==background) |
192 | { |
217 | { |
193 | dark_background = MixColors(background,b24(i+3),200); |
218 | dark_background = MixColors(background,b32(i+KFONT_BPP),200); |
194 | DSDWORD[i] = DSDWORD[i] & 0xFF000000 | dark_background; |
219 | DSDWORD[i] = dark_background; |
195 | DSDWORD[i+3+line_w] = DSDWORD[i+3+line_w] & 0xFF000000 | dark_background; |
220 | DSDWORD[i+KFONT_BPP+line_w] = dark_background; |
196 | } |
221 | } |
197 | } |
222 | } |
198 | } |
223 | } |
199 | 224 | ||
200 | :void LABEL::WriteIntoBuffer(int x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1) |
225 | :void LABEL::WriteIntoBuffer(int x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1) |
201 | { |
226 | { |
202 | dword new_raw_size; |
227 | dword new_raw_size; |
203 | if(!text1)return; |
228 | if(!text1)return; |
204 | if(size.pt)if(!changeSIZE())return; |
229 | if(size.pt)if(!changeSIZE())return; |
205 | 230 | ||
206 | if (size.pt != fontSizePoints) { |
231 | if (size.pt != fontSizePoints) { |
207 | getsize(fontSizePoints, text1); |
232 | getsize(fontSizePoints, text1); |
208 | y -= size.offset_y; |
233 | y -= size.offset_y; |
209 | } |
234 | } |
210 | color = _color; |
235 | color = _color; |
211 | background = _background; |
236 | background = _background; |
212 | 237 | ||
213 | size.width = w; |
238 | size.width = w; |
214 | size.height = h; |
239 | size.height = h; |
215 | 240 | ||
216 | new_raw_size = w*h*3; |
241 | new_raw_size = w*h*KFONT_BPP; |
217 | if(raw_size != new_raw_size) |
242 | if(raw_size != new_raw_size) |
218 | { |
243 | { |
219 | raw_size = new_raw_size; |
244 | raw_size = new_raw_size; |
220 | free(raw); |
245 | free(raw); |
221 | raw = malloc(raw_size); |
246 | raw = malloc(raw_size); |
222 | // Fill background color |
247 | // Fill background color |
223 | EBX = background; |
248 | EBX = background; |
224 | EAX = raw_size+raw; |
249 | EAX = raw_size+raw; |
225 | for (EDI=raw; EDI |
250 | for (EDI=raw; EDI |
226 | } |
251 | } |
227 | WHILE(DSBYTE[text1]) |
252 | WHILE(DSBYTE[text1]) |
228 | { |
253 | { |
229 | x+=symbol(x,y,DSBYTE[text1], raw); |
254 | x+=symbol(x,y,DSBYTE[text1], raw); |
230 | if(bold)x+=math.ceil(size.pt/17); |
255 | if(bold)x+=math.ceil(size.pt/17); |
231 | text1++; |
256 | text1++; |
232 | } |
257 | } |
233 | return; |
258 | return; |
234 | } |
259 | } |
235 | 260 | ||
236 | :int LABEL::WriteIntoWindow(int x,y; dword _background, _color; byte fontSizePoints; dword text1) |
261 | :int LABEL::WriteIntoWindow(int x,y; dword _background, _color; byte fontSizePoints; dword text1) |
237 | { |
262 | { |
238 | if(!text1)return 0; |
263 | if(!text1)return 0; |
239 | getsize(fontSizePoints, text1); |
264 | getsize(fontSizePoints, text1); |
240 | raw_size = NULL; |
265 | raw_size = NULL; |
241 | WriteIntoBuffer(0, -size.offset_y, size.width-size.offset_x, |
266 | WriteIntoBuffer(0, -size.offset_y, size.width-size.offset_x, |
242 | size.height-size.offset_y, _background, _color, fontSizePoints, text1); |
267 | size.height-size.offset_y, _background, _color, fontSizePoints, text1); |
243 | if (smooth) ApplySmooth(); |
268 | if (smooth) ApplySmooth(); |
244 | ShowBuffer(x,y); |
269 | ShowBuffer(x,y); |
245 | return size.offset_x + size.width; |
270 | return size.offset_x + size.width; |
246 | } |
271 | } |
247 | 272 | ||
248 | :int LABEL::WriteIntoWindowCenter(dword x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1) |
273 | :int LABEL::WriteIntoWindowCenter(dword x,y,w,h; dword _background, _color; byte fontSizePoints; dword text1) |
249 | { |
274 | { |
250 | getsize(fontSizePoints, text1); |
275 | getsize(fontSizePoints, text1); |
251 | return WriteIntoWindow(w-size.width/2+x,y, _background, _color, fontSizePoints, text1); |
276 | return WriteIntoWindow(w-size.width/2+x,y, _background, _color, fontSizePoints, text1); |
252 | } |
277 | } |
253 | 278 | ||
- | 279 | :void LABEL::ShowBuffer(dword _x, _y) |
|
254 | :void LABEL::ShowBuffer(dword x, y){ |
280 | { |
- | 281 | if (4==KFONT_BPP) PutPaletteImage(raw, size.width, size.height, _x, _y, 32, 0); |
|
255 | _PutImage(x, y, size.width, size.height, raw); |
282 | //if (1==KFONT_BPP) PutPaletteImage(raw, size.width, size.height, _x, _y, 8, #palette); |
- | 283 | } |
|
- | 284 | ||
- | 285 | :void LABEL::ShowBufferPart(dword _x, _y, _w, _h, _buf_offset) |
|
- | 286 | { |
|
- | 287 | if (4==KFONT_BPP) PutPaletteImage(_buf_offset * KFONT_BPP + raw, _w, _h, _x, _y, 32, 0); |
|
256 | } |
288 | //if (1==KFONT_BPP) PutPaletteImage(_buf_offset * KFONT_BPP + raw, _w, _h, _x, _y, 8, #palette); |
257 | 289 | } |
|
258 | 290 | ||
259 | #endif>=239)>=175)>0)size.offset_x>0)size.offset_y>><>2+font_begin)]; |
291 | #endif>=239)>=175)>0)size.offset_x>0)size.offset_y>><>2+font_begin)]; |
260 | ><2+font_begin)]; |
292 | ><2+font_begin)]; |
261 | >9)> |
293 | >9)> |