Compare commits

...

15 Commits

Author SHA1 Message Date
3942d7f147 build webassembly succeed. 2023-04-07 05:57:05 +08:00
shouchih_chen 陳守志
fc8bb70f56 1. save file succeed 2023-03-31 16:17:51 +08:00
shouchih_chen 陳守志
24639c50b0 web assemble testing 2023-03-31 14:40:23 +08:00
d9d110ce04 1. add new five picture 2. add x64 env 2022-12-28 22:16:02 +08:00
83fde65fae 調整位置 2022-03-26 10:16:17 +08:00
56ea07365d Merge branch 'birthday' of https://gitlab.com/portfolio91/namecreater into birthday
# Conflicts:
#	NameCreater/main.cpp
2022-03-26 07:10:19 +08:00
6009f56287 add number sample 2022-03-26 06:55:59 +08:00
shouchih_chen
dd69403ee6 修正一些錯誤 2022-03-25 22:53:47 +08:00
shouchih_chen
3ce254f16d Merge branch 'birthday' of https://gitlab.com/portfolio91/namecreater into birthday 2022-03-25 22:36:50 +08:00
shouchih_chen
1216358657 commit build setting 2022-03-25 22:36:28 +08:00
793446dcd2 1. add two word template
2. add new background
2022-03-25 22:30:29 +08:00
4fa3d9dc1c fix bg type string '/r/n' 2022-02-20 11:07:11 +08:00
shouchih_chen
27a4eb5c8b marco mac/windows handle /r/n string 2022-02-20 07:53:55 +08:00
6025cc2913 finish birthday namecreater 2022-02-20 07:27:25 +08:00
615fa0e283 finish layout adjustment. 2022-02-19 08:44:26 +08:00
44 changed files with 908 additions and 506 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@
/*.opendb
/*.db
/_bin
/web_build
/buildwed

View File

@ -7,12 +7,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NameCreater", "NameCreater\
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B66B108B-6DA8-408D-936D-988FF8B6B722}.Debug|x64.ActiveCfg = Debug|x64
{B66B108B-6DA8-408D-936D-988FF8B6B722}.Debug|x64.Build.0 = Debug|x64
{B66B108B-6DA8-408D-936D-988FF8B6B722}.Debug|x86.ActiveCfg = Debug|Win32
{B66B108B-6DA8-408D-936D-988FF8B6B722}.Debug|x86.Build.0 = Debug|Win32
{B66B108B-6DA8-408D-936D-988FF8B6B722}.Release|x64.ActiveCfg = Release|x64
{B66B108B-6DA8-408D-936D-988FF8B6B722}.Release|x64.Build.0 = Release|x64
{B66B108B-6DA8-408D-936D-988FF8B6B722}.Release|x86.ActiveCfg = Release|Win32
{B66B108B-6DA8-408D-936D-988FF8B6B722}.Release|x86.Build.0 = Release|Win32
EndGlobalSection

View File

@ -1,12 +1,406 @@
#include "NameCreater.h"
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#include <QFontDatabase>
#include <QTextCodec>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QDateTime>
#include <QBuffer>
//#define BG_SAMPLE_PATH ":/NameCreater/resource/background_sample.jpg"
#define BG_SAMPLE_PATH ":/NameCreater/resource/background_number_smaple.jpg"
#define BG_PATH_FORMAT ":/NameCreater/resource/background_%1.jpg"
#define FONT_NAME "DFYuanStd-W8.otf"
#define FONT_PATH ":/NameCreater/_exp/DFYuanStd-W8.otf"
#define FONT_SIZE 120
//#define FONT_SIZE 74
#define BG_MIX_TYPE_STR "mix"
#define BG_BOY_TYPE_STR "boy"
#define BG_GIRL_TYPE_STR "girl"
#define VERSION "v1.2.0"
struct NameInfo_t {
QString name1;
QString name2;
QString bg_path;
bool is_number_bg;
};
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 BG_POS_COUNT = sizeof(BG_POS) / sizeof(BG_POS[0]);
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 QPointF NAME_POS_NUMBER[] = {
QPointF(240, 370), QPointF(372, 1442),
QPointF(564, 370), QPointF(694, 1442),
QPointF(883, 370), QPointF(1014, 1442),
QPointF(1205, 370), QPointF(1337, 1442),
QPointF(1532, 370), QPointF(1663, 1442),
QPointF(1854, 370), QPointF(1987, 1442),
QPointF(2176, 370), QPointF(2309, 1442),
QPointF(2498, 370), QPointF(2629, 1442),
QPointF(2821, 370), QPointF(2952, 1442),
QPointF(3145, 370), QPointF(3276, 1442),
QPointF(1228, 2012), QPointF(2280, 1880),
QPointF(1228, 2334), QPointF(2280, 2202),
};
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);
QPainter painter(&image);
scene->render(&painter);
#ifdef Q_OS_MAC
QString folder_name = QCoreApplication::applicationDirPath() + "/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#else
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);
}
image.save(QString(folder_name).append("/").append(filename), "JPG", 100);*/
; // obtained from e.g. QImage::save()
QByteArray imageData;
QBuffer buffer(&imageData);
buffer.open(QIODevice::WriteOnly);
QPixmap pixmap = QPixmap::fromImage(image);
pixmap.save(&buffer, "JPEG",100); // You can also use other formats like "JPEG" or "BMP"
QFileDialog::saveFileContent(imageData, filename);
}
QList<NameInfo_t> getNameByFile(const QString& filename) {
QList<NameInfo_t> nameList;
#ifdef Q_OS_MAC
QString root_path = QCoreApplication::applicationDirPath() + "/../../../";
#else
QString root_path = "";//QCoreApplication::applicationDirPath() + "/";
#endif
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox msgBox;
msgBox.setText(QString("Load file failed!").append(filename));
msgBox.exec();
file.close();
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(',');
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"));
type_str = type_str.remove(QRegExp("\n"));
if (name1.compare("name_1") == 0) {
continue;
}
info.name1 = name1;
info.bg_path = QString(BG_PATH_FORMAT).arg(type_str);
info.is_number_bg = type_str[0].isDigit();
nameList.append(info);
row++;
}
file.close();
return nameList;
}
QList<NameInfo_t> getNameByFileContent(const QByteArray& conetent) {
QList<NameInfo_t> nameList;
QTextCodec* tc = QTextCodec::codecForName("Big5");
QString codec = tc->toUnicode(conetent.data());
QTextStream stream(&codec);
int row = 0;
while (!stream.atEnd())
{
NameInfo_t info;
QString line = stream.readLine();
QString name_tc = line;
QStringList csvList = name_tc.split(',');
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"));
type_str = type_str.remove(QRegExp("\n"));
if (name1.compare("name_1") == 0) {
continue;
}
info.name1 = name1;
info.bg_path = QString(BG_PATH_FORMAT).arg(type_str);
info.is_number_bg = type_str[0].isDigit();
nameList.append(info);
row++;
}
return nameList;
}
void processCSV(const QString& filename, const QByteArray& filecontent, const QFont& font, const QColor& font_color) {
int export_times = 0;
//QList<NameInfo_t> nameList = getNameByFile(filename);
QList<NameInfo_t> nameList = getNameByFileContent(filecontent);
if (nameList.isEmpty()) {
QMessageBox msgBox;
msgBox.setText(QString("Name is empty ! ").append(filename));
msgBox.exec();
}
QGraphicsScene scene;
scene.setBackgroundBrush(QBrush(QColor(255, 255, 255)));
QGraphicsView view(&scene);
/*QImage image(BG_SAMPLE_PATH);
QGraphicsPixmapItem* bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(image));
scene.addItem(bgItem);*/
for (int n = 0; n < nameList.length(); n++) {
int idx = n % BG_POS_COUNT;
NameInfo_t name_info = nameList.at(n);
QImage name_image(name_info.bg_path);
if (idx == 0) {
QGraphicsRectItem* bg_item = new QGraphicsRectItem(0, 0, 3508, 2482);
bg_item->setBrush(QBrush(QColor(255, 255, 255)));
scene.addItem(bg_item);
}
QGraphicsPixmapItem* name_bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(name_image));
bool rot = (idx == 10 || idx == 11);
name_bgItem->setRotation(rot ? -90 : 0);
name_bgItem->setPos(BG_POS[idx]);
scene.addItem(name_bgItem);
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;
int name_len = name.length();
for (int j = 0; j < 2; j++) {
int pos_idx = idx * 2 + j;
int xscale, yscale;
xscale = yscale = (j == 1) ? -1 : 1;
QPointF pos = name_info.is_number_bg ? NAME_POS_NUMBER[pos_idx] : NAME_POS[pos_idx];
int y_offset[2] = { 0 };
if (name_len == 2) {
if (!rot) {
pos.setY(pos.y() + 82 * xscale);
}
else {
pos.setX(pos.x() + 82 * xscale);
}
y_offset[0] = 25;
}
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 + y_offset[0]) * xscale);
textItem2->setTransform(QTransform::fromScale(xscale, yscale));
}
else {
textItem2->setPos(pos.x() + (145 + y_offset[0]) * xscale, pos.y());
textItem2->setRotation(-90);
textItem2->setTransform(QTransform::fromScale(xscale, yscale));
}
scene.addItem(textItem2);
if (name_len > 2) {
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);
}
}
bool is_export_page = ((idx + 1) % BG_POS_COUNT == 0);
if (is_export_page || n == nameList.count() - 1) {
QString file_name = QString("%1_.jpg").arg(QString::number(export_times + 1));
saveToImage(file_name, &scene);
export_times++;
scene.clear();
}
}
QMessageBox msgBox;
msgBox.setText(QString().asprintf("Export Finshed. Count:%d", export_times));
msgBox.exec();
}
NameCreater::NameCreater(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.openfile_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
QString font_path = 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.exec();
font_res.close();
}
int id = QFontDatabase::addApplicationFontFromData(font_res.readAll());
QStringList family_list = QFontDatabase::applicationFontFamilies(id);
font = QFont(family_list.at(0));
font.setPixelSize(FONT_SIZE);
font_color = QColor(0, 0, 0);
QFont tital_font = QFont(font);
tital_font.setPixelSize(20);
QFont version_font = QFont(font);
version_font.setPixelSize(12);
ui.tital_label->setFont(tital_font);
ui.version_label->setFont(version_font);
ui.version_label->setText(VERSION);
font_res.close();
qDebug() << ui.label->font().family();
}
void NameCreater::OnClickedReadBtn() {
auto fileContentReady = [this](const QString &fileName, const QByteArray &fileContent) {
if (fileName.isEmpty()) {
// No file was selected
}
else {
// Use fileName and fileContent
processCSV(fileName, fileContent, this->font, this->font_color);
}
};
QFileDialog::getOpenFileContent("CSV (*.csv)", fileContentReady);
}

View File

@ -12,4 +12,10 @@ public:
private:
Ui::NameCreaterClass ui;
QFont font;
QColor font_color;
private Q_SLOTS:
void OnClickedReadBtn();
};

View File

@ -11,4 +11,4 @@ HEADERS += ./NameCreater.h
SOURCES += ./NameCreater.cpp \
./main.cpp
FORMS += ./NameCreater.ui
RESOURCES += ./NameCreater.qrc
RESOURCES += NameCreater.qrc

View File

@ -2,7 +2,7 @@ QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
CONFIG += c++11 resources_big
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 6.0.2, 2022-02-16T21:45:54. -->
<!-- Written by QtCreator 6.0.2, 2022-02-20T11:42:40. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -92,7 +92,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.15.2 clang 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.15.2 clang 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5152.clang_64_kit</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
@ -245,7 +245,7 @@
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/Users/shouchih_chen/Documents/namecreater/build-NameCreater-Desktop_Qt_5_15_2_clang_64bit-Debug/NameCreater.app/Contents/MacOS</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/Users/shouchih_chen/Documents/namecreater/build-NameCreater-Desktop_Qt_5_15_2_clang_64bit-Release/NameCreater.app/Contents/MacOS</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>

View File

@ -1,8 +1,32 @@
<RCC>
<qresource prefix="/NameCreater">
<file>resource/background.jpg</file>
<file>resource/background_sample.jpg</file>
<file>resource/background_boy.jpg</file>
<file>resource/background_girl.jpg</file>
</qresource>
<qresource prefix="/NameCreater">
<file>_exp/DFYuanStd-W8.otf</file>
<file>resource/background_sample.jpg</file>
<file>resource/background_b.jpg</file>
<file>resource/background_g.jpg</file>
<file>resource/background_r.jpg</file>
<file>resource/background_y.jpg</file>
<file>resource/two_word_sample.jpg</file>
<file>resource/background_1.jpg</file>
<file>resource/background_2.jpg</file>
<file>resource/background_3.jpg</file>
<file>resource/background_4.jpg</file>
<file>resource/background_5.jpg</file>
<file>resource/background_6.jpg</file>
<file>resource/background_7.jpg</file>
<file>resource/background_8.jpg</file>
<file>resource/background_9.jpg</file>
<file>resource/background_10.jpg</file>
<file>resource/background_number_smaple.jpg</file>
<file>resource/background_11.jpg</file>
<file>resource/background_12.jpg</file>
<file>resource/background_13.jpg</file>
<file>resource/background_14.jpg</file>
<file>resource/background_15.jpg</file>
<file>resource/background_16.jpg</file>
<file>resource/background_17.jpg</file>
<file>resource/background_18.jpg</file>
<file>resource/background_19.jpg</file>
<file>resource/background_20.jpg</file>
</qresource>
</RCC>

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>977</width>
<height>716</height>
<width>532</width>
<height>458</height>
</rect>
</property>
<property name="font">
@ -16,12 +16,20 @@
<property name="windowTitle">
<string>NameCreater</string>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(0, 0, 0);</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="styleSheet">
<string notr="true">QWidget#centralWidget{
background-color: rgb(0, 0, 0);
}</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>240</x>
<y>220</y>
<x>470</x>
<y>40</y>
<width>441</width>
<height>261</height>
</rect>
@ -33,7 +41,78 @@
<string/>
</property>
<property name="pixmap">
<pixmap resource="NameCreater.qrc">:/NameCreater/resource/background.jpg</pixmap>
<pixmap>:/NameCreater/resource/background.jpg</pixmap>
</property>
</widget>
<widget class="QPushButton" name="openfile_btn">
<property name="geometry">
<rect>
<x>80</x>
<y>100</y>
<width>181</width>
<height>161</height>
</rect>
</property>
<property name="text">
<string>Open File</string>
</property>
</widget>
<widget class="QLabel" name="tital_label">
<property name="geometry">
<rect>
<x>50</x>
<y>20</y>
<width>261</width>
<height>71</height>
</rect>
</property>
<property name="font">
<font>
<family>Yu Gothic UI</family>
<pointsize>20</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
</string>
</property>
<property name="text">
<string>五入組拆成單入產生器</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="version_label">
<property name="geometry">
<rect>
<x>50</x>
<y>60</y>
<width>261</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<family>Yu Gothic UI</family>
<pointsize>10</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 255, 255);
</string>
</property>
<property name="text">
<string>五入組拆成單入產生器</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
@ -42,8 +121,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>977</width>
<height>22</height>
<width>532</width>
<height>21</height>
</rect>
</property>
</widget>
@ -56,6 +135,11 @@
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionOpen_File">
<property name="text">
<string>Open File</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>

View File

@ -5,24 +5,42 @@
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B66B108B-6DA8-408D-936D-988FF8B6B722}</ProjectGuid>
<Keyword>QtVS_v304</Keyword>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'">10.0.19041.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'">10.0.19041.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'">10.0.16299.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">10.0.19041.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'">10.0.16299.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)'=='Release|x64'">10.0.19041.0</WindowsTargetPlatformVersion>
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
@ -31,6 +49,11 @@
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'" Label="QtSettings">
<QtInstall>5.8_msvc2015</QtInstall>
<QtModules>core;gui;widgets</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="QtSettings">
<QtInstall>$(DefaultQtVersion)</QtInstall>
<QtModules>core;gui;widgets</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
@ -40,6 +63,11 @@
<QtModules>core;gui;widgets</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="QtSettings">
<QtInstall>$(DefaultQtVersion)</QtInstall>
<QtModules>core;gui;widgets</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
<Message Importance="High" Text="QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly." />
</Target>
@ -49,15 +77,24 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(QtMsBuild)\Qt.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(QtMsBuild)\Qt.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(QtMsBuild)\Qt.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(QtMsBuild)\Qt.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'">
<OutDir>$(SolutionDir)_bin\</OutDir>
<IntDir>$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'">
<OutDir>$(SolutionDir)_bin\</OutDir>
<IntDir>$(Configuration)\</IntDir>
@ -66,12 +103,25 @@
<PreBuildEvent>
<Command>xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)"</Command>
</PreBuildEvent>
<ClCompile>
<AdditionalOptions>/Zm1000</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PreBuildEvent>
<Command>xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PreBuildEvent>
<Command>xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PreBuildEvent>
<Command>xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'" Label="Configuration">
<ClCompile>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
@ -85,6 +135,19 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ClCompile>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'" Label="Configuration">
<ClCompile>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
@ -98,6 +161,19 @@
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ClCompile>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<DebugInformationFormat>None</DebugInformationFormat>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<QtRcc Include="NameCreater.qrc" />
<QtUic Include="NameCreater.ui" />

View File

@ -4,14 +4,28 @@
<LocalDebuggerWorkingDirectory>$(TargetDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(TargetDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>$(TargetDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(TargetDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<QtLastBackgroundBuild>2023-02-07T09:42:35.8095077Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="QtSettings">
<QtLastBackgroundBuild>2022-02-09T21:34:52.5655210Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<QtLastBackgroundBuild>2022-02-09T21:34:53.9897137Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="QtSettings">
<QtLastBackgroundBuild>2022-02-09T21:34:53.9897137Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>

View File

@ -1,4 +1,26 @@
name_1,name_2,bg_type
ÄŹ´éśŁ,ÄŹ¤_ŽŚ,mix
łŻĽKŽŚ,łŻŹfżÎ,boy
§őŤBŞä,§őŤBŞä,girl
name_1,bg_type
艾小沙,1
夏小,2
吳苡需,3
尹小,4
艾小,5
夏小,g
吳苡,b
尹小,y
艾小,r
夏小,g
艾小,6
夏小天,7
艾小沙,8
夏小,9
吳苡需,10
陳守志,11
陳宣愉,12
吳佳鈴,13
陳守志,14
陳宣愉,15
吳佳鈴,16
陳守志,17
陳宣愉,18
吳佳鈴,19
艾小沙,20

1 name_1 name_2 bg_type
2 ÄŹ´éśŁ 艾小沙 ÄŹ¤_ŽŚ mix 1
3 łŻĽKŽŚ 夏小 łŻŹfżÎ boy 2
4 §őŤBŞä 吳苡需 §őŤBŞä girl 3
5 尹小 4
6 艾小 5
7 夏小 g
8 吳苡 b
9 尹小 y
10 艾小 r
11 夏小 g
12 艾小 6
13 夏小天 7
14 艾小沙 8
15 夏小 9
16 吳苡需 10
17 陳守志 11
18 陳宣愉 12
19 吳佳鈴 13
20 陳守志 14
21 陳宣愉 15
22 吳佳鈴 16
23 陳守志 17
24 陳宣愉 18
25 吳佳鈴 19
26 艾小沙 20

View File

@ -1,237 +1,11 @@
#include "NameCreater.h"
#include <QtWidgets/QApplication>
#include <QTextCodec>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QGraphicsTextItem>
#include <QFile>
#include <QDebug>
#include <QMessageBox>
#include <QDir>
#include <QDateTime>
#include <QFontDatabase>
#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 FONT_NAME "DFYuanStd-W8.otf"
#define FONT_SIZE 120
//#define FONT_SIZE 74
#define BG_MIX_TYPE_STR "mix"
#define BG_BOY_TYPE_STR "boy"
#define BG_GIRL_TYPE_STR "girl"
struct NameInfo_t {
QString name1;
QString name2;
int bg_type;
};
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 int BOY_POS_COUNT = sizeof(BOY_POS) / sizeof(BOY_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 int GIRL_POS_COUNT = sizeof(GIRL_POS) / sizeof(GIRL_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);
QPainter painter(&image);
scene->render(&painter);
#ifdef Q_OS_MAC
QString folder_name = QCoreApplication::applicationDirPath()+"/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#else
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);
}
image.save(QString(folder_name).append("/").append(filename), "JPG", 100);
}
QList<NameInfo_t> getNameByFile(const QString& filename) {
QList<NameInfo_t> nameList;
#ifdef Q_OS_MAC
QString root_path = QCoreApplication::applicationDirPath() + "/../../../";
#else
QString root_path = QCoreApplication::applicationDirPath() + "/";
#endif
QFile file(root_path.append(filename));
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox msgBox;
msgBox.setText("Load file failed!");
msgBox.exec();
file.close();
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(',');
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;
if (name1.compare("name_1") == 0 || name2.compare("name_2") == 0) {
continue;
}
info.name1 = name1;
info.name2 = name2;
info.bg_type = type_str.contains(QRegExp("boy")) ? 1 : (type_str.contains(QRegExp("girl"))) ? 2 : 0;
nameList.append(info);
row++;
}
file.close();
return nameList;
}
int main(int argc, char* argv[])
{
int export_times = 0;
QApplication a(argc, argv);
// NameCreater w;
// w.show();
#ifdef Q_OS_MAC
QString root_path = QCoreApplication::applicationDirPath() + "/../../../";
#else
QString root_path = QCoreApplication::applicationDirPath() + "/";
#endif
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.exec();
font_res.close();
return 0;
}
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);
QList<NameInfo_t> nameList = getNameByFile("name.csv");
if (nameList.isEmpty()) {
QMessageBox msgBox;
msgBox.setText(("Name is empty !"));
msgBox.exec();
}
QGraphicsScene scene;
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);
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++;
}
QMessageBox msgBox;
msgBox.setText(QString().asprintf("Export Finshed. Count:%d",export_times));
msgBox.exec();
font_res.close();
return 0;
QApplication a(argc, argv);
NameCreater w;
w.show();
return a.exec();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 KiB