diff --git a/hgmarkdownhighlighter.cpp b/hgmarkdownhighlighter.cpp index 710c73fe..17dba3ab 100644 --- a/hgmarkdownhighlighter.cpp +++ b/hgmarkdownhighlighter.cpp @@ -52,7 +52,7 @@ void WorkerThread::resizeBuffer(int newCap) void WorkerThread::prepareAndStart(const char *data) { Q_ASSERT(data); - int len = strlen(data); + int len = int(strlen(data)); if (len >= capacity) { resizeBuffer(qMax(2 * capacity, len + 1)); } @@ -245,6 +245,7 @@ void HGMarkdownHighlighter::handleContentsChange(int position, int charsRemoved, if (charsRemoved == 0 && charsAdded == 0) return; + position; timer->stop(); timer->start(); } diff --git a/resources/styles/default.mdhl b/resources/styles/default.mdhl index 9315de1d..0148f810 100644 --- a/resources/styles/default.mdhl +++ b/resources/styles/default.mdhl @@ -2,7 +2,7 @@ # Created by Le Tan (tamlokveer@gmail.com) editor -font-family: Georgia, Palatino, Arial, serif +font-family: Microsoft YaHei, WenQuanYi Micro Hei, Droid Sans, SimSun, Georgia, Palatino, Arial, serif H1 foreground: 111111 diff --git a/vconfigmanager.cpp b/vconfigmanager.cpp index dd6b74c1..847ce4d2 100644 --- a/vconfigmanager.cpp +++ b/vconfigmanager.cpp @@ -95,5 +95,7 @@ void VConfigManager::updateMarkdownEditStyle() VStyleParser parser; parser.parseMarkdownStyle(styleStr); mdHighlightingStyles = parser.fetchMarkdownStyles(baseEditFont); - mdEditPalette = parser.fetchMarkdownEditorStyles(baseEditPalette); + mdEditPalette = baseEditPalette; + mdEditFont = baseEditFont; + parser.fetchMarkdownEditorStyles(mdEditPalette, mdEditFont); } diff --git a/vconfigmanager.h b/vconfigmanager.h index 9ba2d4e5..c1ff160a 100644 --- a/vconfigmanager.h +++ b/vconfigmanager.h @@ -25,6 +25,7 @@ public: QFont baseEditFont; QPalette baseEditPalette; + QFont mdEditFont; QPalette mdEditPalette; QVector mdHighlightingStyles; diff --git a/vedit.cpp b/vedit.cpp index 326bb793..84bfd5da 100644 --- a/vedit.cpp +++ b/vedit.cpp @@ -6,9 +6,11 @@ VEdit::VEdit(VNoteFile *noteFile, QWidget *parent) : QTextEdit(parent), noteFile(noteFile) { - setFont(VConfigInst->baseEditFont); if (noteFile->docType == DocType::Markdown) { setPalette(VConfigInst->mdEditPalette); + setFont(VConfigInst->mdEditFont); + } else { + setFont(VConfigInst->baseEditFont); } } diff --git a/vstyleparser.cpp b/vstyleparser.cpp index a18440da..ea7718d6 100644 --- a/vstyleparser.cpp +++ b/vstyleparser.cpp @@ -77,8 +77,8 @@ QTextCharFormat VStyleParser::QTextCharFormatFromAttrs(pmh_style_attribute *attr if (!finalFamily.isEmpty()) { format.setFontFamily(finalFamily); } - } break; + } case pmh_attr_type_font_style: { @@ -128,10 +128,8 @@ QVector VStyleParser::fetchMarkdownStyles(const QFont &baseFo return styles; } -QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) const +void VStyleParser::fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const { - QPalette palette(basePalette); - // editor pmh_style_attribute *editorStyles = markdownStyles->editor_styles; while (editorStyles) { @@ -146,6 +144,16 @@ QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) co QColorFromPmhAttr(editorStyles->value->argb_color)); break; + case pmh_attr_type_font_family: + { + QString familyList(editorStyles->value->font_family); + QString finalFamily = filterAvailableFontFamily(familyList); + if (!finalFamily.isEmpty()) { + font.setFamily(finalFamily); + } + break; + } + default: qWarning() << "warning: unimplemented editor attr type:" << editorStyles->type; } @@ -177,8 +185,6 @@ QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) co } selStyles = selStyles->next; } - - return palette; } // @familyList is a comma separated string diff --git a/vstyleparser.h b/vstyleparser.h index deff8829..6938a168 100644 --- a/vstyleparser.h +++ b/vstyleparser.h @@ -22,7 +22,7 @@ public: void parseMarkdownStyle(const QString &styleStr); QVector fetchMarkdownStyles(const QFont &baseFont) const; - QPalette fetchMarkdownEditorStyles(const QPalette &basePalette) const; + void fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const; private: QColor QColorFromPmhAttr(pmh_attr_argb_color *attr) const;