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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
/////////////////////////////////////////////////////////////
// Flash Plugin and Player
// Copyright (C) 1998,1999 Olivier Debon
//
// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
///////////////////////////////////////////////////////////////
// Author : Olivier Debon <odebon@club-internet.fr>
//
#include "swf.h"
#ifdef RCSID
static char *rcsid = "$Id: text.cc,v 1.2 2004/12/22 18:46:40 tgc Exp $";
#endif
Text::Text(long id) : Character(TextType, id)
{
textRecords = 0;
}
Text::~Text()
{
TextRecord *cur,*del;
for(cur = textRecords; cur;)
{
del = cur;
cur = cur->next;
delete del;
}
}
void
Text::setTextBoundary(Rect rect)
{
boundary = rect;
}
void
Text::setTextMatrix(Matrix m)
{
textMatrix = m;
}
void
Text::addTextRecord(TextRecord *tr)
{
SwfFont *font = 0;
long n;
tr->next = 0;
if (textRecords == 0) {
textRecords = tr;
font = tr->font;
} else {
TextRecord *current;
long fontHeight = 0;
for(current = textRecords; current->next; current = current->next) {
if (current->flags & textHasFont) {
font = current->font;
fontHeight = current->fontHeight;
}
}
current->next = tr;
if (current->flags & textHasFont) {
font = current->font;
fontHeight = current->fontHeight;
}
if (tr->flags & textHasFont) {
font = tr->font;
} else {
tr->font = font;
tr->fontHeight = fontHeight;
}
}
// Fix code when Font is null, set a default font
if (font == NULL) {
font = new SwfFont(0);
}
if (tr->nbGlyphs) {
for(n=0; n < tr->nbGlyphs; n++) {
tr->glyphs[n].code = font->getGlyphCode(tr->glyphs[n].index);
}
}
}
int
Text::execute(GraphicDevice *gd, Matrix *matrix, Cxform *cxform)
{
return doText(gd, matrix, cxform, ShapeDraw, NULL, NULL);
}
void
Text::getRegion(GraphicDevice *gd, Matrix *matrix,
void *id, ScanLineFunc scan_line_func)
{
doText(gd, matrix, 0, ShapeGetRegion, id, scan_line_func);
}
void
Text::getBoundingBox(Rect *bb, DisplayListEntry *e)
{
*bb = boundary;
}
TextRecord *
Text::getTextRecords()
{
return textRecords;
}
int
Text::doText(GraphicDevice *gd, Matrix *matrix, Cxform *cxform, ShapeAction action,
void *id, ScanLineFunc scan_line_func)
{
TextRecord *tr;
long x,y; // Current position
SwfFont *font = 0; // Current font
long fontHeight;
Matrix tmat,fmat;
long g;
x = y = 0;
fontHeight = 0;
// Compute final text matrix
tmat = (*matrix) * textMatrix;
for(tr = textRecords; tr; tr = tr ->next)
{
if (tr->flags & isTextControl) {
if (tr->flags & textHasXOffset) {
x = tr->xOffset;
}
if (tr->flags & textHasYOffset) {
y = tr->yOffset;
}
if (tr->flags & textHasColor) {
if (action == ShapeDraw) {
if (cxform) {
gd->setForegroundColor(cxform->getColor(tr->color));
} else {
gd->setForegroundColor(tr->color);
}
}
}
}
font = tr->font;
fontHeight = tr->fontHeight;
// Update font matrix
fmat.a = fontHeight/1000.0;
fmat.d = fontHeight/1000.0;
//Fix case where font is not defined : eg http://www.emme.com
if (font != NULL) { // TODO:
for (g = 0; g < tr->nbGlyphs; g++)
{
Shape *shape;
Matrix cmat;
shape = font->getGlyph( tr->glyphs[g].index );
#ifdef PRINT
printf("%c", font->getGlyphCode(tr->glyphs[g].index));
#endif
// Update font matrix
fmat.tx = x;
fmat.ty = y;
// Compute Character matrix
cmat = tmat * fmat;
if (action == ShapeDraw) {
shape->execute(gd, &cmat, cxform);
} else {
shape->getRegion(gd, &cmat, id, scan_line_func);
}
// Advance
x += tr->glyphs[g].xAdvance;
}
#ifdef PRINT
printf("\n");
#endif
}
}
if (gd->showMore) {
tmat = (*gd->adjust) * (*matrix);
long x1,x2,y1,y2;
x1 = boundary.xmin;
y1 = boundary.ymin;
x2 = boundary.xmax;
y2 = boundary.ymax;
gd->drawLine(tmat.getX(x1,y1),tmat.getY(x1,y1),tmat.getX(x2,y1),tmat.getY(x2,y1),FRAC);
gd->drawLine(tmat.getX(x2,y1),tmat.getY(x2,y1),tmat.getX(x2,y2),tmat.getY(x2,y2),FRAC);
gd->drawLine(tmat.getX(x2,y2),tmat.getY(x2,y2),tmat.getX(x1,y2),tmat.getY(x1,y2),FRAC);
gd->drawLine(tmat.getX(x1,y2),tmat.getY(x1,y2),tmat.getX(x1,y1),tmat.getY(x1,y1),FRAC);
}
return 0;
}
////////// TextRecord Methods
TextRecord::TextRecord() {
flags = (TextFlags)0;
font = 0;
fontHeight = 0;
nbGlyphs = 0;
glyphs = 0;
xOffset = 0;
yOffset = 0;
}
TextRecord::~TextRecord() {
if (nbGlyphs) delete glyphs;
}
char *
TextRecord::getText() {
static char text[256];
long g;
for(g=0; g < nbGlyphs; g++) {
text[g] = glyphs[g].code;
}
text[g] = 0;
return text;
}
|