From cee62df1871ab9e061d658e301514e930698f2f3 Mon Sep 17 00:00:00 2001 From: JackLee <809262979@qq.com> Date: Sun, 23 Mar 2025 18:36:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3Cmake-GFM=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E5=90=8D=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 ++ src/ctaiHistoryTextEdit.cpp | 3 ++- src/ctaiHistoryTextEdit.h | 2 ++ src/ctaiMathConvert.cpp | 12 ++++++------ src/ctaiMathConvert.h | 17 ++++++++++------- src/main.cpp | 25 ++++++++++++------------- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9152f1..98c4b51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,8 @@ include_directories(${JSON}/include) find_package(CURL REQUIRED) #cmark-gfm +add_definitions(-DCMARK_GFM_STATIC_DEFINE) +add_definitions(-DCMARK_STATIC_DEFINE) 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/extensions) diff --git a/src/ctaiHistoryTextEdit.cpp b/src/ctaiHistoryTextEdit.cpp index 75fa99e..b1583c6 100644 --- a/src/ctaiHistoryTextEdit.cpp +++ b/src/ctaiHistoryTextEdit.cpp @@ -39,6 +39,7 @@ void ctaiHistoryTextEdit::initMsgHistoryLayout() history_layout = new QVBoxLayout(); // 历史信息QTextEdit m_msg_history = new QTextEdit(); + m_cef_widget=new CefWidget(); m_math_convert = new ctaiMathConvert(); m_msg_history->setUndoRedoEnabled(false); // 关闭撤销历史以节省内存 m_msg_history->setAcceptRichText(true); @@ -46,7 +47,7 @@ void ctaiHistoryTextEdit::initMsgHistoryLayout() m_msg_history->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); m_msg_history->setObjectName("m_msg_history"); m_msg_history->setReadOnly(true); - history_layout->addWidget(m_msg_history); + history_layout->addWidget(m_cef_widget); history_layout->addWidget(msg_line); history_layout->setContentsMargins(0, 0, 0, 0); } diff --git a/src/ctaiHistoryTextEdit.h b/src/ctaiHistoryTextEdit.h index 5a398b8..8619198 100644 --- a/src/ctaiHistoryTextEdit.h +++ b/src/ctaiHistoryTextEdit.h @@ -37,6 +37,7 @@ #include "ctai_base.h" #include "ctaiMathConvert.h" #include "ctaiHistoryTools.h" +#include "QCefWidget/CefWidget.h" std::mutex m_mutex; class ctaiHistoryTextEdit : public QWidget { @@ -72,6 +73,7 @@ private: void connect_signals(msg_type msg_type_mode); // 连接信号和槽 void set_default_opts(); private: + CefWidget* m_cef_widget={}; ctaiMathConvert *m_math_convert; QFrame *msg_line; QSpacerItem *sparcer_item = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed); diff --git a/src/ctaiMathConvert.cpp b/src/ctaiMathConvert.cpp index 51b653f..8a0216e 100644 --- a/src/ctaiMathConvert.cpp +++ b/src/ctaiMathConvert.cpp @@ -126,11 +126,11 @@ QString ctaiMathConvert::markdown_to_html(const QString &text) CMARK_OPT_FOOTNOTES | CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE | CMARK_OPT_TABLE_PREFER_STYLE_ATTRIBUTES | - CMARK_NODE_TEXT| + cmark::CMARK_NODE_TEXT| CMARK_OPT_FULL_INFO_STRING; // 解析Markdown为AST - cmark_node *doc = cmark_parse_document(markdown.constData(), markdown.size(), options); + cmark::cmark_node *doc = cmark::cmark_parse_document(markdown.constData(), markdown.size(), options); if (debug_node_print) { // 递归打印AST节点 @@ -158,13 +158,13 @@ void ctaiMathConvert::replace_symbol(QString &context) } } // 添加新的辅助方法用于打印AST节点 -void ctaiMathConvert::print_ast_node(cmark_node *node, int level) +void ctaiMathConvert::print_ast_node(cmark::cmark_node *node, int level) { if (!node) return; // 获取节点类型 - const char *type_str = cmark_node_get_type_string(node); + const char *type_str = cmark::cmark_node_get_type_string(node); // 打印缩进和节点类型 QString indent = QString(" ").repeated(level * 2); @@ -178,11 +178,11 @@ void ctaiMathConvert::print_ast_node(cmark_node *node, int level) } // 递归处理子节点 - cmark_node *child = cmark_node_first_child(node); + cmark::cmark_node *child = cmark_node_first_child(node); while (child) { print_ast_node(child, level + 1); - child = cmark_node_next(child); + child = cmark::cmark_node_next(child); } } diff --git a/src/ctaiMathConvert.h b/src/ctaiMathConvert.h index 4b45131..cfb5a73 100644 --- a/src/ctaiMathConvert.h +++ b/src/ctaiMathConvert.h @@ -1,12 +1,7 @@ #ifndef CTAIMATHCONVERT_H #define CTAIMATHCONVERT_H -// 然后包含 cmark-gfm 相关头文件 -#include "cmark-gfm.h" -#include "cmark-gfm-extension_api.h" -#include "cmark-gfm-core-extensions.h" -#include -// Qt 相关头文件 +// Qt 相关头文件放在最前面 #include #include #include @@ -19,6 +14,14 @@ #include #include +// 使用命名空间来隔离 cmark-gfm +namespace cmark { + #include "cmark-gfm.h" + #include "cmark-gfm-extension_api.h" + #include "cmark-gfm-core-extensions.h" + #include +} + // LaTeX 相关头文件 #include "latex.h" #include "platform/qt/graphic_qt.h" @@ -55,7 +58,7 @@ private: QByteArray svg_to_base64(QPixmap& pix); QString markdown_to_html(const QString& text); QString fix_img_str_line_height(QString html); - void print_ast_node(cmark_node *node, int level); + void print_ast_node(cmark::cmark_node *node, int level); void replace_symbol(QString& context); void replace_css(QString& context); TexGuard texGuard; diff --git a/src/main.cpp b/src/main.cpp index 1f48f6a..a7fcb78 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,10 +19,10 @@ int main(int argc, char *argv[]) config.addCommandLineSwitch("use-alloy-style"); config.addCommandLineSwitch("off-screen-rendering-enabled"); config.addCommandLineSwitch("multi-threaded-message-loop"); - //config.addCommandLineSwitch("external-message-pump"); - //config.addCommandLineSwitch("enable-chrome-runtime"); - //config.addCommandLineSwitch("enable-gpu"); - //config.addCommandLineSwitch("use-views"); + config.addCommandLineSwitch("external-message-pump"); + config.addCommandLineSwitch("enable-chrome-runtime"); + config.addCommandLineSwitch("enable-gpu"); + config.addCommandLineSwitch("use-views"); //config.addCommandLineSwitch("site-per-process"); config.addCommandLineSwitch("no-sandbox"); //config.addCommandLineSwitch("in-process-gpu"); @@ -30,17 +30,16 @@ int main(int argc, char *argv[]) config.addCommandLineSwitch("enable-chrome-runtime"); config.addCommandLineSwitch("start-stack-profiler"); //config.addCommandLineSwitchWithValue("type","gpu-process"); - //config.addCommandLineSwitchWithValue("ignore-certificate-errors","true"); - //config.addCommandLineSwitchWithValue("enable-gpu-rasterizatio","true"); - //config.addCommandLineSwitchWithValue("enable-accelerated-video","true"); - //config.addCommandLineSwitchWithValue("use-fake-ui-for-media-stream","true"); - //config.addCommandLineSwitchWithValue("use-fake-device-for-media-stream","true"); + config.addCommandLineSwitchWithValue("ignore-certificate-errors","true"); + config.addCommandLineSwitchWithValue("enable-gpu-rasterizatio","true"); + config.addCommandLineSwitchWithValue("enable-accelerated-video","true"); + config.addCommandLineSwitchWithValue("use-fake-ui-for-media-stream","true"); + config.addCommandLineSwitchWithValue("use-fake-device-for-media-stream","true"); //config.addCommandLineSwitchWithValue("renderer-process-limit", "1"); - //config.addCommandLineSwitchWithValue("disable-features", "BlinkGenPropertyTrees,TranslateUI,site-per-process"); + config.addCommandLineSwitchWithValue("disable-features", "BlinkGenPropertyTrees,TranslateUI,site-per-process"); QCefContext cefContext(&a, argc, argv, &config); - - CefWidget cw; - cw.show(); + //CefWidget cw; + //cw.show(); qputenv("QT_QPA_PLATFORM", "windows:fontengine=freetype"); // 加载语言包 QTranslator qtBaseTranslator;