00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "xymvtext.h"
00011 #include "cdimage.h"
00012 #include "xymath.h"
00013
00014 const char* xy_id_xyvtext_cpp="$Id: xymvtext.cpp,v 1.2 2000/01/17 13:45:39 camilo Exp $";
00015
00016 XYMultilineVectorText::XYMultilineVectorText (const char* text,
00017 XYCoordinate x,
00018 XYCoordinate y,
00019 long color,
00020 double width,
00021 double height,
00022 Typeface font,
00023 Style style,
00024 Alignment alignment,
00025 Orientation orientation,
00026 xybool underline,
00027 xybool visible)
00028 : XYText(text, x, y, color, font, style, alignment,
00029 orientation, underline, visible),
00030 _height(height),
00031 _width(width)
00032 {
00033 }
00034
00035 XYMultilineVectorText::XYMultilineVectorText (const char* text,
00036 XYCoordinate x,
00037 XYCoordinate y,
00038 xybool visible)
00039 : XYText(text, x, y, visible),
00040 _height(0.05),
00041 _width(0.05)
00042 {
00043 }
00044
00045 XYMultilineVectorText::XYMultilineVectorText (const char* text,
00046 long color,
00047 double width,
00048 double height,
00049 Typeface font,
00050 Style style,
00051 Alignment alignment,
00052 Orientation orientation,
00053 xybool underline,
00054 xybool visible)
00055 : XYText(text, color, font, style, alignment,
00056 orientation, underline, visible),
00057 _height(height),
00058 _width(width)
00059 {
00060 }
00061
00062 XYMultilineVectorText::XYMultilineVectorText (long color,
00063 double width,
00064 double height,
00065 Typeface font,
00066 Style style,
00067 Alignment alignment,
00068 Orientation orientation,
00069 xybool underline,
00070 xybool visible)
00071 : XYText(color, font, style, alignment,
00072 orientation, underline, visible),
00073 _height(height),
00074 _width(width)
00075 {
00076 }
00077
00078 XYMultilineVectorText::~XYMultilineVectorText (void)
00079 {
00080 }
00081
00082 void XYVectorText::draw (void)
00083 {
00084 draw (_xmin, _ymin, _xmax, _ymax);
00085 }
00086
00087 static void setAlignment (int a)
00088 {
00089
00090
00091 switch (a)
00092 {
00093 case XYText::north: cdTextAlignment(XYText::east); break;
00094 case XYText::south: cdTextAlignment(XYText::west); break;
00095 case XYText::east: cdTextAlignment(XYText::south); break;
00096 case XYText::west: cdTextAlignment(XYText::north); break;
00097 case XYText::northEast: cdTextAlignment(XYText::southEast); break;
00098 case XYText::northWest: cdTextAlignment(XYText::northEast); break;
00099 case XYText::southEast: cdTextAlignment(XYText::southWest); break;
00100 case XYText::southWest: cdTextAlignment(XYText::northWest); break;
00101 case XYText::center: cdTextAlignment(XYText::center); break;
00102 case XYText::baseLeft: cdTextAlignment(XYText::baseLeft); break;
00103 case XYText::baseCenter: cdTextAlignment(XYText::baseCenter); break;
00104 case XYText::baseRight: cdTextAlignment(XYText::baseRight); break;
00105 }
00106 }
00107
00108 static void xyVectorStyle (int style)
00109 {
00110
00111
00112
00113 switch (style)
00114 {
00115 case XYText::plain:
00116 cdLineWidth(1);
00117
00118
00119 break;
00120
00121 case XYText::bold:
00122 cdLineWidth(3);
00123
00124
00125 break;
00126
00127 case XYText::italic:
00128 cdLineWidth(1);
00129
00130
00131 break;
00132
00133 case XYText::boldItalic:
00134 cdLineWidth(3);
00135
00136
00137 break;
00138 }
00139 }
00140
00141 void XYVectorText::draw (int xmin, int ymin, int xmax, int ymax) const
00142 {
00143
00144 if (text() == NULL) return;
00145
00146 if (visible() == xyfalse) return;
00147
00148 int mode = cdClip(CD_CLIPON);
00149
00150
00151 int oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax;
00152 cdGetClipArea (&oldclip_xmin, &oldclip_xmax, &oldclip_ymin, &oldclip_ymax);
00153
00154
00155 cdClipArea(xmin, xmax, ymin, ymax);
00156
00157
00158 wdVectorFont(NULL);
00159 xyVectorStyle(style());
00160
00161
00162 cdTextAlignment(align());
00163 cdForeground(color());
00164
00165
00166 double wmm, hmm;
00167 int wpx,hpx;
00168 cdGetCanvasSize(&wpx, &hpx, &wmm, &hmm);
00169
00170 if (orientation() == horizontal)
00171 {
00172 wdVectorTextSize(width(), height(), "_");
00173 wdVectorTextDirection(0., 0., 1., 0.);
00174 }
00175 else
00176 {
00177 wdVectorTextSize(width(),height(), "_");
00178
00179
00180 if (orientation() == vertBotTop)
00181 {
00182 wdVectorTextDirection(0., 0., 0., 1.);
00183 setAlignment(align());
00184 }
00185 else
00186 {
00187 wdVectorTextDirection(0., 1., 0., 0.);
00188 setAlignment(align());
00189 }
00190 }
00191
00192 double xd, yd;
00193 position (&xd, &yd);
00194
00195
00196 wdVectorText(xd, yd, text());
00197
00198
00199 if (underline())
00200 {
00201
00202 cdLineStyle(CD_SOLID);
00203 wdLineWidth((style() == bold || style() == boldItalic) ? 1. : .7);
00204
00205
00206
00207 int bxmin, bxmax, bymin, bymax;
00208 boundingBox(bxmin, bymin, bxmax, bymax);
00209
00210 int descent;
00211 cdFontDim(0, 0, 0, &descent);
00212
00213 if (orientation() == horizontal)
00214 {
00215 cdLine(bxmin, bymin, bxmin, bymax);
00216 cdLine(bxmin, bymin, bxmax, bymin);
00217 cdLine(bxmax, bymin, bxmax, bymax);
00218 cdLine(bxmin, bymax, bxmax, bymax);
00219 }
00220
00221 else if (orientation() == vertBotTop)
00222 {
00223 cdLine(bxmin, bymin, bxmin, bymax);
00224 cdLine(bxmin, bymin, bxmax, bymin);
00225 cdLine(bxmax, bymin, bxmax, bymax);
00226 cdLine(bxmin, bymax, bxmax, bymax);
00227 }
00228
00229 else
00230 {
00231 cdLine(bxmin, bymin, bxmin, bymax);
00232 cdLine(bxmin, bymin, bxmax, bymin);
00233 cdLine(bxmax, bymin, bxmax, bymax);
00234 cdLine(bxmin, bymax, bxmax, bymax);
00235 }
00236
00237 }
00238
00239 cdClip(mode);
00240
00241 cdClipArea(oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax);
00242 }
00243
00244 void XYVectorText::boundingBox (int& xmin, int& ymin, int& xmax, int& ymax)
00245 const
00246 {
00247
00248 if (text() == NULL) return;
00249
00250
00251 int zero_x_canvas, zero_y_canvas;
00252 wdWorld2Canvas(0.0, 0.0, &zero_x_canvas, &zero_y_canvas);
00253
00254
00255 wdVectorFont(NULL);
00256 xyVectorStyle(style());
00257
00258 cdTextAlignment(align());
00259
00260
00261 double wmm, hmm;
00262 int wpx,hpx;
00263 cdGetCanvasSize(&wpx, &hpx, &wmm, &hmm);
00264
00265 if (orientation() == horizontal)
00266 {
00267 wdVectorTextSize(width(), height(), "_");
00268 wdVectorTextDirection(0., 0., 1., 0.);
00269 }
00270 else
00271 {
00272 wdVectorTextSize(width(), height(), "_");
00273
00274
00275 if (orientation() == vertBotTop)
00276 wdVectorTextDirection(0., 0., 0., 1.);
00277 else
00278 wdVectorTextDirection(0., 1., 0., 0.);
00279 }
00280
00281
00282 double d_width, d_height;
00283 wdGetVectorTextSize(text(), &d_width, &d_height);
00284
00285 int width, height;
00286 wdWorld2Canvas(d_width, d_height, &width, &height);
00287
00288 width -= zero_x_canvas - 1;
00289 height -= zero_y_canvas - 1;
00290
00291 if (orientation() != horizontal)
00292 {
00293 int aux = width;
00294 width = height;
00295 height = aux;
00296 }
00297
00298 int xi, yi;
00299 position (&xi, &yi);
00300
00301
00302 switch (align())
00303 {
00304 case north: xmin = xi - width / 2; ymin = yi - height; break;
00305 case south: xmin = xi - width / 2; ymin = yi; break;
00306 case east: xmin = xi - width; ymin = yi - height / 2; break;
00307 case west: xmin = xi; ymin = yi - height / 2; break;
00308 case northEast: xmin = xi - width; ymin = yi - height; break;
00309 case northWest: xmin = xi; ymin = yi - height; break;
00310 case southEast: xmin = xi - width; ymin = yi; break;
00311 case southWest: xmin = xi; ymin = yi; break;
00312 case center: xmin = xi - width / 2; ymin = yi - height / 2; break;
00313
00314 case baseLeft:
00315 int descent;
00316 cdFontDim(0, 0, 0, &descent);
00317
00318 xmin = xi;
00319 ymin = yi;
00320 break;
00321
00322 case baseCenter:
00323 cdFontDim(0, 0, 0, &descent);
00324
00325 xmin = xi - width / 2;
00326 ymin = yi ;
00327 break;
00328
00329 case baseRight:
00330 cdFontDim(0, 0, 0, &descent);
00331
00332 xmin = xi - width;
00333 ymin = yi ;
00334 break;
00335 }
00336
00337 xmax = xmin + width;
00338 ymax = ymin + height;
00339 }
00340