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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*
* This code is based on Labyrinth of Time code with assistance of
*
* Copyright (c) 1993 Terra Nova Development
* Copyright (c) 2004 The Wyrmkeep Entertainment Co.
*
*/
#include "lab/lab.h"
#include "lab/labfun.h"
#include "lab/text.h"
namespace Lab {
/*****************************************************************************/
/* Closes a font and frees all memory associated with it. */
/*****************************************************************************/
void closeFont(TextFont *tf) {
if (tf) {
if (tf->data && tf->DataLength)
delete[] tf->data;
delete tf;
}
}
/*****************************************************************************/
/* Returns the length of a text in the specified font. */
/*****************************************************************************/
uint16 textLength(TextFont *tf, const char *text, uint16 numchars) {
uint16 length = 0;
if (tf) {
for (uint16 i = 0; i < numchars; i++) {
length += tf->Widths[(uint)*text];
text++;
}
}
return length;
}
/*****************************************************************************/
/* Returns the height of a specified font. */
/*****************************************************************************/
uint16 textHeight(TextFont *tf) {
return (tf) ? tf->Height : 0;
}
/*****************************************************************************/
/* Draws the text to the screen. */
/*****************************************************************************/
void text(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numchars) {
byte *VGATop, *VGACur, *VGATemp, *VGATempLine, *cdata;
uint32 RealOffset, SegmentOffset;
int32 templeft, LeftInSegment;
uint16 bwidth, mask, curpage, data;
VGATop = g_lab->getCurrentDrawingBuffer();
for (uint16 i = 0; i < numchars; i++) {
RealOffset = (g_lab->_screenWidth * y) + x;
curpage = RealOffset / g_lab->_screenBytesPerPage;
SegmentOffset = RealOffset - (curpage * g_lab->_screenBytesPerPage);
LeftInSegment = g_lab->_screenBytesPerPage - SegmentOffset;
VGACur = VGATop + SegmentOffset;
if (tf->Widths[(uint)*text]) {
cdata = tf->data + tf->Offsets[(uint)*text];
bwidth = *cdata++;
VGATemp = VGACur;
VGATempLine = VGACur;
for (uint16 rows = 0; rows < tf->Height; rows++) {
VGATemp = VGATempLine;
templeft = LeftInSegment;
for (uint16 cols = 0; cols < bwidth; cols++) {
data = *cdata++;
if (data && (templeft >= 8)) {
for (int j = 7; j >= 0; j--) {
if ((1 << j) & data)
*VGATemp = color;
VGATemp++;
}
templeft -= 8;
} else if (data) {
mask = 0x80;
templeft = LeftInSegment;
for (uint16 counterb = 0; counterb < 8; counterb++) {
if (templeft <= 0) {
curpage++;
VGATemp = (byte *)(VGATop - templeft);
/* Set up VGATempLine for next line */
VGATempLine -= g_lab->_screenBytesPerPage;
/* Set up LeftInSegment for next line */
LeftInSegment += g_lab->_screenBytesPerPage + templeft;
templeft += g_lab->_screenBytesPerPage;
}
if (mask & data)
*VGATemp = color;
VGATemp++;
mask = mask >> 1;
templeft--;
}
} else {
templeft -= 8;
VGATemp += 8;
}
}
VGATempLine += g_lab->_screenWidth;
LeftInSegment -= g_lab->_screenWidth;
if (LeftInSegment <= 0) {
curpage++;
VGATempLine -= g_lab->_screenBytesPerPage;
LeftInSegment += g_lab->_screenBytesPerPage;
}
}
}
x += tf->Widths[(int)*text];
text++;
}
}
} // End of namespace Lab
|