Debian Codegraph @

editor/GrFontDialog.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/editor/GrFontDialog.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:38 $
23 * $Author: kevinb $
24 *
25 * Font Editor
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 11 4/17/99 6:15p Samir
30 * replaced gr.h with grdefs.h and fixed resulting compile bugs.
31 *
32 * 10 5/08/98 5:23p Samir
33 * added font brightness and grayscale caps.
34 *
35 * 9 4/30/98 3:02p Samir
36 * better error checking.
37 *
38 * 8 4/29/98 3:13p Samir
39 * fixed font translation.
40 *
41 * 7 4/23/98 6:38p Jason
42 * made bitmaps use 1555 format
43 *
44 * 6 3/31/98 3:49p Jason
45 * added memory lib
46 *
47 * 5 3/06/98 3:34p Samir
48 * Fixed font image scanning to scan multiple rows of fonts.
49 *
50 * 4 1/28/98 3:29p Samir
51 * Increased max height of font.
52 *
53 * 3 1/12/98 5:22p Samir
54 * Fixed up font reading.
55 *
56 * 2 9/02/97 3:28p Matt
57 * Got rid of warnings
58 *
59 * 6 6/03/97 5:37p Mark
60 *
61 * 6 6/03/97 5:32p Jeff
62 * Added Context Sensitive Help
63 *
64 * 5 2/06/97 3:08p Samir
65 * Improved font saving for monochrome fonts
66 *
67 * $NoKeywords: $
68 */
69 // GrFontDialog.cpp : implementation file
70 //
71
72 #include "stdafx.h"
73 #include <stdlib.h>
74 #include <stdio.h>
75
76 #include "editor.h"
77 #include "GrFontDialog.h"
78
79 #include "gr.h"
80 #include "mono.h"
81 #include "bitmap.h"
82 #include "gametexture.h"
83 #include "manage.h"
84 #include "mem.h"
85
86 #ifdef _DEBUG
87 #define new DEBUG_NEW
88 #undef THIS_FILE
89 static char THIS_FILE[] = __FILE__;
90 #endif
91
92 #define COLOR_FONT 1
93 #define MONOCHROME_FONT 2
94 #define GRADIENT_FONT 3
95
96 #define FT_COLOR 1
97 #define FT_PROPORTIONAL 2
98 #define FT_KERNED 4
99 #define FT_GRADIENT 8
100
101 // Font File stuff
102
103 typedef FILE *FONTFILE;
104
105 #define BITS_TO_BYTES(x) (((x) + 7) >> 3)
106
107 inline int WRITE_FONT_INT(FONTFILE ffile, int i) { return fwrite(&i, sizeof(i), 1, (FILE *)ffile); }
108
109 inline int WRITE_FONT_SHORT(FONTFILE ffile, int16_t s) { return fwrite(&s, sizeof(s), 1, (FILE *)ffile); }
110
111 inline int WRITE_FONT_BYTE(FONTFILE ffile, uint8_t c) { return fwrite(&c, sizeof(c), 1, (FILE *)ffile); }
112
113 inline int WRITE_FONT_DATA(FONTFILE ffile, void *buf, int size, int nelem) {
114 int i;
115 i = (int)fwrite(buf, size, nelem, (FILE *)ffile);
116
117 ASSERT(i == nelem);
118
119 return i;
120 }
121
122 inline FONTFILE OPEN_FONT(char *filename) {
123 FONTFILE fp;
124
125 fp = (FONTFILE)fopen(filename, "wb");
126 if (!fp)
127 return NULL;
128
129 return fp;
130 }
131
132 inline void CLOSE_FONT(FONTFILE ffile) { fclose((FILE *)ffile); }
133
134 /////////////////////////////////////////////////////////////////////////////
135 // CGrFontDialog dialog
136
137 CGrFontDialog::CGrFontDialog(CWnd *pParent /*=NULL*/) : CDialog(CGrFontDialog::IDD, pParent) {
138 //{{AFX_DATA_INIT(CGrFontDialog)
139 // NOTE: the ClassWizard will add member initialization here
140 //}}AFX_DATA_INIT
141
142 m_FontPicBm = -1;
143 m_DataBuffer = NULL;
144
145 ZeroMemory(&m_FontRecord, sizeof(m_FontRecord));
146 }
147
148 void CGrFontDialog::DoDataExchange(CDataExchange *pDX) {
149 CDialog::DoDataExchange(pDX);
150 //{{AFX_DATA_MAP(CGrFontDialog)
151 // NOTE: the ClassWizard will add DDX and DDV calls here
152 //}}AFX_DATA_MAP
153 }
154
155 BEGIN_MESSAGE_MAP(CGrFontDialog, CDialog)
156 //{{AFX_MSG_MAP(CGrFontDialog)
157 ON_BN_CLICKED(IDC_NEW, OnNew)
158 ON_WM_PAINT()
159 ON_WM_CREATE()
160 ON_BN_CLICKED(IDC_SAVEAS, OnSaveAs)
161 ON_BN_CLICKED(IDC_SAVE, OnSave)
162 ON_WM_DESTROY()
163 ON_EN_KILLFOCUS(IDC_EDIT_MINASCII, OnKillfocusEditMinascii)
164 ON_EN_KILLFOCUS(IDC_EDIT_FONTNAME, OnKillfocusEditFontname)
165 ON_BN_CLICKED(IDC_LOCK, OnLock)
166 ON_BN_CLICKED(IDC_CHECKIN, OnCheckin)
167 ON_WM_HELPINFO()
168 ON_EN_KILLFOCUS(IDC_BRIGHTNESS, OnKillfocusBrightness)
169 //}}AFX_MSG_MAP
170 END_MESSAGE_MAP()
171
172 /////////////////////////////////////////////////////////////////////////////
173 // CGrFontDialog message handlers
174
175 void CGrFontDialog::OnNew() {
176 // TODO: Add your control notification handler code here
177 // Bring up Open TGA dialog.
178 CString filter = "D3 bitmap files (*.tga; *lbm; *.bbm)|*.tga; *.lbm; *.bbm|Targa files (*.tga)|*.tga|IFF files "
179 "(*.bbm; *.lbm)|*.bbm; *.lbm||";
180
181 CFileDialog dlg_open(TRUE, 0, 0, OFN_FILEMUSTEXIST, (LPCTSTR)filter, this);
182
183 if (dlg_open.DoModal() == IDCANCEL)
184 return;
185
186 // Okay, load in the proper picture for the font
187 char filename[255];
188 int bm_handle;
189
190 lstrcpy(filename, dlg_open.GetPathName());
191
192 if (m_FontPicBm > -1)
193 bm_FreeBitmap(m_FontPicBm);
194 m_FontPicBm = -1;
195
196 mprintf(0, "Loading font template: %s...", filename);
197 bm_handle = bm_AllocLoadFileBitmap(filename, 0);
198 if (bm_handle < 0) {
199 mprintf(0, "shit!\n");
200 OutrageMessageBox("Couldn't open the font template file.");
201 return;
202 }
203 mprintf(0, "finished!\n");
204
205 m_FontPicBm = bm_handle;
206
207 // Get MinAscii and other needed info before extracting font.
208
209 if (!extract_font(&m_FontRecord)) {
210 OutrageMessageBox("Unable to generate font from template %s.", filename);
211 return;
212 }
213
214 UpdateDialog();
215
216 // Display font on screen.
217 CWnd::Invalidate();
218 }
219
220 void CGrFontDialog::OnPaint() {
221 CPaintDC dc(this); // device context for painting
222 CWnd *fontwnd;
223 RECT rect;
224 int w, h;
225
226 if (m_FontPicBm > -1) {
227 grHardwareSurface surf(bm_w(m_FontPicBm, 0), bm_h(m_FontPicBm, 0), bm_bpp(m_FontPicBm));
228
229 fontwnd = GetDlgItem(IDC_STATIC_FONTVIEW);
230 fontwnd->GetWindowRect(&rect);
231 ScreenToClient(&rect);
232
233 w = rect.right - rect.left - 4;
234 h = rect.bottom - rect.top - 4;
235
236 if (w > (surf.width() - 4))
237 w = surf.width() - 4;
238 if (h > (surf.height() - 4))
239 h = surf.height() - 4;
240
241 // load bitmap, convert transparency to pure black and then blt
242 surf.load(m_FontPicBm);
243 surf.replace_color(TRANSPARENT_COLOR32, 0);
244
245 Desktop_surf->attach_to_window((unsigned)m_hWnd);
246 Desktop_surf->blt(rect.left + 2, rect.top + 2, &surf, 0, 0, w, h);
247 Desktop_surf->attach_to_window((unsigned)NULL);
248 }
249 }
250
251 int CGrFontDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) {
252 if (CDialog::OnCreate(lpCreateStruct) == -1)
253 return -1;
254
255 return 0;
256 }
257
258 BOOL CGrFontDialog::OnInitDialog() {
259 CDialog::OnInitDialog();
260
261 // TODO: Add extra initialization here
262 CButton *radio;
263 CButton *gray_check = (CButton *)GetDlgItem(IDC_PROP_GRADIANT);
264 CEdit *brightness = (CEdit *)GetDlgItem(IDC_BRIGHTNESS);
265 char str[8];
266
267 gray_check->EnableWindow(FALSE);
268
269 radio = (CButton *)GetDlgItem(IDC_PROP_MONO);
270 radio->SetCheck(0);
271
272 lstrcpy(m_FontName, "Untitled");
273 lstrcpy(m_FontFileName, "Untitled");
274
275 m_Brightness = 10;
276
277 sprintf(str, "%.1f", m_Brightness / 10.0f);
278 brightness->SetWindowText(str);
279
280 return TRUE; // return TRUE unless you set the focus to a control
281 // EXCEPTION: OCX Property Pages should return FALSE
282 }
283
284 void CGrFontDialog::OnSaveAs() {
285 CString filter = "Outrage font files (*.fnt)|*.fnt||";
286
287 CFileDialog dlg(FALSE, 0, 0, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, (LPCTSTR)filter, this);
288
289 if (dlg.DoModal() == IDCANCEL)
290 return;
291
292 lstrcpy(m_FontFileName, dlg.GetPathName());
293
294 save_font_file(&m_FontRecord);
295
296 UpdateDialog();
297 }
298
299 void CGrFontDialog::OnSave() {
300 if (strcmp(m_FontFileName, "Untitled") == 0)
301 OnSaveAs();
302 else {
303 save_font_file(&m_FontRecord);
304 }
305 }
306
307 void CGrFontDialog::OnDestroy() {
308 CDialog::OnDestroy();
309
310 if (m_DataBuffer)
311 delete[] m_DataBuffer;
312 if (m_FontPicBm > -1)
313 bm_FreeBitmap(m_FontPicBm);
314 m_FontPicBm = -1;
315 }
316
317 void CGrFontDialog::UpdateDialog() {
318 CButton *radio;
319 CEdit *edit;
320 CStatic *text;
321 char buf[64];
322
323 // Setup any necessary changes to control states in the dialog reflecting extraction of font.
324 radio = (CButton *)GetDlgItem(IDC_PROP_MONO);
325 radio->SetCheck(0);
326 radio = (CButton *)GetDlgItem(IDC_PROP_BITMAPPED);
327 radio->SetCheck(0);
328 radio = (CButton *)GetDlgItem(IDC_PROP_GRADIANT);
329 radio->SetCheck(0);
330
331 switch (m_FontType) {
332 case COLOR_FONT:
333 radio = (CButton *)GetDlgItem(IDC_PROP_BITMAPPED);
334 radio->SetCheck(1);
335 break;
336 case MONOCHROME_FONT:
337 radio = (CButton *)GetDlgItem(IDC_PROP_MONO);
338 radio->SetCheck(1);
339 break;
340 default:
341 Int3();
342 }
343
344 // Set filename static text. Set 'Untitled' name. Change static text font info.
345 edit = (CEdit *)GetDlgItem(IDC_EDIT_MINASCII);
346 _itoa(m_FontRecord.min_ascii, buf, 10);
347 edit->SetWindowText(buf);
348 text = (CStatic *)GetDlgItem(IDC_STATIC_MAXASCII);
349 _itoa(m_FontRecord.max_ascii, buf, 10);
350 text->SetWindowText(buf);
351 text = (CStatic *)GetDlgItem(IDC_STATIC_FONTNAME);
352 text->SetWindowText(m_FontFileName);
353
354 edit = (CEdit *)GetDlgItem(IDC_EDIT_FONTNAME);
355 edit->SetWindowText(m_FontName);
356
357 if (m_FontProp) {
358 text = (CStatic *)GetDlgItem(IDC_STATIC_PROP);
359 text->SetWindowText("Proportional");
360 } else {
361 text = (CStatic *)GetDlgItem(IDC_STATIC_PROP);
362 text->SetWindowText("");
363 }
364 }
365
366 void CGrFontDialog::OnKillfocusEditMinascii() {
367 CEdit *edit = (CEdit *)GetDlgItem(IDC_EDIT_MINASCII);
368 char buf[4];
369 int num_char = m_FontRecord.max_ascii - m_FontRecord.min_ascii + 1;
370 ;
371
372 edit->GetWindowText(buf, 4);
373 m_FontRecord.min_ascii = atoi(buf);
374 m_FontRecord.max_ascii = m_FontRecord.min_ascii + num_char - 1;
375
376 UpdateDialog();
377 }
378
379 void CGrFontDialog::OnKillfocusEditFontname() {
380 CEdit *edit = (CEdit *)GetDlgItem(IDC_EDIT_FONTNAME);
381 edit->GetWindowText(m_FontName, 32);
382 }
383
384 // ========================================================================================
385 // Font Extraction from Bitmap routines
386 // ========================================================================================
387
388 #define PIX(_x, _y) m_FontBmData[(_x) + (_y) * m_FontBmW]
389
390 inline uint16_t MAKE_565_FROM_555(uint16_t jcol) {
391 ddgr_color pix32 = GR_16_TO_COLOR(jcol);
392 int red = GR_COLOR_RED(pix32);
393 int green = GR_COLOR_GREEN(pix32);
394 int blue = GR_COLOR_BLUE(pix32);
395
396 uint16_t newpix = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
397 return newpix;
398 }
399
400 BOOL CGrFontDialog::extract_font(gr_font_file_record *ft) {
401 int bmx, bmy;
402 int cur_char;
403
404 // grab font template bitmap data from the bitmap library and retrieve characters
405 // store relevent information in file record.
406 m_FontBmData = bm_data(m_FontPicBm, 0);
407 m_FontBmW = bm_w(m_FontPicBm, 0);
408 m_FontBmH = bm_h(m_FontPicBm, 0);
409 m_CharMaxWidth = m_CharHeight = 0;
410 m_FontProp = FALSE;
411 m_FontType = MONOCHROME_FONT;
412 m_FgColor = NEW_TRANSPARENT_COLOR;
413
414 if (m_DataBuffer)
415 delete[] m_DataBuffer;
416 m_DataBuffer = new uint16_t[1024 * MAX_FONT_CHARS];
417 m_DataPtr = m_DataBuffer;
418
419 // assume upper left pixel is background color, and first-found other
420 // color is box color
421 m_BgColor = PIX(0, 0);
422
423 for (bmy = 0; bmy < m_FontBmH; bmy++) {
424 for (bmx = 0; bmx < m_FontBmW && PIX(bmx, bmy) == m_BgColor; bmx++)
425 ;
426 if (PIX(bmx, bmy) != m_BgColor)
427 break;
428 }
429
430 m_BoxColor = PIX(bmx, bmy);
431
432 // Get all data from current line.
433 mprintf(0, "Parsing font...");
434 mprintf(0, " read_characters: ");
435
436 for (cur_char = 0; bmy < m_FontBmH && cur_char < MAX_FONT_CHARS;) {
437 cur_char = read_font_line(cur_char, bmx, bmy);
438 if (cur_char == -1) {
439 delete[] m_DataBuffer;
440 m_DataBuffer = NULL;
441 mprintf(0, "fuck!\n");
442 return FALSE;
443 }
444 bmy += m_CharHeight + 1;
445
446 // search for start of next box
447 for (; bmy < m_FontBmH; bmy++) {
448 for (bmx = 0; bmx < m_FontBmW && PIX(bmx, bmy) != m_BoxColor; bmx++)
449 ;
450 if ((PIX(bmx, bmy) == m_BoxColor) && (PIX(bmx, bmy + 1) == m_BoxColor))
451 break;
452 }
453
454 if (bmy == m_FontBmH)
455 break;
456 // if (PIX(bmx,bmy+1) != m_BoxColor)
457 // break;
458 }
459 mprintf(0, "\nDone!\n");
460
461 // now fill in font information & store it into our file record. this information
462 // can be used to save the font
463 ft->width = m_CharMaxWidth;
464 ft->height = m_CharHeight;
465 ft->flags = (m_FontProp ? FT_PROPORTIONAL : 0) + ((m_FontType == COLOR_FONT) ? FT_COLOR : 0);
466 ft->baseline = m_CharHeight;
467 ft->min_ascii = 0;
468 ft->max_ascii = cur_char - 1;
469 ft->raw_data = (uint8_t *)m_DataBuffer;
470 ft->char_data = NULL;
471 ft->char_widths = m_CharWidths;
472 ft->kern_data = NULL;
473
474 CButton *gray_check = (CButton *)GetDlgItem(IDC_PROP_GRADIANT);
475 if (ft->flags & FT_COLOR)
476 gray_check->EnableWindow(TRUE);
477 else
478 gray_check->EnableWindow(FALSE);
479
480 return TRUE;
481 }
482
483 int CGrFontDialog::read_font_line(int cur_char, int &bmx, int &bmy) {
484 while (bmx < m_FontBmW && PIX(bmx + 1, bmy) == m_BoxColor) {
485 int res;
486 res = read_font_char(cur_char, bmx, bmy);
487 if (res == 0)
488 return -1;
489 else if (res == 1) {
490 bmx += m_CharWidths[cur_char] + 1;
491 cur_char++;
492 } else if (res == 2) {
493 break;
494 } else
495 break;
496 }
497
498 return cur_char;
499 }
500
501 int CGrFontDialog::read_font_char(int cur_char, int &bmx, int &bmy) {
502 int w, h, x, y;
503 bool box_edge = false;
504
505 mprintf(0, " %d-(%d,%d)", cur_char, bmx, bmy);
506
507 while (PIX(bmx + 1, bmy + 1) == m_BoxColor)
508 bmx++; // deal with double-thick vertical lines
509
510 for (w = 0; PIX(bmx + 1 + w, bmy + 1) != m_BoxColor; w++) {
511 if (PIX(bmx + 1 + w, bmy) != m_BoxColor) {
512 if (box_edge) {
513 OutrageMessageBox("Read probable premature eol at (%d,%d).\n", bmx + 1 + w, bmy);
514 w--;
515 return 2;
516 } else {
517 OutrageMessageBox("Suspected error at pixel coordindates %d,%d (char %d)", bmx + 1 + w, bmy, cur_char);
518 return 0;
519 }
520 } else {
521 box_edge = true;
522 }
523 }
524
525 box_edge = false;
526
527 for (h = 0; PIX(bmx + 1, bmy + 1 + h) != m_BoxColor; h++) {
528 if (PIX(bmx, bmy + 1 + h) != m_BoxColor) {
529 if (box_edge) {
530 OutrageMessageBox("Read probable premature end of row at (%d,%d).\n", bmx, bmy + 1 + h);
531 h--;
532 return 2;
533 } else {
534 OutrageMessageBox("Suspected error at pixel coordindates %d,%d (char %d)", bmx, bmy + 1 + h, cur_char);
535 return 0;
536 }
537 } else {
538 box_edge = true;
539 }
540 }
541
542 if (w == 0 || h == 0) {
543 OutrageMessageBox("Character %d has width of %d and height of %d", cur_char, w, h);
544 return 0;
545 }
546
547 m_CharWidths[cur_char] = w;
548
549 if (m_CharMaxWidth != 0 && w != m_CharMaxWidth)
550 m_FontProp = TRUE;
551
552 if (w > m_CharMaxWidth)
553 m_CharMaxWidth = w;
554
555 if (m_CharHeight == 0)
556 m_CharHeight = h;
557 else if (m_CharHeight != h) {
558 OutrageMessageBox("Char %d is wrong height (height = %d, correct height = %d)", cur_char, h, m_CharHeight);
559 return 0;
560 }
561
562 for (y = 0; y < h; y++)
563 for (x = 0; x < w; x++) {
564 uint16_t c;
565
566 if ((c = PIX(bmx + 1 + x, bmy + 1 + y)) == m_BgColor)
567 c = 0x07e0; // must go back 565 pure green (old transparent)
568 else if (!(m_FgColor & OPAQUE_FLAG))
569 m_FgColor = c;
570 else if (m_FgColor != c) { // c here is 1555 !! remember this.
571 m_FontType = COLOR_FONT;
572 // mprintf(0, "%d,%d\n", bmx+1+x, bmy+1+y);
573 }
574
575 if (c != 0x07e0)
576 *m_DataPtr++ = MAKE_565_FROM_555(c); // here 555 pure green will turn into 565 pure green transparent.
577 else
578 *m_DataPtr++ = 0x07e0;
579
580 ASSERT(m_DataPtr < m_DataBuffer + (1024 * 256));
581 }
582
583 return 1;
584 }
585
586 BOOL CGrFontDialog::save_font_file(gr_font_file_record *ft) {
587 uint8_t *tmp_data;
588 int16_t *tmp_widths;
589 uint8_t **tmp_cdata;
590 FONTFILE ffile;
591 uint32_t id = 0xfeedbaba;
592 int num_char;
593 bool grayed_font;
594 CButton *gray_check = (CButton *)GetDlgItem(IDC_PROP_GRADIANT);
595
596 if (gray_check->GetCheck() == 1)
597 grayed_font = true;
598 else
599 grayed_font = false;
600
601 // save data pointers. We don't write these out to the file.
602 tmp_data = ft->raw_data;
603 tmp_widths = ft->char_widths;
604 tmp_cdata = ft->char_data;
605
606 // Adjust font record for file write.
607 ft->flags = (m_FontProp ? FT_PROPORTIONAL : 0) + ((m_FontType == COLOR_FONT) ? FT_COLOR : 0) +
608 ((m_FontType == GRADIENT_FONT) ? FT_GRADIENT : 0) + (grayed_font ? FT_GRADIENT : 0);
609 ft->raw_data = NULL;
610 ft->char_data = NULL;
611 ft->char_widths = NULL;
612 ft->kern_data = NULL;
613
614 // write to file
615 mprintf(0, "Saving font data...");
616 // sprintf(filename, "%s\\%s", LocalManageGraphicsDir, m_FontFileName);
617 ffile = OPEN_FONT(m_FontFileName);
618 if (!ffile) {
619 OutrageMessageBox("Unable to save font %s.", m_FontFileName);
620 return FALSE;
621 }
622
623 // Write file id.
624 WRITE_FONT_INT(ffile, id);
625
626 // Write Header
627 // baseline brightness located in upper 8 bits.
628 ft->baseline = ft->baseline & 0x00ff;
629 ft->baseline = ft->baseline | (m_Brightness << 8);
630
631 WRITE_FONT_SHORT(ffile, ft->width);
632 WRITE_FONT_SHORT(ffile, ft->height);
633 WRITE_FONT_SHORT(ffile, ft->flags);
634 WRITE_FONT_SHORT(ffile, ft->baseline);
635 WRITE_FONT_BYTE(ffile, ft->min_ascii);
636 WRITE_FONT_BYTE(ffile, ft->max_ascii);
637 WRITE_FONT_DATA(ffile, m_FontName, 32, 1);
638
639 num_char = ft->max_ascii - ft->min_ascii + 1;
640
641 // Write widths now if necessary.(FT_PROPORTIONAL)
642 if (ft->flags & FT_PROPORTIONAL) {
643 for (int i = 0; i < num_char; i++)
644 WRITE_FONT_SHORT(ffile, tmp_widths[i]);
645 }
646
647 if (ft->flags & FT_COLOR) {
648 WRITE_FONT_INT(ffile, (int)(m_DataPtr - m_DataBuffer) * sizeof(uint16_t));
649 WRITE_FONT_DATA(ffile, (uint8_t *)m_DataBuffer, (m_DataPtr - m_DataBuffer) * sizeof(uint16_t), 1);
650 } else {
651 // bitpack for mono font storage:: 16bpp -> 8 bits/1 byte
652 int i, x, y, w, cnt = 0;
653 uint16_t *p = m_DataBuffer;
654 uint8_t *bits;
655
656 bits = (uint8_t *)mem_malloc(256 * MAX_FONT_CHARS);
657
658 for (i = 0; i < num_char; i++) {
659 for (y = 0; y < ft->height; y++) {
660 uint8_t mask, datum;
661
662 w = (ft->flags & FT_PROPORTIONAL) ? tmp_widths[i] : ft->width;
663
664 ASSERT(w <= 48); // Max width size shall be 32 pixels
665
666 mask = 0x80;
667 datum = 0;
668
669 for (x = 0; x < w; x++) {
670 if (mask == 0) {
671 bits[cnt++] = datum;
672 datum = 0;
673 mask = 0x80;
674 }
675 if (*p++ != 0x07e0)
676 datum |= mask;
677 mask >>= 1;
678 }
679
680 bits[cnt++] = datum;
681 }
682 }
683
684 WRITE_FONT_INT(ffile, cnt);
685 WRITE_FONT_DATA(ffile, bits, cnt, 1);
686 mem_free(bits);
687 }
688
689 // We should add kerning support here.
690
691 // Close font.
692 CLOSE_FONT(ffile);
693 mprintf(0, "Done.\n");
694
695 ft->raw_data = tmp_data;
696 ft->char_widths = tmp_widths;
697 ft->char_data = tmp_cdata;
698
699 return TRUE;
700 }
701
702 void CGrFontDialog::OnLock() {
703 // TODO: Add your control notification handler code here
704 }
705
706 void CGrFontDialog::OnCheckin() {
707 // TODO: Add your control notification handler code here
708 }
709
710 BOOL CGrFontDialog::OnHelpInfo(HELPINFO *pHelpInfo) {
711 // TODO: Add your message handler code here and/or call default
712 WinHelp(HID_FONTEDITORDLG, HELP_CONTEXT);
713 return TRUE;
714 // return CDialog::OnHelpInfo(pHelpInfo);
715 }
716
717 void CGrFontDialog::OnKillfocusBrightness() {
718 CEdit *edit = (CEdit *)GetDlgItem(IDC_BRIGHTNESS);
719 char str[8];
720
721 edit->GetWindowText(str, 7);
722
723 m_Brightness = (int)(atof(str) * 10.0);
724 }