00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021
00022
00023 #include "swf.h"
00024
00025 #ifdef RCSID
00026 static char *rcsid = "$Id: text.cc,v 1.1.1.1 2002/01/25 22:14:59 kergoth Exp $";
00027 #endif
00028
00029 Text::Text(long id) : Character(TextType, id)
00030 {
00031 textRecords = 0;
00032 }
00033
00034 Text::~Text()
00035 {
00036 TextRecord *cur,*del;
00037
00038 for(cur = textRecords; cur;)
00039 {
00040 del = cur;
00041 cur = cur->next;
00042 delete del;
00043 }
00044 }
00045
00046 void
00047 Text::setTextBoundary(Rect rect)
00048 {
00049 boundary = rect;
00050 }
00051
00052 void
00053 Text::setTextMatrix(Matrix m)
00054 {
00055 textMatrix = m;
00056 }
00057
00058 void
00059 Text::addTextRecord(TextRecord *tr)
00060 {
00061 SwfFont *font = 0;
00062 long n;
00063
00064 tr->next = 0;
00065
00066 if (textRecords == 0) {
00067 textRecords = tr;
00068 font = tr->font;
00069 } else {
00070 TextRecord *current;
00071 long fontHeight = 0;
00072
00073 for(current = textRecords; current->next; current = current->next) {
00074 if (current->flags & textHasFont) {
00075 font = current->font;
00076 fontHeight = current->fontHeight;
00077 }
00078 }
00079
00080 current->next = tr;
00081 if (current->flags & textHasFont) {
00082 font = current->font;
00083 fontHeight = current->fontHeight;
00084 }
00085
00086 if (tr->flags & textHasFont) {
00087 font = tr->font;
00088 } else {
00089 tr->font = font;
00090 tr->fontHeight = fontHeight;
00091 }
00092 }
00093
00094 if (tr->nbGlyphs) {
00095 for(n=0; n < tr->nbGlyphs; n++) {
00096 tr->glyphs[n].code = font->getGlyphCode(tr->glyphs[n].index);
00097 }
00098 }
00099 }
00100
00101 int
00102 Text::execute(GraphicDevice *gd, Matrix *matrix, Cxform *cxform)
00103 {
00104 return doText(gd, matrix, cxform, ShapeDraw, NULL, NULL);
00105 }
00106
00107 void
00108 Text::getRegion(GraphicDevice *gd, Matrix *matrix,
00109 void *id, ScanLineFunc scan_line_func)
00110 {
00111 doText(gd, matrix, 0, ShapeGetRegion, id, scan_line_func);
00112 }
00113
00114 void
00115 Text::getBoundingBox(Rect *bb, DisplayListEntry *e)
00116 {
00117 *bb = boundary;
00118 }
00119
00120 TextRecord *
00121 Text::getTextRecords()
00122 {
00123 return textRecords;
00124 }
00125
00126 int
00127 Text::doText(GraphicDevice *gd, Matrix *matrix, Cxform *cxform, ShapeAction action,
00128 void *id, ScanLineFunc scan_line_func)
00129 {
00130 TextRecord *tr;
00131 long x,y;
00132 SwfFont *font = 0;
00133 long fontHeight;
00134 Matrix tmat,fmat;
00135 long g;
00136
00137 x = y = 0;
00138 fontHeight = 0;
00139
00140
00141 tmat = (*matrix) * textMatrix;
00142
00143 for(tr = textRecords; tr; tr = tr ->next)
00144 {
00145 if (tr->flags & isTextControl) {
00146 if (tr->flags & textHasXOffset) {
00147 x = tr->xOffset;
00148 }
00149 if (tr->flags & textHasYOffset) {
00150 y = tr->yOffset;
00151 }
00152 if (tr->flags & textHasColor) {
00153 if (action == ShapeDraw) {
00154 if (cxform) {
00155 gd->setForegroundColor(cxform->getColor(tr->color));
00156 } else {
00157 gd->setForegroundColor(tr->color);
00158 }
00159 }
00160 }
00161 }
00162
00163 font = tr->font;
00164 fontHeight = tr->fontHeight;
00165
00166 fmat.a = fontHeight/1000.0;
00167 fmat.d = fontHeight/1000.0;
00168
00169 assert(font != 0);
00170 for (g = 0; g < tr->nbGlyphs; g++)
00171 {
00172 Shape *shape;
00173 Matrix cmat;
00174
00175 shape = font->getGlyph( tr->glyphs[g].index );
00176
00177 #ifdef PRINT
00178 printf("%c", font->getGlyphCode(tr->glyphs[g].index));
00179 #endif
00180
00181
00182 fmat.tx = x;
00183 fmat.ty = y;
00184
00185
00186 cmat = tmat * fmat;
00187
00188 if (action == ShapeDraw) {
00189 shape->execute(gd, &cmat, cxform);
00190 } else {
00191 shape->getRegion(gd, &cmat, id, scan_line_func);
00192 }
00193
00194
00195 x += tr->glyphs[g].xAdvance;
00196 }
00197 #ifdef PRINT
00198 printf("\n");
00199 #endif
00200 }
00201
00202 if (gd->showMore) {
00203 tmat = (*gd->adjust) * (*matrix);
00204
00205 long x1,x2,y1,y2;
00206
00207 x1 = boundary.xmin;
00208 y1 = boundary.ymin;
00209 x2 = boundary.xmax;
00210 y2 = boundary.ymax;
00211 gd->drawLine(tmat.getX(x1,y1),tmat.getY(x1,y1),tmat.getX(x2,y1),tmat.getY(x2,y1),FRAC);
00212 gd->drawLine(tmat.getX(x2,y1),tmat.getY(x2,y1),tmat.getX(x2,y2),tmat.getY(x2,y2),FRAC);
00213 gd->drawLine(tmat.getX(x2,y2),tmat.getY(x2,y2),tmat.getX(x1,y2),tmat.getY(x1,y2),FRAC);
00214 gd->drawLine(tmat.getX(x1,y2),tmat.getY(x1,y2),tmat.getX(x1,y1),tmat.getY(x1,y1),FRAC);
00215 }
00216
00217 return 0;
00218 }
00219
00221 TextRecord::TextRecord() {
00222 flags = (TextFlags)0;
00223 font = 0;
00224 fontHeight = 0;
00225 nbGlyphs = 0;
00226 glyphs = 0;
00227 xOffset = 0;
00228 yOffset = 0;
00229 }
00230
00231 TextRecord::~TextRecord() {
00232 if (nbGlyphs) delete glyphs;
00233 }
00234
00235 char *
00236 TextRecord::getText() {
00237 static char text[256];
00238 long g;
00239
00240 for(g=0; g < nbGlyphs; g++) {
00241 text[g] = glyphs[g].code;
00242 }
00243 text[g] = 0;
00244
00245 return text;
00246 }