00001 #pragma ident "$Id: VGImage.cpp 1644 2009-01-27 19:26:14Z ckiesch $"
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "VGImage.hpp"
00029
00030 namespace vdraw
00031 {
00033 const double VGImage::PTS_PER_INCH=72;
00035 const double VGImage::PTS_PER_CM=72/2.54;
00036
00038 const double VGImage::US_LETTER_WIDTH_PTS=612;
00040 const double VGImage::US_LETTER_HEIGHT_PTS=792;
00041
00042
00044 const double VGImage::A3_WIDTH_PTS=841.9;
00046 const double VGImage::A3_HEIGHT_PTS=1190.6;
00047
00048
00050 const double VGImage::A4_WIDTH_PTS=595.3;
00052 const double VGImage::A4_HEIGHT_PTS=841.9;
00053
00055 const double VGImage::A5_WIDTH_PTS=419.5;
00057 const double VGImage::A5_HEIGHT_PTS=595.3;
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 void VGImage::rectangles(const Bitmap &bitmap)
00072 {
00073 double bw=bitmap.x2-bitmap.x1;
00074 double bh=bitmap.y2-bitmap.y1;
00075
00076 Bitmap::CMType which;
00077 int w, h;
00078 InterpolatedColorMap icm;
00079 ColorMap cm;
00080
00081 if(bitmap.getICM(&icm))
00082 {
00083 which = Bitmap::ICM;
00084 w = icm.getCols();
00085 h = icm.getRows();
00086 }
00087 else if(bitmap.getCM(&cm))
00088 {
00089 which = Bitmap::CM;
00090 w = cm.getCols();
00091 h = cm.getRows();
00092 }
00093
00094 double dx=bw/w;
00095 double dy=bh/h;
00096
00097 StrokeStyle ssb(Color::CLEAR);
00098
00099
00100
00101
00102 for(int r=(ll?0:h-1); (ll?r<h:r>=0); r+=(ll?1:-1))
00103 {
00104 for(int c=0; c<w; c++)
00105 {
00106 double x1=bitmap.x1+c*dx;
00107 double y1=bitmap.y1+(ll?r:h-r-1)*dy;
00108 Rectangle rect(x1,y1,x1+dx,y1+dy,ssb);
00109 if(which==Bitmap::CM)
00110 rect.setFillColor(cm.get(r,c));
00111 else
00112 rect.setFillColor(icm.get(r,c));
00113 rectangle(rect);
00114 }
00115 }
00116 }
00117
00118 VGImage::StyleType VGImage::getCorrectMarker(Marker *m, const Markable& mark)
00119 {
00120 if(mark.hasOwnMarker())
00121 {
00122 *m = mark.getMarker();
00123 if(!m->getColor().isClear())
00124 return SHAPE;
00125 else
00126 return CLEAR;
00127 }
00128 else if(defaults->useM)
00129 {
00130 *m = defaults->marker;
00131 if(!m->getColor().isClear())
00132 return DEFAULT;
00133 else
00134 return CLEAR;
00135 }
00136 return NONE;
00137 }
00138
00139 VGImage::StyleType VGImage::getCorrectStrokeStyle(StrokeStyle *s, const BasicShape& shape)
00140 {
00141 if(shape.hasOwnStrokeStyle())
00142 {
00143 *s = shape.getStrokeStyle();
00144 if(!s->getColor().isClear())
00145 return SHAPE;
00146 else
00147 return CLEAR;
00148 }
00149 else if(defaults->useSS)
00150 {
00151 *s = defaults->strokeStyle;
00152 if(!s->getColor().isClear())
00153 return DEFAULT;
00154 else
00155 return CLEAR;
00156 }
00157 return NONE;
00158 }
00159
00160 VGImage::StyleType VGImage::getCorrectFillColor(Color *c, const Fillable& shape)
00161 {
00162 if(shape.hasOwnFillColor())
00163 {
00164 *c = shape.getFillColor();
00165 if(!c->isClear())
00166 return SHAPE;
00167 else
00168 return CLEAR;
00169 }
00170 else if(defaults->useFC)
00171 {
00172 *c = defaults->fillColor;
00173 if(!c->isClear())
00174 return DEFAULT;
00175 else
00176 return CLEAR;
00177 }
00178 return NONE;
00179 }
00180
00181 VGImage::StyleType VGImage::getCorrectTextStyle(TextStyle *s, const Text& text)
00182 {
00183 if(text.hasOwnTextStyle())
00184 {
00185 *s = text.getStyle();
00186 if(!s->getColor().isClear())
00187 return SHAPE;
00188 else
00189 return CLEAR;
00190 }
00191 else if(defaults->useTS)
00192 {
00193 *s = defaults->textStyle;
00194 if(!s->getColor().isClear())
00195 return DEFAULT;
00196 else
00197 return CLEAR;
00198 }
00199 return NONE;
00200 }
00201 }