diff --git a/3rdparty/qwtplot3d/src/qwt3d_io_gl2ps.cpp b/3rdparty/qwtplot3d/src/qwt3d_io_gl2ps.cpp index dd1b7e4..8ce3c8c 100755 --- a/3rdparty/qwtplot3d/src/qwt3d_io_gl2ps.cpp +++ b/3rdparty/qwtplot3d/src/qwt3d_io_gl2ps.cpp @@ -6,12 +6,12 @@ #include <locale.h> #include "qwt3d_openglhelper.h" -#include "../3rdparty/gl2ps/gl2ps.h" +#include <gl2ps.h> #include "qwt3d_io_gl2ps.h" #include "qwt3d_plot.h" - -#include <QFileInfo> -#include <QMessageBox> + +#include <QFileInfo> +#include <QMessageBox> using namespace Qwt3D; @@ -32,7 +32,7 @@ VectorWriter::VectorWriter() sortmode_(SIMPLESORT), landscape_(VectorWriter::AUTO), textmode_(VectorWriter::PIXEL), - texfname_(""), + texfname_(""), export_size_(QSize()) {} @@ -132,10 +132,10 @@ bool VectorWriter::operator()(Plot3D* plot, QString const& fname) char* tmploc = setlocale(LC_ALL, "C"); - plot->makeCurrent(); - - QSize size = plot->size(); - if (export_size_.isValid()) + plot->makeCurrent(); + + QSize size = plot->size(); + if (export_size_.isValid()) plot->resize(export_size_); GLint bufsize = 0, state = GL2PS_OVERFLOW; @@ -220,7 +220,7 @@ bool VectorWriter::operator()(Plot3D* plot, QString const& fname) return false; } - plot->setExportingVector(true, gl2ps_format_); + plot->setExportingVector(true, gl2ps_format_); while( state == GL2PS_OVERFLOW ){ bufsize += 2*1024*1024; @@ -236,9 +236,9 @@ bool VectorWriter::operator()(Plot3D* plot, QString const& fname) // extra TeX file if (textmode_ == TEX) - { - QFileInfo fi(fname); - QString fn = fname; + { + QFileInfo fi(fname); + QString fn = fname; fn = fn.remove(fi.suffix()) + "tex"; fp = fopen(QWT3DLOCAL8BIT(fn), "wb"); @@ -268,9 +268,9 @@ bool VectorWriter::operator()(Plot3D* plot, QString const& fname) Label::useDeviceFonts(false); - setlocale(LC_ALL, tmploc); - if (export_size_.isValid()) - plot->resize(size);// restore original plot size + setlocale(LC_ALL, tmploc); + if (export_size_.isValid()) + plot->resize(size);// restore original plot size return true; } @@ -324,20 +324,20 @@ GLint Qwt3D::drawDevicePixels(GLsizei width, GLsizei height, if(format != GL_RGBA || type != GL_UNSIGNED_BYTE) return GL2PS_ERROR; - - GLfloat* convertedpixel = (GLfloat*)malloc(4 * width * height * sizeof(GLfloat)); - if (!convertedpixel) - return GL2PS_ERROR; - - GLubyte* px = (GLubyte*)pixels; - for (int i = 0; i != 4*width*height; i += 4){ - convertedpixel[i] = px[i] / 255.0; - convertedpixel[i+1] = px[i+1] / 255.0; - convertedpixel[i+2] = px[i+2] / 255.0; - convertedpixel[i+3] = px[i+3] / 255.0; - } - GLint ret = gl2psDrawPixels(width, height, 0, 0, GL_RGBA, GL_FLOAT, convertedpixel); - free(convertedpixel); + + GLfloat* convertedpixel = (GLfloat*)malloc(4 * width * height * sizeof(GLfloat)); + if (!convertedpixel) + return GL2PS_ERROR; + + GLubyte* px = (GLubyte*)pixels; + for (int i = 0; i != 4*width*height; i += 4){ + convertedpixel[i] = px[i] / 255.0; + convertedpixel[i+1] = px[i+1] / 255.0; + convertedpixel[i+2] = px[i+2] / 255.0; + convertedpixel[i+3] = px[i+3] / 255.0; + } + GLint ret = gl2psDrawPixels(width, height, 0, 0, GL_RGBA, GL_FLOAT, convertedpixel); + free(convertedpixel); return ret; } diff --git a/3rdparty/qwtplot3d/src/qwt3d_label.cpp b/3rdparty/qwtplot3d/src/qwt3d_label.cpp index c495a0f..2107cf8 100755 --- a/3rdparty/qwtplot3d/src/qwt3d_label.cpp +++ b/3rdparty/qwtplot3d/src/qwt3d_label.cpp @@ -1,7 +1,7 @@ #include <qbitmap.h> #include "qwt3d_label.h" -#include "qwt3d_plot.h" -#include "../3rdparty/gl2ps/gl2ps.h" +#include "qwt3d_plot.h" +#include <gl2ps.h> using namespace Qwt3D; @@ -32,9 +32,9 @@ void Label::init() setColor(0,0,0); font_ = QFont(); anchor_ = BottomLeft; - gap_ = 0; - width_ = 0.0; - height_ = 0.0; + gap_ = 0; + width_ = 0.0; + height_ = 0.0; } void Label::useDeviceFonts(bool val) @@ -88,66 +88,66 @@ void Label::setRelPosition(Tuple rpos, ANCHOR a) getMatrices(modelMatrix, projMatrix, viewport); beg_ = relativePosition(Triple(rpos.x, rpos.y, ot)); setPosition(beg_, a); -} - -QImage Label::createImage(double angle) -{ - QRect r = QRect(QPoint(0, 0), QFontMetrics(font_).size(Qwt3D::SingleLine, text_)); - int textWidth = r.width(); - int textHeight = r.height(); - - double aux_a = angle; - if (aux_a > 270) - aux_a -= 270; - if (aux_a >= 180) - aux_a -= 180; - if (aux_a > 90) - aux_a -= 90; - - double rad = aux_a*M_PI/180.0; - - int w = 0, h = 0; - if ((angle >= 0 && angle <= 90) || (angle >= 180 && angle <= 270)){ - w = qRound(fabs(textWidth*cos(rad) + textHeight*sin(rad))); - h = qRound(fabs(textWidth*sin(rad) + textHeight*cos(rad))); - } else { - w = qRound(fabs(textWidth*sin(rad) + textHeight*cos(rad))); - h = qRound(fabs(textWidth*cos(rad) + textHeight*sin(rad))); - } - - width_ = w; - height_ = h; - - QPixmap pm_ = QPixmap(w, h); - - if (plot() && plot()->isExportingVector() && plot()->vectorExportFormat() != GL2PS_PDF){ - Qwt3D::RGBA rgba = plot()->backgroundRGBAColor(); - pm_.fill(GL2Qt(rgba.r, rgba.g, rgba.b)); - } else - pm_.fill(Qt::transparent); - - QPainter p(&pm_); - - if (angle >= 270) - p.translate(textHeight*cos(rad), 0.0); - else if (angle >= 180) - p.translate(w, textHeight*cos(rad)); - else if (angle > 90) - p.translate(textWidth*sin(rad), h); - else - p.translate(0.0, textWidth*sin(rad)); - - p.rotate(-angle); - p.translate(0.0, textHeight - QFontMetrics(font_).descent()); - - p.setFont( font_ ); - p.setPen(Qt::SolidLine); - p.setPen(GL2Qt(color.r, color.g, color.b)); - p.drawText(0, 0, text_); - p.end(); - - return QGLWidget::convertToGLFormat(pm_.toImage()); -} +} + +QImage Label::createImage(double angle) +{ + QRect r = QRect(QPoint(0, 0), QFontMetrics(font_).size(Qwt3D::SingleLine, text_)); + int textWidth = r.width(); + int textHeight = r.height(); + + double aux_a = angle; + if (aux_a > 270) + aux_a -= 270; + if (aux_a >= 180) + aux_a -= 180; + if (aux_a > 90) + aux_a -= 90; + + double rad = aux_a*M_PI/180.0; + + int w = 0, h = 0; + if ((angle >= 0 && angle <= 90) || (angle >= 180 && angle <= 270)){ + w = qRound(fabs(textWidth*cos(rad) + textHeight*sin(rad))); + h = qRound(fabs(textWidth*sin(rad) + textHeight*cos(rad))); + } else { + w = qRound(fabs(textWidth*sin(rad) + textHeight*cos(rad))); + h = qRound(fabs(textWidth*cos(rad) + textHeight*sin(rad))); + } + + width_ = w; + height_ = h; + + QPixmap pm_ = QPixmap(w, h); + + if (plot() && plot()->isExportingVector() && plot()->vectorExportFormat() != GL2PS_PDF){ + Qwt3D::RGBA rgba = plot()->backgroundRGBAColor(); + pm_.fill(GL2Qt(rgba.r, rgba.g, rgba.b)); + } else + pm_.fill(Qt::transparent); + + QPainter p(&pm_); + + if (angle >= 270) + p.translate(textHeight*cos(rad), 0.0); + else if (angle >= 180) + p.translate(w, textHeight*cos(rad)); + else if (angle > 90) + p.translate(textWidth*sin(rad), h); + else + p.translate(0.0, textWidth*sin(rad)); + + p.rotate(-angle); + p.translate(0.0, textHeight - QFontMetrics(font_).descent()); + + p.setFont( font_ ); + p.setPen(Qt::SolidLine); + p.setPen(GL2Qt(color.r, color.g, color.b)); + p.drawText(0, 0, text_); + p.end(); + + return QGLWidget::convertToGLFormat(pm_.toImage()); +} /** Adds an additional shift to the anchor point. This happens in a more or less intelligent manner @@ -205,100 +205,100 @@ void Label::convert2screen() } start = World2ViewPort(beg_); end_ = ViewPort2World(start + Triple(width(), height(), 0)); -} - -const char * Label::fontname() -{ - char *name = "Helvetica"; - if (font_.family() == "Times New Roman"){ - name = "Times"; - if (font_.bold() && font_.italic ()) - name = "Times-BoldItalic"; - else if (font_.italic()) - name = "Times-Italic"; - else if (font_.bold()) - name = "Times-Bold"; - } else if (font_.family() == "Courier" || font_.family() == "Courier New"){ - name = "Courier"; - if (font_.bold() && font_.italic ()) - name = "Courier-BoldOblique"; - else if (font_.italic()) - name = "Courier-Oblique"; - else if (font_.bold()) - name = "Courier-Bold"; - } else { - if (font_.bold() && font_.italic ()) - name = "Helvetica-BoldOblique"; - else if (font_.italic()) - name = "Helvetica-Oblique"; - else if (font_.bold()) - name = "Helvetica-Bold"; - } - - return (const char*) name; -} - -void Label::draw(double angle) -{ - if (!plot() || !plot()->isVisible()) - return; - - if (text_.isEmpty()) - return; - - GLboolean b; - GLint func; - GLdouble v; - glGetBooleanv(GL_ALPHA_TEST, &b); - glGetIntegerv(GL_ALPHA_TEST_FUNC, &func); - glGetDoublev(GL_ALPHA_TEST_REF, &v); - - glEnable (GL_ALPHA_TEST); - glAlphaFunc (GL_NOTEQUAL, 0.0); - - convert2screen(); - glRasterPos3d(beg_.x, beg_.y, beg_.z); - - if (plot()->isExportingVector()){ - if (devicefonts_) - drawDeviceText(QWT3DLOCAL8BIT(text_), fontname(), font_.pointSize(), pos_, color, anchor_, gap_, angle); - else { - QImage tex_ = createImage(angle); - drawDevicePixels(tex_.width(), tex_.height(), GL_RGBA, GL_UNSIGNED_BYTE, tex_.bits()); - } - } else { - if (!angle){ - Triple start = World2ViewPort(beg_); - start = ViewPort2World(start + Triple(0, QFontMetrics(font_).descent(), 0)); - plot()->qglColor(GL2Qt(color.r, color.g, color.b)); - plot()->renderText(start.x, start.y, start.z, text_, font_); - } else { - QImage tex_ = createImage(angle); - drawDevicePixels(tex_.width(), tex_.height(), GL_RGBA, GL_UNSIGNED_BYTE, tex_.bits()); - } - } - - glAlphaFunc(func,v); - Enable(GL_ALPHA_TEST, b); -} +} + +const char * Label::fontname() +{ + char *name = "Helvetica"; + if (font_.family() == "Times New Roman"){ + name = "Times"; + if (font_.bold() && font_.italic ()) + name = "Times-BoldItalic"; + else if (font_.italic()) + name = "Times-Italic"; + else if (font_.bold()) + name = "Times-Bold"; + } else if (font_.family() == "Courier" || font_.family() == "Courier New"){ + name = "Courier"; + if (font_.bold() && font_.italic ()) + name = "Courier-BoldOblique"; + else if (font_.italic()) + name = "Courier-Oblique"; + else if (font_.bold()) + name = "Courier-Bold"; + } else { + if (font_.bold() && font_.italic ()) + name = "Helvetica-BoldOblique"; + else if (font_.italic()) + name = "Helvetica-Oblique"; + else if (font_.bold()) + name = "Helvetica-Bold"; + } + + return (const char*) name; +} + +void Label::draw(double angle) +{ + if (!plot() || !plot()->isVisible()) + return; + + if (text_.isEmpty()) + return; + + GLboolean b; + GLint func; + GLdouble v; + glGetBooleanv(GL_ALPHA_TEST, &b); + glGetIntegerv(GL_ALPHA_TEST_FUNC, &func); + glGetDoublev(GL_ALPHA_TEST_REF, &v); + + glEnable (GL_ALPHA_TEST); + glAlphaFunc (GL_NOTEQUAL, 0.0); + + convert2screen(); + glRasterPos3d(beg_.x, beg_.y, beg_.z); + + if (plot()->isExportingVector()){ + if (devicefonts_) + drawDeviceText(QWT3DLOCAL8BIT(text_), fontname(), font_.pointSize(), pos_, color, anchor_, gap_, angle); + else { + QImage tex_ = createImage(angle); + drawDevicePixels(tex_.width(), tex_.height(), GL_RGBA, GL_UNSIGNED_BYTE, tex_.bits()); + } + } else { + if (!angle){ + Triple start = World2ViewPort(beg_); + start = ViewPort2World(start + Triple(0, QFontMetrics(font_).descent(), 0)); + plot()->qglColor(GL2Qt(color.r, color.g, color.b)); + plot()->renderText(start.x, start.y, start.z, text_, font_); + } else { + QImage tex_ = createImage(angle); + drawDevicePixels(tex_.width(), tex_.height(), GL_RGBA, GL_UNSIGNED_BYTE, tex_.bits()); + } + } + + glAlphaFunc(func,v); + Enable(GL_ALPHA_TEST, b); +} double Label::width() const -{ - if (width_ > 0.0 && height_ > 0.0) - return width_; - +{ + if (width_ > 0.0 && height_ > 0.0) + return width_; + return QRect(QPoint(0, 0), QFontMetrics(font_).size(Qwt3D::SingleLine, text_)).width(); } double Label::height() const -{ +{ if (width_ > 0.0 && height_ > 0.0) - return height_; - + return height_; + + return QRect(QPoint(0, 0), QFontMetrics(font_).size(Qwt3D::SingleLine, text_)).height(); +} + +double Label::textHeight() const +{ return QRect(QPoint(0, 0), QFontMetrics(font_).size(Qwt3D::SingleLine, text_)).height(); } - -double Label::textHeight() const -{ - return QRect(QPoint(0, 0), QFontMetrics(font_).size(Qwt3D::SingleLine, text_)).height(); -}