From 8381d3a1441058b4103bf4539f531e5f436bf91a Mon Sep 17 00:00:00 2001 From: xiaoming <2014500726@smail.xtu.edu.cn> Date: Sun, 3 Jul 2022 18:18:44 +0800 Subject: [PATCH] core:opt code Signed-off-by: xiaoming <2014500726@smail.xtu.edu.cn> --- build_deb.sh | 2 +- build_dmg.sh | 4 ++-- build_setup.bat | 2 +- partform_unix.pri | 2 +- partform_win32.pri | 2 +- src/ImgViewer.cpp | 44 ++++++++++++++++++++++---------------------- src/ImgViewer.h | 10 +++++----- src/TTFdecoder.cpp | 10 +++++----- src/TTFdecoder.h | 4 ++-- src/TTFviewer.cpp | 8 -------- src/TTFviewer.h | 1 - src/font_to_svg.hpp | 2 +- 12 files changed, 41 insertions(+), 50 deletions(-) diff --git a/build_deb.sh b/build_deb.sh index 97b4044..31b8926 100755 --- a/build_deb.sh +++ b/build_deb.sh @@ -7,7 +7,7 @@ QT_DIR=/opt/Qt5.12.8/5.12.8/gcc_64 # 定义版本号 YVYVIEWER_MAJARVERSION="0" YVYVIEWER_SUBVERSION="0" -YVYVIEWER_REVISION="1" +YVYVIEWER_REVISION="2" ############################################################################### diff --git a/build_dmg.sh b/build_dmg.sh index f817fb7..194015a 100755 --- a/build_dmg.sh +++ b/build_dmg.sh @@ -6,8 +6,8 @@ QT_DIR=/opt/Qt5.12.2/5.12.2/gcc_64 # 定义版本号 YVYVIEWER_MAJARVERSION="0" -YVYVIEWER_SUBVERSION="4" -YVYVIEWER_REVISION="9" +YVYVIEWER_SUBVERSION="0" +YVYVIEWER_REVISION="2" ############################################################################### diff --git a/build_setup.bat b/build_setup.bat index a78db33..9984e11 100644 --- a/build_setup.bat +++ b/build_setup.bat @@ -7,7 +7,7 @@ set "QT_TOOLS_DIR=C:/Qt/Qt5.12.8/Tools/mingw730_32/bin" :: 定义Inno Setup目录 set "INNO_SETUP_DIR=C:/Program Files (x86)/Inno Setup 6" :: 定义版本号 -set "YVYVIEWER_VERSION=0.4.9" +set "YVYVIEWER_VERSION=0.0.2" ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: diff --git a/partform_unix.pri b/partform_unix.pri index 9b71977..387ac5a 100644 --- a/partform_unix.pri +++ b/partform_unix.pri @@ -2,5 +2,5 @@ # 定义freetype2 lib路径 FREETPE2_DIR=/home/qqm/Desktop/ttfviewer/depend/freetype # 定义版本号路径 -TTFVIEWER_VERSION=0.0.1 +TTFVIEWER_VERSION=0.0.2 ############################################################################### diff --git a/partform_win32.pri b/partform_win32.pri index 5454506..3fcd3e2 100644 --- a/partform_win32.pri +++ b/partform_win32.pri @@ -2,5 +2,5 @@ # 定义freetype2 lib路径 FREETPE2_DIR=D:\ttfviewer\depend\freetype # 定义版本号路径 -TTFVIEWER_VERSION=0.0.1 +TTFVIEWER_VERSION=0.0.2 ############################################################################### diff --git a/src/ImgViewer.cpp b/src/ImgViewer.cpp index 05ab2e2..c70bff7 100644 --- a/src/ImgViewer.cpp +++ b/src/ImgViewer.cpp @@ -32,7 +32,7 @@ TTFDecodeThread::TTFDecodeThread(QWidget *parent,QString ttffilename,QString TTF void TTFDecodeThread::run() { - QList frame_RGB_list; + QList frame_RGB_list; if(this->decoder == nullptr) { // 未能成功获取则返回无法解码 @@ -57,7 +57,7 @@ ImgViewer::ImgViewer(QWidget *parent,QWidget *parentWindow) : ui(new Ui::ImgViewerWindow) { ui->setupUi(this); - qRegisterMetaType>("QList"); + qRegisterMetaType>("QList"); this->parentWindow = parentWindow; setWindowTitle("loading file, please wait ...."); ui->left_PushButton->setFlat(true); @@ -88,7 +88,7 @@ bool ImgViewer::setFileList(QStringList filenamelist,QString TTFFormat, int W, i // 遍历文件列表 foreach( QString filename, filenamelist) { - QList frame_RGB_list; + QList frame_RGB_list; // 使用获取的解码函数进行解码得到RGB的原始帧列表 frame_RGB_list = decoder(filename, W, H, codepoint); @@ -107,13 +107,13 @@ bool ImgViewer::setFileList(QStringList filenamelist,QString TTFFormat, int W, i this->currentImg_RGB_list = this->img_list.at(0); this->currentImg = this->currentImg_RGB_list.at(0); this->setWindowTitle(this->filelist.at(0)+"-0"); - this->scaled_img = this->currentImg.scaled(this->size()); + this->scaled_img = this->currentImg->scaled(this->size()); this->point = QPoint(0, 0); return true; } } -void ImgViewer::reciveimgdata(QList img_RGB_list,QString filename) +void ImgViewer::reciveimgdata(QList img_RGB_list,QString filename) { if (!img_RGB_list.empty()) { @@ -128,7 +128,7 @@ void ImgViewer::reciveimgdata(QList img_RGB_list,QString filename) this->currentImg_RGB_list = this->img_list.at(0); this->currentImg = this->currentImg_RGB_list.at(0); this->setWindowTitle(this->filelist.at(0)+"-0"); - this->scaled_img = this->currentImg.scaled(this->size()); + this->scaled_img = this->currentImg->scaled(this->size()); this->point = QPoint(0, 0); this->repaint(); } @@ -162,7 +162,7 @@ bool ImgViewer::setFileList_multithreading(QStringList filenamelist,QString TTFF foreach( QString filename, filenamelist) { TTFDecodeThread *decodeThread = new TTFDecodeThread(this, filename, TTFFormat, W, H, codepoint); - QObject::connect(decodeThread, SIGNAL(finsh_signal(QList, QString)), this, SLOT(reciveimgdata(QList, QString))); + QObject::connect(decodeThread, SIGNAL(finsh_signal(QList, QString)), this, SLOT(reciveimgdata(QList, QString))); this->decode_thread.insert(this->decode_thread.end(),decodeThread); } this->decode_thread[0]->start(); @@ -175,13 +175,13 @@ void ImgViewer::closeEvent(QCloseEvent *event) event->accept(); if(!this->img_list.empty()) { - foreach(QList list,this->img_list) + foreach(QList list,this->img_list) { if(!list.empty()) { - foreach(QPixmap img,list) + foreach(QPixmap *img,list) { - //delete img; + delete img; } } } @@ -243,12 +243,12 @@ void ImgViewer::mouseReleaseEvent(QMouseEvent *event) else if(event->button() == Qt::RightButton) { this->point = QPoint(0, 0); - this->scaled_img = this->currentImg.scaled(this->size()); + this->scaled_img = this->currentImg->scaled(this->size()); this->repaint(); } else if(event->button() == Qt::MiddleButton) { - this->scaled_img = this->currentImg.scaled(this->currentImg.size().width(),this->currentImg.size().height()); + this->scaled_img = this->currentImg->scaled(this->currentImg->size().width(),this->currentImg->size().height()); this->point = QPoint(0, 0); this->repaint(); } @@ -262,19 +262,19 @@ void ImgViewer::mouseDoubleClickEvent(QMouseEvent *event) if( event->button() == Qt::LeftButton) { int list_index = this->img_list.indexOf(this->currentImg_RGB_list); - QList img_RGB_list = this->img_list[list_index]; + QList img_RGB_list = this->img_list[list_index]; int img_index = img_RGB_list.indexOf(this->currentImg); QString savefile_name = QFileDialog::getSaveFileName(this, "保存文件", this->filelist[list_index].replace(".ttf","-") + QString::number(img_index) + ".png", "Image files(*.png)"); if(savefile_name != nullptr) { - this->currentImg.save(savefile_name); + this->currentImg->save(savefile_name); } } else if(event->button() == Qt::RightButton) { this->flipRGB = this->flipRGB ? false : true; this->point = QPoint(0, 0); - this->scaled_img = this->currentImg.scaled(this->size()); + this->scaled_img = this->currentImg->scaled(this->size()); this->repaint(); } } @@ -292,7 +292,7 @@ void ImgViewer::wheelEvent(QWheelEvent *event) float setpsize_x = ((float)this->scaled_img.width())/16.0f; float setpsize_y = ((float)this->scaled_img.height())/16.0f; //缩放可能导致比例不精确 - this->scaled_img = this->currentImg.scaled(this->scaled_img.width() + setpsize_x,this->scaled_img.height() + setpsize_y); + this->scaled_img = this->currentImg->scaled(this->scaled_img.width() + setpsize_x,this->scaled_img.height() + setpsize_y); float new_w = event->x() - (this->scaled_img.width() * (event->x() - this->point.x())) / (this->scaled_img.width() - setpsize_x); float new_h = event->y() - (this->scaled_img.height() * (event->y() - this->point.y())) / (this->scaled_img.height() - setpsize_y); this->point = QPoint(new_w, new_h); @@ -307,7 +307,7 @@ void ImgViewer::wheelEvent(QWheelEvent *event) float setpsize_x = ((float)this->scaled_img.width())/16.0f; float setpsize_y = ((float)this->scaled_img.height())/16.0f; //缩放可能导致比例不精确 - this->scaled_img = this->currentImg.scaled(this->scaled_img.width() - setpsize_x,this->scaled_img.height() - setpsize_y); + this->scaled_img = this->currentImg->scaled(this->scaled_img.width() - setpsize_x,this->scaled_img.height() - setpsize_y); float new_w = event->x() - (this->scaled_img.width() * (event->x() - this->point.x())) / (this->scaled_img.width() + setpsize_x); float new_h = event->y() - (this->scaled_img.height() * (event->y() - this->point.y())) / (this->scaled_img.height() + setpsize_y); this->point = QPoint(new_w, new_h); @@ -321,7 +321,7 @@ void ImgViewer::resizeEvent(QResizeEvent *event) { if (!this->img_list.empty()) { - this->scaled_img = this->currentImg.scaled(this->size()); + this->scaled_img = this->currentImg->scaled(this->size()); this->point = QPoint(0, 0); this->update(); } @@ -334,7 +334,7 @@ void ImgViewer::previousImg() { //得到当前显示的文件序号 int list_index = this->img_list.indexOf(this->currentImg_RGB_list); - QList img_RGB_list = this->img_list[list_index]; + QList img_RGB_list = this->img_list[list_index]; //得到当前显示的图像是文件的帧序号 int img_index = img_RGB_list.indexOf(this->currentImg); @@ -366,7 +366,7 @@ void ImgViewer::previousImg() this->currentImg_RGB_list = this->img_list[list_index]; this->currentImg = this->currentImg_RGB_list[img_index]; this->point = QPoint(0, 0); - this->scaled_img = this->currentImg.scaled(this->size()); + this->scaled_img = this->currentImg->scaled(this->size()); this->repaint(); } } @@ -377,7 +377,7 @@ void ImgViewer::nextImg() { //得到当前显示的文件序号 int list_index = this->img_list.indexOf(this->currentImg_RGB_list); - QList img_RGB_list = this->img_list[list_index]; + QList img_RGB_list = this->img_list[list_index]; //得到当前显示的图像是文件的帧序号 int img_index = img_RGB_list.indexOf(this->currentImg); @@ -409,7 +409,7 @@ void ImgViewer::nextImg() this->currentImg_RGB_list = this->img_list[list_index]; this->currentImg = this->currentImg_RGB_list[img_index]; this->point = QPoint(0, 0); - this->scaled_img = this->currentImg.scaled(this->size()); + this->scaled_img = this->currentImg->scaled(this->size()); this->repaint(); } } diff --git a/src/ImgViewer.h b/src/ImgViewer.h index ac785c1..5319433 100644 --- a/src/ImgViewer.h +++ b/src/ImgViewer.h @@ -37,7 +37,7 @@ class TTFDecodeThread : public QThread void run(); signals: - void finsh_signal(QList frame_RGB_list,QString str); + void finsh_signal(QList frame_RGB_list,QString str); private: QWidget *window; @@ -59,7 +59,7 @@ class ImgViewer : public QWidget bool setFileList_multithreading(QStringList filenamelist, QString TTFFormat, int W, int H, int codepoint); private slots: - void reciveimgdata(QList img_RGB_list, QString filename); + void reciveimgdata(QList img_RGB_list, QString filename); void previousImg(); void nextImg(); @@ -79,14 +79,14 @@ private slots: QWidget *parentWindow; bool left_click; - QList> img_list; + QList> img_list; QStringList filelist; QList decode_thread; QList decode_thread_finsh; - QList currentImg_RGB_list; - QPixmap currentImg; + QList currentImg_RGB_list; + QPixmap *currentImg; QPixmap scaled_img; QPoint point; QPoint startPos; diff --git a/src/TTFdecoder.cpp b/src/TTFdecoder.cpp index 251a8de..198a9b1 100644 --- a/src/TTFdecoder.cpp +++ b/src/TTFdecoder.cpp @@ -21,9 +21,9 @@ QMap TTF2RGB::ttfdecoder_map = {"ttf", TTF2RGB::ttf}, }; -QList TTF2RGB::ttf(QString ttffilename,int W, int H, int codepoint) +QList TTF2RGB::ttf(QString ttffilename,int W, int H, int codepoint) { - QList rgbImglist; + QList rgbImglist; QString svgImg; QByteArray naBA = ttffilename.toLatin1(); @@ -43,9 +43,9 @@ QList TTF2RGB::ttf(QString ttffilename,int W, int H, int codepoint) QXmlStreamReader svgXmlStreamReader(svgImg); QSvgRenderer svgRender; svgRender.load(&svgXmlStreamReader); - QPixmap svgPixmap(W,H); - svgPixmap.fill(Qt::transparent); - QPainter svgPainter(&svgPixmap); + QPixmap *svgPixmap = new QPixmap(W,H); + svgPixmap->fill(Qt::transparent); + QPainter svgPainter(svgPixmap); svgRender.render(&svgPainter); rgbImglist.append(svgPixmap); diff --git a/src/TTFdecoder.h b/src/TTFdecoder.h index aff403b..37f9a0b 100644 --- a/src/TTFdecoder.h +++ b/src/TTFdecoder.h @@ -11,12 +11,12 @@ #include #include -typedef QList (* ttfdecoder_t)(QString ttffilename,int W, int H, int codepoint); +typedef QList (* ttfdecoder_t)(QString ttffilename,int W, int H, int codepoint); class TTF2RGB { public: - static QList ttf(QString ttffilename,int W, int H, int codepoint); + static QList ttf(QString ttffilename,int W, int H, int codepoint); static QMap ttfdecoder_map; }; diff --git a/src/TTFviewer.cpp b/src/TTFviewer.cpp index a234965..66483d3 100644 --- a/src/TTFviewer.cpp +++ b/src/TTFviewer.cpp @@ -62,8 +62,6 @@ TTFviewer::TTFviewer(QWidget *parent) : QMainWindow(parent), ui(new Ui::TTFviewer) { - int currentIndex; - ui->setupUi(this); this->setWindowTitle("TTFviewer " + VERSION); @@ -119,11 +117,9 @@ TTFviewer::TTFviewer(QWidget *parent) : } - currentIndex = 0; QList color_list; - QObject::connect(ui->TTFFormat_ComboBox, SIGNAL(currentTextChanged(const QString &)), this, SLOT(changeFormat(const QString &))); QObject::connect(ui->frameSizeType_Combo_RadioButton, SIGNAL(clicked()), this, SLOT(configComboBox())); QObject::connect(ui->frameSizeType_Other_RadioButton, SIGNAL(clicked()), this, SLOT(configOther())); QObject::connect(ui->frameSizeType_ComboBox, SIGNAL(currentTextChanged(const QString &)), this,SLOT(changeFrameSizeType(const QString &))); @@ -151,10 +147,6 @@ TTFviewer::~TTFviewer() delete ui; } -void TTFviewer::changeFormat(const QString &text) -{ -} - void TTFviewer::configComboBox() { ui->frameSizeType_ComboBox->setEnabled(true); diff --git a/src/TTFviewer.h b/src/TTFviewer.h index 5a7cc83..0812fa1 100644 --- a/src/TTFviewer.h +++ b/src/TTFviewer.h @@ -28,7 +28,6 @@ class TTFviewer : public QMainWindow void closeEvent(QCloseEvent *event); private slots: - void changeFormat(const QString &text); void configComboBox(); void configOther(); void changeFrameSizeType(const QString &text); diff --git a/src/font_to_svg.hpp b/src/font_to_svg.hpp index 8394438..4c487ff 100644 --- a/src/font_to_svg.hpp +++ b/src/font_to_svg.hpp @@ -139,7 +139,7 @@ std::string do_outline(std::vector points, std::vector tags, st int contour_starti = 0; int contour_endi = 0; - for ( int i = 0 ; i < contours.size() ; i++ ) { + for ( size_t i = 0 ; i < contours.size() ; i++ ) { contour_endi = contours.at(i); debug << "new contour starting. startpt index, endpt index:"; debug << contour_starti << "," << contour_endi << "\n";