27 #include "../../../annotationtext/Attributes.h"
28 #include "../../../annotationtext/Element.h"
29 #include "../../../annotationtext/Text.h"
30 #include "../../../color/RGBAColor.h"
31 #include "../../../common/StringUtils.h"
32 #include "../../../geometry.h"
33 #include "../../../maptools/PtMarker.h"
34 #include "../../../raster.h"
42 #include <QPaintEngine>
45 #include <QResizeEvent>
52 : m_isDeviceOwner(true),
53 m_bgColor(Qt::transparent),
57 m_ptColorFrom(m_ptColor),
60 m_ptSelectionPatternImg(0),
61 m_ptClearPatternImg(0),
65 m_lnColor(Qt::transparent),
67 m_polyContourColor(Qt::transparent),
68 m_polyContourPen(Qt::gray),
70 m_polyBrush(Qt::magenta),
72 m_polyRotatedImage(0),
73 m_polyPatternWidth(16),
74 m_txtContourPen(Qt::black),
75 m_txtContourEnabled(false),
76 m_txtBrush(Qt::black),
77 m_txtLetterSpacing(1),
81 if(devType == QInternal::Pixmap)
83 QPixmap* p =
new QPixmap(w, h);
90 QImage* i =
new QImage(w, h, QImage::Format_ARGB32_Premultiplied);
99 : m_isDeviceOwner(false),
100 m_bgColor(Qt::transparent),
103 m_ptColor(Qt::black),
104 m_ptColorFrom(m_ptColor),
107 m_ptSelectionPatternImg(0),
108 m_ptClearPatternImg(0),
112 m_lnColor(Qt::transparent),
114 m_polyContourColor(Qt::transparent),
115 m_polyContourPen(Qt::gray),
116 m_polyColor(Qt::red),
117 m_polyBrush(Qt::magenta),
119 m_polyRotatedImage(0),
120 m_polyPatternWidth(16),
121 m_txtContourPen(Qt::black),
122 m_txtContourEnabled(false),
123 m_txtBrush(Qt::black),
124 m_txtLetterSpacing(1),
135 QPaintDevice* device = m_painter.device();
141 delete m_ptImgRotated;
142 delete m_ptClearPatternImg;
143 delete m_ptSelectionPatternImg;
148 const double& urx,
const double& ury)
150 double xScale =
static_cast<double>(getWidth()) / (urx - llx);
151 double yScale =
static_cast<double>(getHeight()) / (ury - lly);
154 m_matrix.scale(xScale, -yScale);
155 m_matrix.translate(-llx, -ury);
157 m_painter.setMatrix(m_matrix);
163 double ww = urx - llx;
164 double wh = ury - lly;
166 double widthByHeight =
static_cast<double>(getWidth()) / static_cast<double>(getHeight());
168 if(widthByHeight > ww / wh)
172 ww = wh * widthByHeight;
180 llx = llx - (ww - v) / 2.0;
188 wh = ww / widthByHeight;
196 lly = lly - (wh - v) / 2.0;
204 calcAspectRatio(envelope->
m_llx, envelope->
m_lly, envelope->
m_urx, envelope->
m_ury, hAlign, vAlign);
209 m_bgColor = QColor(color.
getRgba());
210 m_bgColor.setAlpha(qAlpha(color.
getRgba()));
212 m_painter.setWorldMatrixEnabled(
false);
213 m_painter.fillRect(m_painter.viewport(), m_bgColor);
214 m_painter.setWorldMatrixEnabled(
true);
219 return te::color::RGBAColor(m_bgColor.red(), m_bgColor.green(), m_bgColor.blue(), m_bgColor.alpha());
224 int devType = m_painter.device()->devType();
226 if(devType != QInternal::Image && devType != QInternal::Pixmap)
229 QPaintDevice* device = m_painter.device();
234 if(devType == QInternal::Image)
235 static_cast<QImage*
>(device)->fill(m_bgColor.rgba());
237 static_cast<QPixmap*
>(device)->fill(m_bgColor);
238 m_painter.begin(device);
247 m_painter.setMatrix(m_matrix);
249 m_ptPen.setColor(m_ptColor);
250 QRectF rec(QPoint(0., 0.), QPoint(m_ptWidth, m_ptWidth));
251 rec = m_matrix.inverted().mapRect(rec);
252 m_ptPen.setWidthF(rec.width());
257 int devType = m_painter.device()->devType();
259 if(devType != QInternal::Image && devType != QInternal::Pixmap)
265 if(devType == QInternal :: Pixmap)
267 QPixmap* pixmap =
static_cast<QPixmap*
>(m_painter.device());
270 pixmap =
new QPixmap(w, h);
271 pixmap->fill(m_bgColor);
272 m_painter.begin(pixmap);
276 QImage* image =
static_cast<QImage*
>(m_painter.device());
280 image =
new QImage(w, h, QImage::Format_ARGB32_Premultiplied);
281 image->fill(m_bgColor.rgba());
282 m_painter.begin(image);
288 return m_painter.device()->width();
293 return m_painter.device()->height();
304 draw(static_cast<const te::gm::MultiPolygon*>(geom));
311 draw(static_cast<const te::gm::Point*>(geom));
318 draw(static_cast<const te::gm::LineString*>(geom));
325 draw(static_cast<const te::gm::Polygon*>(geom));
332 draw(static_cast<const te::gm::MultiLineString*>(geom));
339 draw(static_cast<const te::gm::MultiPoint*>(geom));
346 draw(static_cast<const te::gm::GeometryCollection*>(geom));
355 m_pt.setX(point->
getX());
356 m_pt.setY(point->
getY());
360 QRectF rectf(0, 0, m_ptImg->width(), m_ptImg->height());
361 QPointF pc = m_matrix.map(m_pt);
362 pc.setX(pc.x() + m_ptHOffset);
363 pc.setY(pc.y() + m_ptVOffset);
364 rectf.moveCenter(pc);
366 m_painter.setWorldMatrixEnabled(
false);
367 if(m_erase && m_ptClearPatternImg)
368 m_painter.drawImage(rectf, *m_ptClearPatternImg);
369 else if(!m_erase && m_ptSelectionPatternImg)
370 m_painter.drawImage(rectf, *m_ptSelectionPatternImg);
371 m_painter.setWorldMatrixEnabled(
true);
378 p.setColor(Qt::black);
382 m_painter.setPen(m_ptPen);
383 m_painter.drawPoint(m_pt);
391 for(std::size_t i = 0; i < size; ++i)
392 draw(static_cast<const te::gm::Point*>(mpoint->
getGeometryN(i)));
397 if(m_lnPen.brush().style() != Qt::TexturePattern)
399 const std::size_t nPoints = line->
getNPoints();
400 QPolygonF qpol(nPoints);
401 memcpy(&(qpol[0]), (
double*)(line->
getCoordinates()), 16 * nPoints);
403 pen.setColor(m_lnColor);
404 m_painter.setPen(pen);
405 m_painter.setBrush(Qt::NoBrush);
406 m_painter.drawPolyline(qpol);
417 p1.setX(coords[0].x);
418 p1.setY(coords[0].y);
420 for(
register std::size_t i = 1; i != size; ++i)
422 p2.setX(coords[i].x);
423 p2.setY(coords[i].y);
428 pen.setColor(Qt::red);
429 if(m_lnPen.brush().style() == Qt::TexturePattern)
430 pen.setCapStyle(Qt::FlatCap);
431 m_painter.setPen(pen);
432 m_painter.setBrush(Qt::NoBrush);
433 m_painter.drawLine(p1, p2);
445 if(m_lnPen.brush().style() == Qt::TexturePattern)
449 QPoint dp1 = m_matrix.map(p1).toPoint();
450 QPoint dp2 = m_matrix.map(p2).toPoint();
451 int ddx = dp2.x() - dp1.x();
452 int ddy = dp2.y() - dp1.y();
453 if(abs(ddx) <= minPixels && abs(ddy) <= minPixels)
460 double dx = p2.x() - p1.x();
461 double dy = p2.y() - p1.y();
462 double distance = sqrt((dx * dx) + (dy * dy));
463 double scale = m_lnPen.widthF() / m_lnPen.brush().textureImage().height();
481 alfa = atan(dy/dx) * 180. / 3.14159265;
484 else if(alfa < 0 && dy < 0.)
490 QBrush brush(m_lnPen.brush());
493 pen.setCapStyle(Qt::FlatCap);
495 matrix.scale(scale, scale);
496 matrix.translate(m_lnPen.brush().textureImage().width()/2, -m_lnPen.brush().textureImage().height()/2.);
497 brush.setMatrix(matrix);
499 m_painter.setPen(pen);
502 m_painter.translate(p1);
503 m_painter.rotate(alfa);
504 m_painter.drawLine(0., 0., distance, 0.);
505 if(m_lnColor.alpha() != 0)
507 pen.setBrush(Qt::NoBrush);
508 pen.setColor(m_lnColor);
509 m_painter.setPen(pen);
510 m_painter.drawLine(0., 0., distance, 0.);
519 QPoint dp1 = m_matrix.map(p1).toPoint();
520 QPoint dp2 = m_matrix.map(p2).toPoint();
521 int ddx = dp2.x() - dp1.x();
522 int ddy = dp2.y() - dp1.y();
523 double dx = p2.x() - p1.x();
524 double dy = p2.y() - p1.y();
525 double distance = sqrt((dx * dx) + (dy * dy));
526 double scale = m_lnPen.widthF() / m_lnPen.brush().textureImage().height();
544 alfa = atan(dy/dx) * 180. / 3.14159265;
547 else if(alfa < 0 && dy < 0.)
553 QBrush brush(m_lnPen.brush());
556 pen.setCapStyle(Qt::FlatCap);
558 matrix.scale(scale, scale);
559 matrix.translate(m_lnPen.brush().textureImage().width()/2, -m_lnPen.brush().textureImage().height()/2.);
560 brush.setMatrix(matrix);
562 m_painter.setPen(pen);
565 m_painter.translate(p1);
566 m_painter.rotate(alfa);
567 m_painter.drawLine(0., 0., distance, 0.);
568 if(m_lnColor.alpha() != 0)
570 pen.setBrush(Qt::NoBrush);
571 pen.setColor(m_lnColor);
572 m_painter.setPen(pen);
573 m_painter.drawLine(0., 0., distance, 0.);
583 for(
size_t i = 0; i < size; ++i)
584 draw(static_cast<const te::gm::LineString*>(mline->
getGeometryN(i)));
595 std::vector<te::gm::LinearRing*> rings;
597 for(
register std::size_t i = 0; i != nRings; ++i)
600 rings.push_back(ring);
602 const std::size_t nPoints = ring->
getNPoints();
606 QPolygonF qpol(nPoints);
608 memcpy(&(qpol[0]), (
double*)(ring->
getCoordinates()), 16 * nPoints);
609 path.addPolygon(qpol);
659 m_painter.setPen(Qt::NoPen);
660 m_painter.setBrush(Qt::red);
661 m_painter.drawPath(path);
666 m_painter.setPen(Qt::NoPen);
667 if(m_polyImage && m_polyColor.alpha() != 255)
671 QPointF pc = m_matrix.map(recf.center());
672 int transx = pc.toPoint().x();
673 int transy = pc.toPoint().y();
675 QMatrix matrix = m_matrix.inverted();
676 double scale =
static_cast<double>(m_polyPatternWidth) / static_cast<double>(m_polyImage->width());
677 matrix.scale(scale, scale);
678 if(m_polyRotatedImage)
680 transx = transx % m_polyRotatedImage->width();
681 transy = transy % m_polyRotatedImage->height();
682 matrix.translate(transx, transy);
683 m_polyBrush.setMatrix(matrix);
684 m_polyBrush.setTextureImage(*m_polyRotatedImage);
688 transx = transx % m_polyImage->width();
689 transy = transy % m_polyImage->height();
690 matrix.translate(transx, transy);
691 m_polyBrush.setMatrix(matrix);
692 m_polyBrush.setTextureImage(*m_polyImage);
695 m_painter.setBrush(m_polyBrush);
697 if(m_polyContourPen.brush().style() == Qt::TexturePattern)
698 m_painter.setPen(Qt::NoPen);
700 m_painter.setPen(m_polyContourPen);
702 m_painter.drawPath(path);
706 QBrush brush(m_polyColor);
707 m_painter.setBrush(brush);
709 if(m_polyContourPen.brush().style() == Qt::TexturePattern)
710 m_painter.setPen(Qt::NoPen);
712 m_painter.setPen(m_polyContourPen);
714 m_painter.drawPath(path);
718 if(m_polyContourPen.brush().style() == Qt::TexturePattern)
720 std::vector<te::gm::LinearRing*>::iterator it;
721 for(it = rings.begin(); it != rings.end(); ++it)
736 m_polyContourPen.setColor(m_polyContourColor);
737 m_painter.setPen(m_polyContourPen);
738 m_painter.setBrush(Qt::NoBrush);
740 QPointF p1(coords[0].x, coords[0].y);
743 for(
register std::size_t i = 1; i != size; ++i)
745 p2.setX(coords[i].x);
746 p2.setY(coords[i].y);
748 if(m_polyContourPen.brush().style() != Qt::TexturePattern)
751 m_painter.drawLine(p1, p2);
757 QPoint dp1 = m_matrix.map(p1).toPoint();
758 QPoint dp2 = m_matrix.map(p2).toPoint();
759 int ddx = dp2.x() - dp1.x();
760 int ddy = dp2.y() - dp1.y();
761 if(ddx == 0 && ddy == 0)
768 double dx = p2.x() - p1.x();
769 double dy = p2.y() - p1.y();
770 double distance = sqrt((dx * dx) + (dy * dy));
771 double scale = m_polyContourPen.widthF() / m_polyContourPen.brush().textureImage().height();
789 alfa = atan(dy/dx) * 180. / 3.14159265;
792 else if(alfa < 0 && dy < 0.)
798 if(alfa > 90. && alfa <= 270.)
815 QBrush brush(m_polyContourPen.brush());
816 QPen pen(m_polyContourPen);
818 pen.setCapStyle(Qt::FlatCap);
820 matrix.scale(scale, scale);
821 matrix.translate(m_polyContourPen.brush().textureImage().width()/2, -m_polyContourPen.brush().textureImage().height()/2.);
822 brush.setMatrix(matrix);
824 m_painter.setPen(pen);
827 m_painter.translate(pf1);
828 m_painter.rotate(beta);
829 m_painter.drawLine(0., 0., distance, 0.);
830 if(m_polyContourColor.alpha() != 0)
832 pen.setBrush(Qt::NoBrush);
833 pen.setColor(m_polyContourColor);
834 m_painter.setPen(pen);
835 m_painter.drawLine(0., 0., distance, 0.);
845 QPoint dp1 = m_matrix.map(p1).toPoint();
846 QPoint dp2 = m_matrix.map(p2).toPoint();
847 int ddx = dp2.x() - dp1.x();
848 int ddy = dp2.y() - dp1.y();
849 double dx = p2.x() - p1.x();
850 double dy = p2.y() - p1.y();
851 double distance = sqrt((dx * dx) + (dy * dy));
852 double scale = m_polyContourPen.widthF() / m_polyContourPen.brush().textureImage().height();
870 alfa = atan(dy/dx) * 180. / 3.14159265;
873 else if(alfa < 0 && dy < 0.)
879 if(alfa > 90. && alfa <= 270.)
896 QBrush brush(m_polyContourPen.brush());
897 QPen pen(m_polyContourPen);
899 pen.setCapStyle(Qt::FlatCap);
901 matrix.scale(scale, scale);
902 matrix.translate(m_polyContourPen.brush().textureImage().width()/2, -m_polyContourPen.brush().textureImage().height()/2.);
903 brush.setMatrix(matrix);
905 m_painter.setPen(pen);
908 m_painter.translate(pf1);
909 m_painter.rotate(beta);
910 m_painter.drawLine(0., 0., distance, 0.);
911 if(m_polyContourColor.alpha() != 0)
913 pen.setBrush(Qt::NoBrush);
914 pen.setColor(m_polyContourColor);
915 m_painter.setPen(pen);
916 m_painter.drawLine(0., 0., distance, 0.);
925 for(std::size_t i = 0; i < size; ++i)
926 draw(static_cast<te::gm::Polygon*>(mpoly->
getGeometryN(i)));
932 for(
size_t i = 0; i < size; ++i)
938 int devType = m_painter.device()->devType();
940 if(devType != QInternal::Image && devType != QInternal::Pixmap)
943 static_cast<QPixmap*
>(m_painter.device())->save(fileName,
GetFormat(t), quality);
948 int devType = m_painter.device()->devType();
950 if(devType != QInternal::Image && devType != QInternal::Pixmap)
954 QBuffer buffer(&bytes);
955 buffer.open(QIODevice::WriteOnly);
987 int nbytes = bytes.size();
989 char* result =
new char[nbytes];
991 memcpy(result, bytes.data(), nbytes);
1000 int devType = m_painter.device()->devType();
1002 if(devType != QInternal::Image && devType != QInternal::Pixmap)
1007 if(devType == QInternal::Pixmap)
1008 img =
static_cast<QPixmap*
>(m_painter.device())->toImage();
1010 img = *(
static_cast<QImage*
>(m_painter.device()));
1012 if(x == 0 && y == 0 && w == 0 && y == 0)
1014 int width = img.width();
1015 int height = img.height();
1018 for(
int i = 0; i < height; ++i)
1022 unsigned char* u = img.scanLine(i);
1024 for(
int j = 0; j < width; ++j)
1026 QRgb* qrgb = (QRgb*)(u + (j << 2));
1029 colors[i][j] = rgba;
1035 img = img.copy(x, y, w, h);
1038 for(
int i = 0; i < h; ++i)
1042 unsigned char* u = img.scanLine(i);
1044 for(
int j = 0; j < w; ++j)
1046 QRgb* qrgba = (QRgb*)(u+(j<<2));
1047 QRgb value = *qrgba;
1049 colors[i][j] = rgba;
1064 drawImage(0, 0, src, size, t);
1069 drawImage(0, 0, src, w, h);
1077 pix.loadFromData((
unsigned char*)src, size, f);
1079 m_painter.setWorldMatrixEnabled(
false);
1080 m_painter.drawPixmap(x, y, pix);
1081 m_painter.setWorldMatrixEnabled(
true);
1086 QImage img(w, h, QImage::Format_ARGB32);
1088 for(
int l = 0; l < h; ++l)
1090 for(
int c = 0; c < w; ++c)
1092 QRgb val = qRgba(src[l][c].getRed(), src[l][c].getGreen(), src[l][c].getBlue(), src[l][c].getAlpha());
1094 img.setPixel(c, l, val);
1098 m_painter.setWorldMatrixEnabled(
false);
1099 m_painter.drawImage(x, y, img);
1100 m_painter.setWorldMatrixEnabled(
true);
1108 pix.loadFromData((
unsigned char*)src, size, f);
1110 m_painter.setWorldMatrixEnabled(
false);
1111 m_painter.drawPixmap(x, y, w, h, pix);
1112 m_painter.setWorldMatrixEnabled(
true);
1117 QImage img(srcw, srch, QImage::Format_RGB32);
1119 for(
int l = 0; l < srch; ++l)
1120 for(
int c = 0; c < srcw; ++c)
1121 img.setPixel(c, l, src[l][c].
getRgba());
1123 m_painter.setWorldMatrixEnabled(
false);
1124 m_painter.drawImage(QRect(x, y, w, h), img, QRect(0, 0, srcw, srch));
1125 m_painter.setWorldMatrixEnabled(
true);
1128 void te::qt::widgets::Canvas::drawImage(
int x,
int y,
int w,
int h,
char* src, std::size_t size,
te::map::ImageType t,
int sx,
int sy,
int sw,
int sh)
1133 pix.loadFromData((
unsigned char*)src, size, f);
1135 m_painter.setWorldMatrixEnabled(
false);
1136 m_painter.drawPixmap(x, y, w, h, pix, sx, sy, sw, sh);
1137 m_painter.setWorldMatrixEnabled(
true);
1142 QImage img(sw, sh, QImage::Format_RGB32);
1147 for(
int l = sy, li = 0; l < ssh; ++l, ++li)
1148 for(
int c = sx, ci = 0; c < ssw; ++c, ++ci)
1149 img.setPixel(ci, li, src[l][c].
getRgba());
1151 m_painter.setWorldMatrixEnabled(
false);
1152 m_painter.drawImage(QRect(x, y, w, h), img, QRect(0, 0, sw, sh));
1153 m_painter.setWorldMatrixEnabled(
true);
1161 drawImage(x, y, sw, sh, src, 0, 0, sw, sh, opacity);
1167 int iw = std::min(sw, w);
1168 int ih = std::min(sh, h);
1170 QImage img(iw, ih, QImage::Format_ARGB32);
1175 double sl = std::max(1.0, sh/(
double)h);
1176 double sr = std::max(1.0, sw/(
double)w);
1180 for(
int li = 0; li < ih; dl+=sl, ++li)
1183 for(
int ri = 0; ri < iw; dr+=sr, ++ri)
1185 r =
static_cast<int> (dr);
1186 l =
static_cast<int> (dl);
1194 img.setPixel(ri, li, val);
1200 m_painter.setWorldMatrixEnabled(
false);
1201 m_painter.drawImage(QRect(x, y, w, h), img, QRect(0, 0, iw, ih));
1202 m_painter.setWorldMatrixEnabled(
true);
1207 m_painter.setWorldMatrixEnabled(
false);
1208 m_painter.drawPoint(x, y);
1209 m_painter.setWorldMatrixEnabled(
true);
1215 c.setAlpha(qAlpha(color.
getRgba()));
1217 m_painter.setPen(c);
1219 m_painter.setWorldMatrixEnabled(
false);
1220 m_painter.drawPoint(x, y);
1221 m_painter.setWorldMatrixEnabled(
true);
1225 const std::string& txt,
1231 drawText(p, txt, angle, hAlign, vAlign);
1235 const std::string& txt,
1240 drawText(p->
getX(), p->
getY(), txt, angle, hAlign, vAlign);
1244 const std::string& txt,
1250 pf = m_matrix.map(pf);
1251 QPoint p = pf.toPoint();
1252 drawText(p, txt, angle, hAlign, vAlign);
1264 while(txt->
getElements()[i]->getAttributes() == 0 && i < size)
1279 m_font.setFamily(family.c_str());
1283 setTextPointSize(pointSize);
1301 m_font.setStyle(QFont::StyleNormal);
1303 m_font.setStyle(QFont::StyleOblique);
1305 m_font.setStyle(QFont::StyleItalic);
1311 m_font.setOverline(
false);
1312 m_font.setUnderline(
false);
1313 m_font.setStrikeOut(
false);
1316 m_font.setOverline(
true);
1318 m_font.setUnderline(
true);
1320 m_font.setStrikeOut(
true);
1322 m_painter.setFont(m_font);
1334 QColor qcor(cor.c_str());
1336 qcor.setAlpha(opacity);
1337 m_txtBrush = QBrush(qcor);
1341 QColor qscor(sCor.c_str());
1343 qscor.setAlpha(sOpacity);
1344 m_txtContourPen = QPen(qscor);
1347 m_txtContourPen.setWidth(10. * atr->
getTextStrokeWidth() * (double)getResolution() / 72.);
1369 std::string text = element->
getValue();
1370 size_t p = text.find(
"\n");
1373 if(p != std::string::npos)
1375 QFontMetrics fm = QFontMetrics(m_font);
1376 QRectF rec(fm.boundingRect(
"A"));
1377 hline = QRectF(m_matrix.inverted().mapRect(rec)).height();
1378 hline = hline + hline * m_txtLineSpacing;
1381 while(p != std::string::npos)
1383 std::string t = text.substr(0, p);
1384 drawText(pclone, t, 0., hAlign, vAlign);
1385 text = text.substr(p+1);
1386 p = text.find(
"\n");
1387 pclone->
setY(pclone->
getY() - hline);
1390 drawText(pclone, text, 0., hAlign, vAlign);
1392 drawText(pt, text, 0., hAlign, vAlign);
1407 return getTextBoundary(p, txt, angle, hAlign, vAlign);
1412 return getTextBoundary(p->
getX(), p->
getY(), txt, angle, hAlign, vAlign);
1418 pf = m_matrix.map(pf);
1419 QPoint p = pf.toPoint();
1420 return getTextBoundary(p, txt, angle, hAlign, vAlign);
1425 m_txtBrush.setStyle(Qt::SolidPattern);
1427 m_txtBrush.setColor(cor);
1432 QColor cor(m_txtBrush.color().red(), m_txtBrush.color().green(), m_txtBrush.color().blue(), opacity);
1433 m_txtBrush.setColor(cor);
1438 m_font.setFamily(family.c_str());
1443 double resolution = 0.0;
1445 if(m_painter.device()->devType() == QInternal::Printer)
1446 resolution = static_cast<QPrinter*>(m_painter.device())->resolution();
1448 resolution = m_painter.device()->logicalDpiY();
1450 double PointSize = psize * resolution / 72.0;
1452 m_font.setPointSizeF(PointSize);
1457 m_font.setStyle((QFont::Style)style);
1467 m_font.setWeight((QFont::Weight)wg);
1472 m_font.setStretch(stretch);
1477 m_font.setUnderline(b);
1482 m_font.setOverline(b);
1487 m_font.setStrikeOut(b);
1501 cor.setAlpha(qAlpha(color.
getRgba()));
1502 m_txtContourPen.setColor(cor);
1507 m_txtContourEnabled = b;
1512 QColor cor(m_txtContourPen.color().red(), m_txtContourPen.color().green(), m_txtContourPen.color().blue(), opacity);
1513 m_txtContourPen.setColor(cor);
1518 m_txtContourPen.setWidth(width);
1527 m_txtLineSpacing = spacing;
1533 cor.setAlpha(qAlpha(color.
getRgba()));
1534 if(m_ptColor == cor)
1538 m_ptPen.setColor(m_ptColor);
1540 if(m_ptColorFrom != m_ptColor && m_ptImg)
1541 createPointPatterns();
1550 QRectF rec(QPoint(0., 0.), QPoint(m_ptWidth, m_ptWidth));
1551 rec = m_matrix.inverted().mapRect(rec);
1552 m_ptPen.setWidthF(rec.width());
1556 double scale = (double)m_ptWidth / (
double)m_ptImg->width();
1557 int h = m_ptImg->height() * scale;
1558 QImage* ima =
new QImage(m_ptImg->scaled(m_ptWidth, h));
1562 createPointPatterns();
1570 if(pattern == 0 || ncols == 0 || nrows == 0)
1573 m_ptImg =
GetImage(pattern, ncols, nrows);
1574 int width = m_ptImg->width();
1577 createPointPatterns();
1585 if(pattern == 0 || size == 0)
1588 m_ptImg =
new QImage();
1592 if(m_ptImg->loadFromData((
const uchar*)pattern, size, format) ==
false)
1599 int width = m_ptImg->width();
1602 createPointPatterns();
1607 m_ptRotation = angle;
1608 createPointPatterns();
1616 updateAlpha(*m_ptImg, opacity);
1617 createPointPatterns();
1623 cor.setAlpha(qAlpha(color.
getRgba()));
1638 m_lnPen.setBrush(Qt::NoBrush);
1642 QImage* img =
GetImage(pattern, ncols, nrows);
1644 if(img->isNull() ==
false)
1647 brush.setTextureImage(*img);
1648 m_lnPen.setBrush(brush);
1657 m_lnPen.setBrush(Qt::NoBrush);
1665 bool result = img.loadFromData((
const uchar*)pattern, size, format);
1667 if(result && img.isNull() ==
false)
1670 brush.setTextureImage(img);
1671 m_lnPen.setBrush(brush);
1677 QBrush brush = m_lnPen.brush();
1678 QImage img = brush.textureImage();
1683 matrix.translate(img.width()/2, img.height()/2);
1684 matrix.rotate(angle);
1685 QImage imgRot = img.transformed(matrix);
1687 brush.setTextureImage(imgRot);
1688 m_lnPen.setBrush(brush);
1693 QBrush brush = m_lnPen.brush();
1694 QImage img = brush.textureImage();
1699 updateAlpha(img, opacity);
1701 brush.setTextureImage(img);
1702 m_lnPen.setBrush(brush);
1707 m_lnPen.setStyle((Qt::PenStyle)style);
1712 setLineDashStyle(m_lnPen, style);
1717 m_lnPen.setCapStyle((Qt::PenCapStyle)style);
1722 m_lnPen.setJoinStyle((Qt::PenJoinStyle)style);
1727 QRectF rec(QPoint(0., 0.), QPoint(w, w));
1728 rec = m_matrix.inverted().mapRect(rec);
1729 m_lnPen.setWidthF(rec.width());
1735 cor.setAlpha(qAlpha(color.
getRgba()));
1743 m_polyBrush.setStyle(Qt::NoBrush);
1745 delete m_polyRotatedImage;
1747 m_polyRotatedImage = 0;
1754 m_polyImage =
GetImage(pattern, ncols, nrows);
1755 if(m_polyImage->isNull())
1760 m_polyPatternWidth = m_polyImage->width();
1780 m_polyBrush.setStyle(Qt::NoBrush);
1782 delete m_polyRotatedImage;
1784 m_polyRotatedImage = 0;
1789 m_polyImage =
new QImage();
1791 bool result = m_polyImage->loadFromData((
const uchar*)pattern, size, format);
1817 m_polyPatternWidth = w;
1819 if(m_polyPatternWidth == 0.)
1820 m_polyPatternWidth = 1.;
1838 matrix.translate((
double)m_polyImage->width()/2., (double)m_polyImage->height()/2.);
1839 matrix.rotate(angle);
1841 if(m_polyRotatedImage == 0)
1842 m_polyRotatedImage =
new QImage();
1843 *m_polyRotatedImage = m_polyImage->transformed(matrix);
1849 QImage img = m_polyBrush.textureImage();
1855 updateAlpha(*m_polyImage, opacity);
1856 if(m_polyRotatedImage)
1857 updateAlpha(*m_polyRotatedImage, opacity);
1865 cor.setAlpha(qAlpha(color.
getRgba()));
1874 m_polyContourPen.setColor(cor);
1875 m_polyContourColor = cor;
1882 m_polyContourPen.setBrush(Qt::NoBrush);
1886 QImage* img =
GetImage(pattern, ncols, nrows);
1888 if(img->isNull() ==
false)
1891 brush.setTextureImage(*img);
1892 m_polyContourPen.setBrush(brush);
1901 m_polyContourPen.setBrush(Qt::NoBrush);
1909 bool result = img.loadFromData((
const uchar*)pattern, size, format);
1911 if(result && img.isNull() ==
false)
1914 brush.setTextureImage(img);
1915 m_polyContourPen.setBrush(brush);
1921 QRectF rec(QPoint(0., 0.), QPoint(w, w));
1922 rec = m_matrix.inverted().mapRect(rec);
1923 m_polyContourPen.setWidthF(rec.width());
1928 QBrush brush = m_polyContourPen.brush();
1929 QImage img = brush.textureImage();
1934 matrix.translate(img.width()/2, img.height()/2);
1935 matrix.rotate(angle);
1936 QImage imgRot = img.transformed(matrix);
1938 brush.setTextureImage(imgRot);
1939 m_polyContourPen.setBrush(brush);
1944 QBrush brush = m_polyContourPen.brush();
1945 QImage img = brush.textureImage();
1950 updateAlpha(img, opacity);
1952 brush.setTextureImage(img);
1953 m_polyContourPen.setBrush(brush);
1958 m_polyContourPen.setStyle((Qt::PenStyle)style);
1963 setLineDashStyle(m_polyContourPen, style);
1968 m_polyContourPen.setCapStyle((Qt::PenCapStyle)style);
1973 m_polyContourPen.setJoinStyle((Qt::PenJoinStyle)style);
1977 const std::string& txt,
1986 QString qtx(txt.c_str());
1988 QFontMetrics fm(m_font);
1989 QRectF rec(fm.boundingRect(qtx));
1994 ax = rec.center().x();
2001 ay = rec.center().y();
2007 path.addText(-ax, -ay, m_font, qtx);
2009 m_painter.resetMatrix();
2010 m_painter.translate(p);
2012 m_painter.rotate(angle);
2014 if(m_txtContourEnabled)
2016 m_painter.setBrush(Qt::NoBrush);
2017 m_painter.setPen(m_txtContourPen);
2018 m_painter.drawPath(path);
2021 m_painter.setPen(Qt::NoPen);
2022 m_painter.fillPath(path, m_txtBrush);
2024 m_painter.drawPath(path);
2026 m_painter.setMatrix(m_matrix);
2037 QString qtx(txt.c_str());
2039 QFontMetrics fm(m_font);
2040 QRectF rec(fm.boundingRect(qtx));
2041 QRectF wrec(m_matrix.inverted().mapRect(rec));
2046 ax = wrec.center().x();
2054 ay = wrec.center().y();
2058 ay = m_matrix.inverted().map(QPoint(0, 0)).y();
2060 wrec.translate(-ax, -ay);
2061 QPolygonF polf(wrec);
2069 QPointF wp = m_matrix.inverted().map(QPointF(p));
2070 polf.translate(wp.x(), wp.y());
2076 lr->
setPoint(0, polf.at(0).x(), polf.at(0).y());
2077 lr->
setPoint(1, polf.at(1).x(), polf.at(1).y());
2078 lr->
setPoint(2, polf.at(2).x(), polf.at(2).y());
2079 lr->
setPoint(3, polf.at(3).x(), polf.at(3).y());
2085 if(m_painter.device()->devType() == QInternal::Pixmap)
2086 return static_cast<QPixmap*>(m_painter.device());
2093 if(m_painter.device()->devType() == QInternal::Image)
2094 return static_cast<QImage*>(m_painter.device());
2101 return m_painter.device();
2109 delete m_painter.device();
2111 m_isDeviceOwner = takeOwnerShip;
2112 m_painter.begin(device);
2117 if(m_painter.device()->devType() == QInternal::Printer)
2118 return static_cast<QPrinter*>(m_painter.device())->resolution();
2120 return m_painter.device()->logicalDpiX();
2130 m_painter.setRenderHint(hint, on);
2135 assert(style.size() % 2 == 0);
2136 QVector<qreal> pattern;
2137 for(std::size_t i = 0; i < style.size(); ++i)
2138 pattern << style[i];
2139 pen.setDashPattern(pattern);
2144 int o = opacity << 24;
2145 for(
int i = 0; i < img.height(); ++i)
2147 unsigned char* u = img.scanLine(i);
2148 for(
int j = 0; j < img.width(); ++j)
2150 QRgb* v = (QRgb*)(u + (j << 2));
2151 if(qAlpha(*v) <= opacity)
2153 *v = *v & 0x00ffffff;
2161 delete m_ptSelectionPatternImg;
2162 delete m_ptClearPatternImg;
2163 delete m_ptImgRotated;
2164 m_ptSelectionPatternImg = 0;
2165 m_ptClearPatternImg = 0;
2172 m.rotate(m_ptRotation);
2173 m_ptImgRotated =
new QImage(m_ptImg->transformed(m));
2175 m_ptColorFrom = m_ptColor;
2177 double a = (double)m_ptColor.alpha() / (double)255;
2178 double b = (double)(255 - m_ptColor.alpha()) / (
double)255;
2179 int width = m_ptImgRotated->width();
2180 int height = m_ptImgRotated->height();
2181 m_ptSelectionPatternImg =
new QImage(width, height, QImage::Format_ARGB32);
2182 m_ptClearPatternImg =
new QImage(width, height, QImage::Format_ARGB32);
2183 for(
int i = 0; i < height; ++i)
2185 unsigned char* u = m_ptImgRotated->scanLine(i);
2186 unsigned char* uu = m_ptSelectionPatternImg->scanLine(i);
2187 unsigned char* uuu = m_ptClearPatternImg->scanLine(i);
2188 for(
int j = 0; j < width; ++j)
2190 QRgb* v = (QRgb*)(u + (j << 2));
2191 QRgb* vv = (QRgb*)(uu + (j << 2));
2192 QRgb* vvv = (QRgb*)(uuu + (j << 2));
2195 *vv = qRgba(0, 0, 0, 0);
2196 *vvv = qRgba(0, 0, 0, 0);
2200 int red = (int)((
double)m_ptColor.red() * a + (double)qRed(*v) * b);
2201 int green = (int)((
double)m_ptColor.green() * a + (double)qGreen(*v) * b);
2202 int blue = (int)((
double)m_ptColor.blue() * a + (double)qBlue(*v) * b);
2203 *vv = qRgba(red, green, blue, qAlpha(*v));
2204 *vvv = qRgba(255, 255, 255, 255);
2212 m_painter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
2218 m_painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
2226 m_painter.setMatrix(m_matrix);
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
ImageType
This enum specifies the possible input and output image formats supported by the canvas API...
MultiPolygon is a MultiSurface whose elements are Polygons.
TextDecoration getDecoration() const
It returns the font decoration.
const double & getLetterSpacing() const
It returns the letter spacing.
FontWeight
Font weight for drawing text.
const double & getTextOpacity() const
It returns the text opacity.
int getRed() const
It returns the red component color value (a value from 0 to 255).
Coord2D * getCoordinates() const
It returns a pointer to the internal array of coordinates.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
const std::string & getFamily() const
It returns the font family.
LineJustification
Line justification for drawing multi line text.
FontStyle
Font style for drawing text.
const std::string & getTextColor() const
It returns the text color.
const double & getPointSize() const
It returns the font point size.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
double m_urx
Upper right corner x-coordinate.
int getGreen() const
It returns the green component color value (a value from 0 to 255).
const std::string & getTextStrokeColor() const
It returns the text stroke color.
double getWidth() const
It returns the envelope width.
A Text may contain 1 or more Text Elements.
An utility struct for representing 2D coordinates.
HorizontalAlignment getHorizontalAlignment() const
It returns the horizontal text alignment.
const Attributes * getAttributes() const
it returns the text attributes.
const te::gm::Geometry * getLeaderLine() const
it returns the text leader line.
FontStyle getStyle() const
It returns the font style.
AlignType
This enum contains values to control the alignment of components (like Canvas and MapDisplay)...
TextDecoration
Text decoration for drawing text.
LineCapStyle
This enum encodes enumerated values telling how line strings should be capped (at the two ends of the...
A LinearRing is a LineString that is both closed and simple.
MultiPoint is a GeometryCollection whose elements are restricted to points.
double m_llx
Lower left corner x-coordinate.
LineString is a curve with linear interpolation between points.
HorizontalAlignment
Horizontal alignment for drawing text.
const double & getY() const
It returns the Point y-coordinate value.
A point with x and y coordinate values.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
VerticalAlignment getVerticalAlignment() const
It returns the vertical text alignment.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
virtual te::dt::AbstractData * clone() const
It clones the point.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
const std::vector< Element * > & getElements() const
It returns the elements.
const double & getLineSpacing() const
It returns the multi line spacing.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
std::size_t getNPoints() const
It returns the number of points (vertexes) in the linestring.
const double & getTextStrokeOpacity() const
It returns the text stroke opacity.
const std::string & getValue() const
it returns the text string.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
FontWeight getWeight() const
It returns the font weight.
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
double m_lly
Lower left corner y-coordinate.
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
MultiLineString is a MultiCurve whose elements are LineStrings.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
LineDashStyle
This enum encodes enumerated values telling how lines should be drawn. e.g. as a plain line or dash l...
LineJoinStyle
This enum encodes enumerated values telling how line strings should be joined (between line segments)...
VerticalAlignment
Vertical alignment for drawing text.
double m_ury
Upper right corner y-coordinate.
const te::gm::Geometry * getLocation() const
it returns the text location.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
void setY(const double &y)
It sets the Point y-coordinate value.
It is a collection of other geometric objects.
double getHeight() const
It returns the envelope height.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
const double & getTextStrokeWidth() const
It returns the text stroke width.
const double & getX() const
It returns the Point x-coordinate value.
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.