diff --git a/NameCreater/NameCreater.qrc b/NameCreater/NameCreater.qrc
index f9048fe..575bd9d 100644
--- a/NameCreater/NameCreater.qrc
+++ b/NameCreater/NameCreater.qrc
@@ -1,8 +1,9 @@
- resource/background.jpg
resource/background_sample.jpg
- resource/background_boy.jpg
- resource/background_girl.jpg
+ resource/background_b.jpg
+ resource/background_g.jpg
+ resource/background_r.jpg
+ resource/background_y.jpg
diff --git a/NameCreater/_exp/name.csv b/NameCreater/_exp/name.csv
index 97db021..13ec11a 100644
--- a/NameCreater/_exp/name.csv
+++ b/NameCreater/_exp/name.csv
@@ -1,4 +1,13 @@
-name_1,name_2,bg_type
-Ĭ鶣,Ĭ_,mix
-K,f,boy
-B,B,girl
+name_1,bg_type
+p,r
+Lp,g
+dw,b
+p,y
+p,r
+Lp,g
+dw,b
+p,y
+p,r
+Lp,g
+p,y
+Lp,b
diff --git a/NameCreater/main.cpp b/NameCreater/main.cpp
index c3b819c..fe3675f 100644
--- a/NameCreater/main.cpp
+++ b/NameCreater/main.cpp
@@ -12,9 +12,9 @@
#include
#include
-#define BG_MIX_PATH ":/NameCreater/resource/background.jpg"
-#define BG_BOY_PATH ":/NameCreater/resource/background_boy.jpg"
-#define BG_GIRL_PATH ":/NameCreater/resource/background_girl.jpg"
+
+#define BG_SAMPLE_PATH ":/NameCreater/resource/background_sample.jpg"
+#define BG_PATH_FORMAT ":/NameCreater/resource/background_%1.jpg"
#define FONT_NAME "DFYuanStd-W8.otf"
#define FONT_SIZE 120
//#define FONT_SIZE 74
@@ -24,134 +24,142 @@
#define BG_GIRL_TYPE_STR "girl"
struct NameInfo_t {
- QString name1;
- QString name2;
- int bg_type;
+ QString name1;
+ QString name2;
+ QString bg_path;
};
-static QPointF BOY_POS[] = {
- QPointF(235, 387), QPointF(366, 1433),
- QPointF(555, 387), QPointF(692, 1433),
- QPointF(878, 387), QPointF(1014, 1433),
- QPointF(1200, 387), QPointF(1337, 1433),
- QPointF(1527, 387), QPointF(1663, 1433),
+static QPointF BG_POS[] = {
+ QPointF(159, 61), QPointF(482, 61), QPointF(802, 61),
+ QPointF(1122, 61), QPointF(1449, 61), QPointF(1772, 61),
+ QPointF(2095, 61), QPointF(2414, 61), QPointF(2738, 61),
+ QPointF(3060, 61), QPointF(900, 2094), QPointF(900, 2420),
};
-static int BOY_POS_COUNT = sizeof(BOY_POS) / sizeof(BOY_POS[0]);
+static int BG_POS_COUNT = sizeof(BG_POS) / sizeof(BG_POS[0]);
-static QPointF GIRL_POS[] = {
- QPointF(1854, 387), QPointF(1987, 1433),
- QPointF(2176, 387), QPointF(2314, 1433),
- QPointF(2498, 387), QPointF(2635, 1433),
- QPointF(2821, 387), QPointF(2958, 1433),
- QPointF(3147, 387), QPointF(3285, 1433),
+static QPointF NAME_POS[] = {
+ QPointF(240, 430), QPointF(372, 1402),
+ QPointF(564, 430), QPointF(694, 1402),
+ QPointF(883, 430), QPointF(1014, 1402),
+ QPointF(1205, 430), QPointF(1337, 1402),
+ QPointF(1532, 430), QPointF(1663, 1402),
+ QPointF(1854, 430), QPointF(1987, 1402),
+ QPointF(2176, 430), QPointF(2309, 1402),
+ QPointF(2498, 430), QPointF(2629, 1402),
+ QPointF(2821, 430), QPointF(2952, 1402),
+ QPointF(3145, 430), QPointF(3276, 1402),
+ QPointF(1268, 2012), QPointF(2240, 1880),
+ QPointF(1268, 2334), QPointF(2240, 2202),
};
-static int GIRL_POS_COUNT = sizeof(GIRL_POS) / sizeof(GIRL_POS[0]);
+static int NAME_POS_COUNT = sizeof(NAME_POS) / sizeof(NAME_POS[0]);
+
+
void saveToImage(const QString& filename, QGraphicsScene* scene) {
- scene->clearSelection(); // Selections would also render to the file
- scene->setSceneRect(scene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents
- QImage image(scene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
- image.fill(Qt::transparent); // Start all pixels transparent
- int dpm = 300 / 0.0254; // ~300 DPI
- image.setDotsPerMeterX(dpm);
- image.setDotsPerMeterY(dpm);
+ scene->clearSelection(); // Selections would also render to the file
+ scene->setSceneRect(scene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents
+ QImage image(scene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
+ image.fill(Qt::transparent); // Start all pixels transparent
+ int dpm = 300 / 0.0254; // ~300 DPI
+ image.setDotsPerMeterX(dpm);
+ image.setDotsPerMeterY(dpm);
- QPainter painter(&image);
- scene->render(&painter);
+ QPainter painter(&image);
+ scene->render(&painter);
#ifdef Q_OS_MAC
- QString folder_name = QCoreApplication::applicationDirPath()+"/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
+ QString folder_name = QCoreApplication::applicationDirPath() + "/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#else
- QString folder_name = QCoreApplication::applicationDirPath() + "/export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
+ QString folder_name = QCoreApplication::applicationDirPath() + "/export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#endif
- qDebug() << "folder_name :" << folder_name;
- if (!QDir(folder_name).exists()) {
- QDir().mkdir(folder_name);
- }
+ qDebug() << "folder_name :" << folder_name;
+ if (!QDir(folder_name).exists()) {
+ QDir().mkdir(folder_name);
+ }
- image.save(QString(folder_name).append("/").append(filename), "JPG", 100);
+ image.save(QString(folder_name).append("/").append(filename), "JPG", 100);
}
QList getNameByFile(const QString& filename) {
- QList nameList;
+ QList nameList;
#ifdef Q_OS_MAC
- QString root_path = QCoreApplication::applicationDirPath() + "/../../../";
+ QString root_path = QCoreApplication::applicationDirPath() + "/../../../";
#else
- QString root_path = QCoreApplication::applicationDirPath() + "/";
+ QString root_path = QCoreApplication::applicationDirPath() + "/";
#endif
- QFile file(root_path.append(filename));
+ QFile file(root_path.append(filename));
- if (!file.open(QIODevice::ReadOnly)) {
+ if (!file.open(QIODevice::ReadOnly)) {
QMessageBox msgBox;
msgBox.setText("Load file failed!");
msgBox.exec();
file.close();
- return nameList;
- }
+ return nameList;
+ }
- int row = 0;
- QTextCodec *tc = QTextCodec::codecForName("Big5");
- while (!file.atEnd())
- {
- NameInfo_t info;
- QByteArray line = file.readLine();
- QString name_tc = tc->toUnicode(line);
- QStringList csvList = name_tc.split(',');
+ int row = 0;
+ QTextCodec* tc = QTextCodec::codecForName("Big5");
+ while (!file.atEnd())
+ {
+ NameInfo_t info;
+ QByteArray line = file.readLine();
+ QString name_tc = tc->toUnicode(line);
+ QStringList csvList = name_tc.split(',');
- QString name1 = csvList.at(0); //QString::fromLocal8Bit(csvList.at(0));
- QString name2 = csvList.at(1);//QString::fromLocal8Bit(csvList.at(1));
- QString type_str = csvList.last();//QString::fromLocal8Bit(csvList.last());
- qDebug() << "row :" << row << " " << name1 << " " << name2;
+ QString name1 = csvList.at(0);
+ QString type_str = csvList.last();//QString::fromLocal8Bit(csvList.last());
+ qDebug() << "row :" << row << " " << name1;
+ type_str = type_str.remove(QRegExp("\r\n"));
- if (name1.compare("name_1") == 0 || name2.compare("name_2") == 0) {
- continue;
- }
+ if (name1.compare("name_1") == 0) {
+ continue;
+ }
- info.name1 = name1;
- info.name2 = name2;
- info.bg_type = type_str.contains(QRegExp("boy")) ? 1 : (type_str.contains(QRegExp("girl"))) ? 2 : 0;
+ info.name1 = name1;
+ info.bg_path = QString(BG_PATH_FORMAT).arg(type_str);
- nameList.append(info);
- row++;
- }
+ nameList.append(info);
+
+ row++;
+ }
file.close();
- return nameList;
+ return nameList;
}
int main(int argc, char* argv[])
{
- int export_times = 0;
+ int export_times = 0;
- QApplication a(argc, argv);
-// NameCreater w;
-// w.show();
+ QApplication a(argc, argv);
+ // NameCreater w;
+ // w.show();
#ifdef Q_OS_MAC
- QString root_path = QCoreApplication::applicationDirPath() + "/../../../";
+ QString root_path = QCoreApplication::applicationDirPath() + "/../../../";
#else
- QString root_path = QCoreApplication::applicationDirPath() + "/";
+ QString root_path = QCoreApplication::applicationDirPath() + "/";
#endif
- QString font_path = root_path.append(FONT_NAME);
+ QString font_path = root_path.append(FONT_NAME);
QFile font_res(font_path);
if (!font_res.open(QIODevice::ReadOnly)) {
QMessageBox msgBox;
- msgBox.setText("Can not load font file!" + font_path);
+ msgBox.setText("Can not load font file!" + font_path);
msgBox.exec();
font_res.close();
return 0;
@@ -159,79 +167,117 @@ int main(int argc, char* argv[])
int id = QFontDatabase::addApplicationFontFromData(font_res.readAll());
QStringList family_list = QFontDatabase::applicationFontFamilies(id);
QFont font = QFont(family_list.at(0));
- font.setPixelSize(FONT_SIZE);
- QColor font_color(0, 0, 0);
+ font.setPixelSize(FONT_SIZE);
+ QColor font_color(0, 0, 0);
- QList nameList = getNameByFile("name.csv");
- if (nameList.isEmpty()) {
- QMessageBox msgBox;
- msgBox.setText(("Name is empty !"));
- msgBox.exec();
- }
+ QList nameList = getNameByFile("name.csv");
+ if (nameList.isEmpty()) {
+ QMessageBox msgBox;
+ msgBox.setText(("Name is empty !"));
+ msgBox.exec();
+ }
- QGraphicsScene scene;
- QGraphicsView view(&scene);
+ QGraphicsScene scene(0, 0, 3508, 2482);
+ scene.setBackgroundBrush(QBrush(QColor(255, 255, 255)));
+ QGraphicsView view(&scene);
- for (int n = 0; n < nameList.length(); n++) {
- //msgBox.setText(QString().sprintf("Export: %d / %d", export_times, nameList.length()));
- NameInfo_t name_info = nameList.at(n);
-
- scene.clear();
- QImage image((name_info.bg_type == 1) ? BG_BOY_PATH : (name_info.bg_type == 2) ? BG_GIRL_PATH : BG_MIX_PATH);
- QGraphicsPixmapItem* bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(image));
- scene.addItem(bgItem);
+ //QImage image(BG_SAMPLE_PATH);
+ //QGraphicsPixmapItem* bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(image));
+ //scene.addItem(bgItem);
- for (int j = 0; j < 2; j++) {
- int flag = j % 2;
- QString name = (flag == 0) ? name_info.name1 : name_info.name2;
- for (int i = 0; i < BOY_POS_COUNT; i++) {
- int xscale, yscale;
- xscale = yscale = (i % 2 == 1) ? -1 : 1;
- QPointF pos = (flag == 0) ? BOY_POS[i] : GIRL_POS[i];
-
- QGraphicsTextItem* textItem1 = new QGraphicsTextItem(name.mid(0, 1));
- textItem1->setFont(font);
- textItem1->setDefaultTextColor(font_color);
- textItem1->setPos(pos);
- textItem1->setTransform(QTransform::fromScale(xscale, yscale));
- scene.addItem(textItem1);
-
- QGraphicsTextItem* textItem2 = new QGraphicsTextItem(name.mid(1, 1));
- textItem2->setFont(font);
- textItem2->setDefaultTextColor(font_color);
- textItem2->setPos(pos.x(), pos.y() + 148 * xscale);
- textItem2->setTransform(QTransform::fromScale(xscale, yscale));
- scene.addItem(textItem2);
-
- QGraphicsTextItem* textItem3 = new QGraphicsTextItem(name.mid(2, 1));
- textItem3->setFont(font);
- textItem3->setDefaultTextColor(font_color);
- textItem3->setPos(pos.x(), pos.y() + 294 * xscale);
- textItem3->setTransform(QTransform::fromScale(xscale, yscale));
- scene.addItem(textItem3);
- }
- }
-// if (name_info.bg_type == 0) {
-// view.show();
-// break;
-// }
-
- QString file_name = QString("%1_%2_%3.jpg").arg(QString::number(export_times+1),name_info.name1,name_info.name2);
- saveToImage(file_name, &scene);
- export_times++;
- }
+ for (int n = 0; n < nameList.length(); n++) {
+ if (n >= BG_POS_COUNT)break;
+ NameInfo_t name_info = nameList.at(n);
+ QImage name_image(name_info.bg_path);
+ QGraphicsPixmapItem* name_bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(name_image));
+ bool rot = (n == 10 || n == 11);
+ name_bgItem->setRotation(rot ? -90 : 0);
+ name_bgItem->setPos(BG_POS[n]);
+ scene.addItem(name_bgItem);
- QMessageBox msgBox;
- msgBox.setText(QString().asprintf("Export Finshed. Count:%d",export_times));
- msgBox.exec();
+ if (name_info.name1.isEmpty()) {
+ QMessageBox msgBox;
+ msgBox.setText(QString().asprintf("Name is Empty at %d", export_times + 1));
+ msgBox.exec();
+ }
+ QString name = name_info.name1;
+ for (int j = 0; j < 2; j++) {
+ int pos_idx = n * 2 + j;
+ int xscale, yscale;
+
+ xscale = yscale = (j == 1) ? -1 : 1;
+ QPointF pos = NAME_POS[pos_idx];
+
+
+
+ QGraphicsTextItem* textItem1 = new QGraphicsTextItem(name.mid(0, 1));
+ textItem1->setFont(font);
+ textItem1->setDefaultTextColor(font_color);
+ if (!rot) {
+ textItem1->setPos(pos);
+ textItem1->setTransform(QTransform::fromScale(xscale, yscale));
+ }
+ else {
+ textItem1->setPos(pos);
+ textItem1->setRotation(-90);
+ textItem1->setTransform(QTransform::fromScale(xscale, yscale));
+ }
+
+
+
+ scene.addItem(textItem1);
+
+ QGraphicsTextItem* textItem2 = new QGraphicsTextItem(name.mid(1, 1));
+ textItem2->setFont(font);
+ textItem2->setDefaultTextColor(font_color);
+ if (!rot) {
+
+ textItem2->setPos(pos.x(), pos.y() + 145 * xscale);
+ textItem2->setTransform(QTransform::fromScale(xscale, yscale));
+ }
+ else {
+ textItem2->setPos(pos.x() + 145 * xscale, pos.y());
+ textItem2->setRotation(-90);
+ textItem2->setTransform(QTransform::fromScale(xscale, yscale));
+ }
+
+ scene.addItem(textItem2);
+
+ QGraphicsTextItem* textItem3 = new QGraphicsTextItem(name.mid(2, 1));
+ textItem3->setFont(font);
+ textItem3->setDefaultTextColor(font_color);
+ if (!rot) {
+ textItem3->setPos(pos.x(), pos.y() + 290 * xscale);
+ textItem3->setTransform(QTransform::fromScale(xscale, yscale));
+ }
+ else {
+ textItem3->setPos(pos.x() + 290 * xscale, pos.y());
+ textItem3->setRotation(-90);
+ textItem3->setTransform(QTransform::fromScale(xscale, yscale));
+ }
+
+ scene.addItem(textItem3);
+
+ }
+
+
+
+ }
+ QString file_name = QString("%1_.jpg").arg(QString::number(export_times + 1));
+ saveToImage(file_name, &scene);
+ export_times++;
+
+ /*QMessageBox msgBox;
+ msgBox.setText(QString().asprintf("Export Finshed. Count:%d", export_times));
+ msgBox.exec();*/
font_res.close();
- return 0;
+ return a.exec();
}
diff --git a/NameCreater/resource/background.jpg b/NameCreater/resource/background.jpg
deleted file mode 100644
index 5b801c5..0000000
Binary files a/NameCreater/resource/background.jpg and /dev/null differ
diff --git a/NameCreater/resource/background_b.jpg b/NameCreater/resource/background_b.jpg
new file mode 100644
index 0000000..8da36cd
Binary files /dev/null and b/NameCreater/resource/background_b.jpg differ
diff --git a/NameCreater/resource/background_boy.jpg b/NameCreater/resource/background_boy.jpg
deleted file mode 100644
index 75b0fb5..0000000
Binary files a/NameCreater/resource/background_boy.jpg and /dev/null differ
diff --git a/NameCreater/resource/background_g.jpg b/NameCreater/resource/background_g.jpg
new file mode 100644
index 0000000..e68ef5c
Binary files /dev/null and b/NameCreater/resource/background_g.jpg differ
diff --git a/NameCreater/resource/background_girl.jpg b/NameCreater/resource/background_girl.jpg
deleted file mode 100644
index cb25e96..0000000
Binary files a/NameCreater/resource/background_girl.jpg and /dev/null differ
diff --git a/NameCreater/resource/background_r.jpg b/NameCreater/resource/background_r.jpg
new file mode 100644
index 0000000..aa4afa1
Binary files /dev/null and b/NameCreater/resource/background_r.jpg differ
diff --git a/NameCreater/resource/background_sample.jpg b/NameCreater/resource/background_sample.jpg
index 55f7928..6f1ff07 100644
Binary files a/NameCreater/resource/background_sample.jpg and b/NameCreater/resource/background_sample.jpg differ
diff --git a/NameCreater/resource/background_y.jpg b/NameCreater/resource/background_y.jpg
new file mode 100644
index 0000000..044c67a
Binary files /dev/null and b/NameCreater/resource/background_y.jpg differ
diff --git a/NameCreater/resource/截圖 2022-01-27 上午9.26.22.png b/NameCreater/resource/截圖 2022-01-27 上午9.26.22.png
deleted file mode 100644
index c910b77..0000000
Binary files a/NameCreater/resource/截圖 2022-01-27 上午9.26.22.png and /dev/null differ