Compare commits
No commits in common. "097f3f542667078b662ffb0e54b55a8843c21784" and "1174f3ff61f77c113ca1e2985afe5d84c2dec458" have entirely different histories.
097f3f5426
...
1174f3ff61
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -102,9 +102,7 @@
|
|||||||
"qtimer": "cpp",
|
"qtimer": "cpp",
|
||||||
"qstring": "cpp",
|
"qstring": "cpp",
|
||||||
"qabstracttextdocumentlayout": "cpp",
|
"qabstracttextdocumentlayout": "cpp",
|
||||||
"qframe": "cpp",
|
"qframe": "cpp"
|
||||||
"qpixmap": "cpp",
|
|
||||||
"qpainter": "cpp"
|
|
||||||
},
|
},
|
||||||
"editor.gotoLocation.alternativeDeclarationCommand": "editor.action.revealDefinition",
|
"editor.gotoLocation.alternativeDeclarationCommand": "editor.action.revealDefinition",
|
||||||
"editor.gotoLocation.alternativeDefinitionCommand": "editor.action.revealDefinition",
|
"editor.gotoLocation.alternativeDefinitionCommand": "editor.action.revealDefinition",
|
||||||
|
|||||||
1
3rdparty/MicroTeX
vendored
Submodule
1
3rdparty/MicroTeX
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 086f4eb740270b28bd0c61a0a359aea9300d61ae
|
||||||
@ -62,13 +62,13 @@ include_directories(${JSON}/include)
|
|||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
|
|
||||||
#cmark-gfm
|
#cmark-gfm
|
||||||
#add_subdirectory(${PROJECT_SOURCE_DIR}/3rdparty/cmark-gfm)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/3rdparty/cmark-gfm)
|
||||||
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cmark-gfm/src)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cmark-gfm/src)
|
||||||
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cmark-gfm/extensions)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cmark-gfm/extensions)
|
||||||
|
|
||||||
#MicroTeX
|
#MicroTeX
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/3rdparty/MicroTeX)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/3rdparty/MicroTeX)
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/MicroTeX/src)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/MicroTeX/lib)
|
||||||
|
|
||||||
#查找QT模块
|
#查找QT模块
|
||||||
FIND_PACKAGE(Qt6 REQUIRED Core Gui Widgets)
|
FIND_PACKAGE(Qt6 REQUIRED Core Gui Widgets)
|
||||||
@ -148,9 +148,9 @@ target_link_libraries(
|
|||||||
Qt6::Gui
|
Qt6::Gui
|
||||||
Qt6::Widgets
|
Qt6::Widgets
|
||||||
CURL::libcurl
|
CURL::libcurl
|
||||||
#libcmark-gfm-extensions_static
|
libcmark-gfm-extensions_static
|
||||||
#libcmark-gfm_static
|
libcmark-gfm_static
|
||||||
LaTeX
|
microtex
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -91,7 +91,6 @@ void ctai_history_textedit::init_layout(msg_type msg_type_mode)
|
|||||||
// 5. 历史信息QTextEdit
|
// 5. 历史信息QTextEdit
|
||||||
historyLayout = new QVBoxLayout();
|
historyLayout = new QVBoxLayout();
|
||||||
m_msg_history = new QTextEdit();
|
m_msg_history = new QTextEdit();
|
||||||
m_math_convert=new ctai_math_convert();
|
|
||||||
m_msg_history->setUndoRedoEnabled(false); // 关闭撤销历史以节省内存
|
m_msg_history->setUndoRedoEnabled(false); // 关闭撤销历史以节省内存
|
||||||
m_msg_history->setAcceptRichText(true);
|
m_msg_history->setAcceptRichText(true);
|
||||||
m_msg_history->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_msg_history->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
@ -260,7 +259,6 @@ void ctai_history_textedit::add_user_message(const model_data &message)
|
|||||||
disp_data = QSL(message.send_user_data);
|
disp_data = QSL(message.send_user_data);
|
||||||
m_msg_sned_id = QSL(message.send_user_id);
|
m_msg_sned_id = QSL(message.send_user_id);
|
||||||
m_msg_history->setMarkdown(disp_data);
|
m_msg_history->setMarkdown(disp_data);
|
||||||
m_math_convert->math_convert_svg(disp_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctai_history_textedit::add_system_message(const model_data &message)
|
void ctai_history_textedit::add_system_message(const model_data &message)
|
||||||
|
|||||||
@ -71,7 +71,7 @@ signals:
|
|||||||
private:
|
private:
|
||||||
void connect_signals(msg_type msg_type_mode);// 连接信号和槽
|
void connect_signals(msg_type msg_type_mode);// 连接信号和槽
|
||||||
private:
|
private:
|
||||||
ctai_math_convert* m_math_convert;
|
ctai_math_convert* m_cmark_gfm;
|
||||||
QFrame *hLine;
|
QFrame *hLine;
|
||||||
QSpacerItem *sparcer_item = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
|
QSpacerItem *sparcer_item = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
QVBoxLayout *mainLayout={};
|
QVBoxLayout *mainLayout={};
|
||||||
|
|||||||
@ -2,48 +2,15 @@
|
|||||||
|
|
||||||
ctai_math_convert::ctai_math_convert()
|
ctai_math_convert::ctai_math_convert()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctai_math_convert::~ctai_math_convert()
|
ctai_math_convert::~ctai_math_convert() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctai_math_convert::set_convert_opts()
|
void ctai_math_convert::math_convert_svg(const QString& text) {
|
||||||
{
|
|
||||||
}
|
|
||||||
void ctai_math_convert::save_svg(QPixmap &img, const QString &svg)
|
|
||||||
{
|
|
||||||
QString uid = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
|
||||||
QString svgName = QDir::currentPath() + "/svg/" + uid + ".png";
|
|
||||||
bool ok = img.save(svgName);
|
|
||||||
}
|
|
||||||
QByteArray ctai_math_convert::svg_to_base64(QPixmap &pix)
|
|
||||||
{
|
|
||||||
|
|
||||||
QByteArray data;
|
|
||||||
QBuffer buffer(&data);
|
|
||||||
QImage img = pix.toImage();
|
|
||||||
|
|
||||||
img.save(&buffer, "PNG");
|
|
||||||
data = data.toBase64();
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
void ctai_math_convert::math_convert_svg(const QString &latex)
|
|
||||||
{
|
|
||||||
auto render = tex::LaTeX::parse(latex.toStdWString(), m_width, m_text_size, m_lineSpace, m_color);
|
|
||||||
qDebug() << render->getWidth() << render->getHeight();
|
|
||||||
QPixmap pix(render->getWidth(), render->getHeight());
|
|
||||||
pix.fill(Qt::white);
|
|
||||||
QPainter painter(&pix);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
tex::Graphics2D_qt g2(&painter);
|
|
||||||
render->draw(g2, 0, 0);
|
|
||||||
if (save_mode)
|
|
||||||
{
|
|
||||||
save_svg(pix, latex);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "svg_to_base64:" << QString::fromUtf8(svg_to_base64(pix));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
void ctai_math_convert::svg_convert_base64() {
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,48 +1,21 @@
|
|||||||
#ifndef CTAI_MATH_CONVERT_H
|
#ifndef CTAI_MATH_CONVERT_H
|
||||||
#define CTAI_MATH_CONVERT_H
|
#define CTAI_MATH_CONVERT_H
|
||||||
|
|
||||||
#include "latex.h"
|
#include "microtex.h"
|
||||||
#include "platform/qt/graphic_qt.h"
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QDir>
|
#include <QTimer>
|
||||||
#include <QBuffer>
|
|
||||||
#include <QUuid>
|
|
||||||
class TexGuard {
|
|
||||||
public:
|
|
||||||
TexGuard() {
|
|
||||||
tex::LaTeX::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
~TexGuard() {
|
|
||||||
tex::LaTeX::release();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class ctai_math_convert :public QObject
|
class ctai_math_convert {
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
explicit ctai_math_convert();
|
explicit ctai_math_convert();
|
||||||
~ctai_math_convert();
|
~ctai_math_convert();
|
||||||
// 追加内容并处理Markdown
|
// 追加内容并处理Markdown
|
||||||
void math_convert_svg(const QString& text);
|
void math_convert_svg(const QString& text);
|
||||||
void set_convert_opts();
|
void svg_convert_base64();
|
||||||
void save_svg(QPixmap& img,const QString& svg);
|
|
||||||
QByteArray svg_to_base64(QPixmap& pix);
|
|
||||||
private:
|
private:
|
||||||
TexGuard texGuard;
|
|
||||||
//宽度
|
|
||||||
int m_width=600;
|
|
||||||
//文本大小
|
|
||||||
int m_text_size=20;
|
|
||||||
//行距
|
|
||||||
float m_lineSpace=20 / 3.f;
|
|
||||||
//颜色
|
|
||||||
tex::color m_color=0xff424242;
|
|
||||||
//处理后保存模式
|
|
||||||
bool save_mode=false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user