summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libflash/text.cc
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libflash/text.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libflash/text.cc246
1 files changed, 246 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libflash/text.cc b/core/multimedia/opieplayer/libflash/text.cc
new file mode 100644
index 0000000..1b6cb5e
--- a/dev/null
+++ b/core/multimedia/opieplayer/libflash/text.cc
@@ -0,0 +1,246 @@
1/////////////////////////////////////////////////////////////
2// Flash Plugin and Player
3// Copyright (C) 1998,1999 Olivier Debon
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 2
8// of the License, or (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, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18//
19///////////////////////////////////////////////////////////////
20// Author : Olivier Debon <odebon@club-internet.fr>
21//
22
23#include "swf.h"
24
25#ifdef RCSID
26static char *rcsid = "$Id$";
27#endif
28
29Text::Text(long id) : Character(TextType, id)
30{
31 textRecords = 0;
32}
33
34Text::~Text()
35{
36 TextRecord *cur,*del;
37
38 for(cur = textRecords; cur;)
39 {
40 del = cur;
41 cur = cur->next;
42 delete del;
43 }
44}
45
46void
47Text::setTextBoundary(Rect rect)
48{
49 boundary = rect;
50}
51
52void
53Text::setTextMatrix(Matrix m)
54{
55 textMatrix = m;
56}
57
58void
59Text::addTextRecord(TextRecord *tr)
60{
61 SwfFont *font = 0;
62 long n;
63
64 tr->next = 0;
65
66 if (textRecords == 0) {
67 textRecords = tr;
68 font = tr->font;
69 } else {
70 TextRecord *current;
71 long fontHeight = 0;
72
73 for(current = textRecords; current->next; current = current->next) {
74 if (current->flags & textHasFont) {
75 font = current->font;
76 fontHeight = current->fontHeight;
77 }
78 }
79
80 current->next = tr;
81 if (current->flags & textHasFont) {
82 font = current->font;
83 fontHeight = current->fontHeight;
84 }
85
86 if (tr->flags & textHasFont) {
87 font = tr->font;
88 } else {
89 tr->font = font;
90 tr->fontHeight = fontHeight;
91 }
92 }
93
94 if (tr->nbGlyphs) {
95 for(n=0; n < tr->nbGlyphs; n++) {
96 tr->glyphs[n].code = font->getGlyphCode(tr->glyphs[n].index);
97 }
98 }
99}
100
101int
102Text::execute(GraphicDevice *gd, Matrix *matrix, Cxform *cxform)
103{
104 return doText(gd, matrix, cxform, ShapeDraw, NULL, NULL);
105}
106
107void
108Text::getRegion(GraphicDevice *gd, Matrix *matrix,
109 void *id, ScanLineFunc scan_line_func)
110{
111 doText(gd, matrix, 0, ShapeGetRegion, id, scan_line_func);
112}
113
114void
115Text::getBoundingBox(Rect *bb, DisplayListEntry *e)
116{
117 *bb = boundary;
118}
119
120TextRecord *
121Text::getTextRecords()
122{
123 return textRecords;
124}
125
126int
127Text::doText(GraphicDevice *gd, Matrix *matrix, Cxform *cxform, ShapeAction action,
128 void *id, ScanLineFunc scan_line_func)
129{
130 TextRecord*tr;
131 long x,y; // Current position
132 SwfFont *font = 0;// Current font
133 long fontHeight;
134 Matrix tmat,fmat;
135 long g;
136
137 x = y = 0;
138 fontHeight = 0;
139
140 // Compute final text matrix
141 tmat = (*matrix) * textMatrix;
142
143 for(tr = textRecords; tr; tr = tr ->next)
144 {
145 if (tr->flags & isTextControl) {
146 if (tr->flags & textHasXOffset) {
147 x = tr->xOffset;
148 }
149 if (tr->flags & textHasYOffset) {
150 y = tr->yOffset;
151 }
152 if (tr->flags & textHasColor) {
153 if (action == ShapeDraw) {
154 if (cxform) {
155 gd->setForegroundColor(cxform->getColor(tr->color));
156 } else {
157 gd->setForegroundColor(tr->color);
158 }
159 }
160 }
161 }
162
163 font = tr->font;
164 fontHeight = tr->fontHeight;
165 // Update font matrix
166 fmat.a = fontHeight/1000.0;
167 fmat.d = fontHeight/1000.0;
168
169 assert(font != 0);
170 for (g = 0; g < tr->nbGlyphs; g++)
171 {
172 Shape *shape;
173 Matrix cmat;
174
175 shape = font->getGlyph( tr->glyphs[g].index );
176
177#ifdef PRINT
178 printf("%c", font->getGlyphCode(tr->glyphs[g].index));
179#endif
180
181 // Update font matrix
182 fmat.tx = x;
183 fmat.ty = y;
184
185 // Compute Character matrix
186 cmat = tmat * fmat;
187
188 if (action == ShapeDraw) {
189 shape->execute(gd, &cmat, cxform);
190 } else {
191 shape->getRegion(gd, &cmat, id, scan_line_func);
192 }
193
194 // Advance
195 x += tr->glyphs[g].xAdvance;
196 }
197#ifdef PRINT
198 printf("\n");
199#endif
200 }
201
202 if (gd->showMore) {
203 tmat = (*gd->adjust) * (*matrix);
204
205 long x1,x2,y1,y2;
206
207 x1 = boundary.xmin;
208 y1 = boundary.ymin;
209 x2 = boundary.xmax;
210 y2 = boundary.ymax;
211 gd->drawLine(tmat.getX(x1,y1),tmat.getY(x1,y1),tmat.getX(x2,y1),tmat.getY(x2,y1),FRAC);
212 gd->drawLine(tmat.getX(x2,y1),tmat.getY(x2,y1),tmat.getX(x2,y2),tmat.getY(x2,y2),FRAC);
213 gd->drawLine(tmat.getX(x2,y2),tmat.getY(x2,y2),tmat.getX(x1,y2),tmat.getY(x1,y2),FRAC);
214 gd->drawLine(tmat.getX(x1,y2),tmat.getY(x1,y2),tmat.getX(x1,y1),tmat.getY(x1,y1),FRAC);
215 }
216
217 return 0;
218}
219
220////////// TextRecord Methods
221TextRecord::TextRecord() {
222 flags = (TextFlags)0;
223 font = 0;
224 fontHeight = 0;
225 nbGlyphs = 0;
226 glyphs = 0;
227 xOffset = 0;
228 yOffset = 0;
229}
230
231TextRecord::~TextRecord() {
232 if (nbGlyphs) delete glyphs;
233}
234
235char *
236TextRecord::getText() {
237 static char text[256];
238 long g;
239
240 for(g=0; g < nbGlyphs; g++) {
241 text[g] = glyphs[g].code;
242 }
243 text[g] = 0;
244
245 return text;
246}