From e3437e9bb6783d9fa63a92d524c025cb30f5d87e Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Sun, 17 Mar 2024 15:36:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E5=AE=8C?= =?UTF-8?q?=E5=85=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QtNovels.sln | 6 + QtNovels/QtNovels.vcxproj | 27 ++- QtNovels/QtNovels.vcxproj.filters | 16 +- WsTextEdit/WsTextEdit.vcxproj | 98 ++++++++++ WsTextEdit/WsTextEdit.vcxproj.filters | 37 ++++ WsTextEdit/wstextedit.cpp | 5 + WsTextEdit/wstextedit.h | 9 + WsTextEdit/wstextedit_global.h | 13 ++ libWsTextEdit/libWsTextEdit.vcxproj | 102 +++++++++++ libWsTextEdit/libWsTextEdit.vcxproj.filters | 52 ++++++ libWsTextEdit/libwstextedit.cpp | 5 + libWsTextEdit/libwstextedit.h | 9 + libWsTextEdit/libwstextedit_global.h | 13 ++ libWsTextEdit/textmodels.cpp | 147 +++++++++++++++ libWsTextEdit/textmodels.h | 103 +++++++++++ libWsTextEdit/textpresents.cpp | 192 ++++++++++++++++++++ libWsTextEdit/textpresents.h | 81 +++++++++ 17 files changed, 889 insertions(+), 26 deletions(-) create mode 100644 WsTextEdit/WsTextEdit.vcxproj create mode 100644 WsTextEdit/WsTextEdit.vcxproj.filters create mode 100644 WsTextEdit/wstextedit.cpp create mode 100644 WsTextEdit/wstextedit.h create mode 100644 WsTextEdit/wstextedit_global.h create mode 100644 libWsTextEdit/libWsTextEdit.vcxproj create mode 100644 libWsTextEdit/libWsTextEdit.vcxproj.filters create mode 100644 libWsTextEdit/libwstextedit.cpp create mode 100644 libWsTextEdit/libwstextedit.h create mode 100644 libWsTextEdit/libwstextedit_global.h create mode 100644 libWsTextEdit/textmodels.cpp create mode 100644 libWsTextEdit/textmodels.h create mode 100644 libWsTextEdit/textpresents.cpp create mode 100644 libWsTextEdit/textpresents.h diff --git a/QtNovels.sln b/QtNovels.sln index 8dd2b2f..76d88c7 100644 --- a/QtNovels.sln +++ b/QtNovels.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.34112.143 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QtNovels", "QtNovels\QtNovels.vcxproj", "{ECED0F1E-01F4-4FBB-BFC0-6A43BA55A52B}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libWsTextEdit", "libWsTextEdit\libWsTextEdit.vcxproj", "{DB6BC034-92EF-457C-B1B9-7997857E782B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -15,6 +17,10 @@ Global {ECED0F1E-01F4-4FBB-BFC0-6A43BA55A52B}.Debug|x64.Build.0 = Debug|x64 {ECED0F1E-01F4-4FBB-BFC0-6A43BA55A52B}.Release|x64.ActiveCfg = Release|x64 {ECED0F1E-01F4-4FBB-BFC0-6A43BA55A52B}.Release|x64.Build.0 = Release|x64 + {DB6BC034-92EF-457C-B1B9-7997857E782B}.Debug|x64.ActiveCfg = Debug|x64 + {DB6BC034-92EF-457C-B1B9-7997857E782B}.Debug|x64.Build.0 = Debug|x64 + {DB6BC034-92EF-457C-B1B9-7997857E782B}.Release|x64.ActiveCfg = Release|x64 + {DB6BC034-92EF-457C-B1B9-7997857E782B}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/QtNovels/QtNovels.vcxproj b/QtNovels/QtNovels.vcxproj index 5307bc1..448e778 100644 --- a/QtNovels/QtNovels.vcxproj +++ b/QtNovels/QtNovels.vcxproj @@ -13,19 +13,18 @@ {ECED0F1E-01F4-4FBB-BFC0-6A43BA55A52B} QtVS_v304 - 10.0.22621.0 + 10.0 10.0.22621.0 - $(MSBuildProjectDirectory)\QtMsBuild + $(MSBuildProjectDirectory)\QtMsBuild Application - v141 + v143 Application - v141 + v143 @@ -41,11 +40,8 @@ core;gui;widgets release - - + + @@ -87,12 +83,11 @@ - - - - - - + + + + + diff --git a/QtNovels/QtNovels.vcxproj.filters b/QtNovels/QtNovels.vcxproj.filters index e61a814..3d621c7 100644 --- a/QtNovels/QtNovels.vcxproj.filters +++ b/QtNovels/QtNovels.vcxproj.filters @@ -35,14 +35,10 @@ Source Files - - - - Resource Files - - - Resource Files - - - + + + Source Files + + + \ No newline at end of file diff --git a/WsTextEdit/WsTextEdit.vcxproj b/WsTextEdit/WsTextEdit.vcxproj new file mode 100644 index 0000000..951bb18 --- /dev/null +++ b/WsTextEdit/WsTextEdit.vcxproj @@ -0,0 +1,98 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {D65CAF69-595C-445C-845B-8707EFA1ECC4} + QtVS_v304 + 10.0.22621.0 + 10.0.22621.0 + $(MSBuildProjectDirectory)\QtMsBuild + + + + DynamicLibrary + v141 + + + DynamicLibrary + v141 + + + + + + + 5.12.11_msvc2017_64 + core;xml;gui;widgets + debug + + + 5.12.11_msvc2017_64 + core + release + + + + + + + + + + + + + + + + + + + + + + true + true + ProgramDatabase + Disabled + WSTEXTEDIT_LIB;%(PreprocessorDefinitions) + + + Windows + true + + + + + true + true + None + MaxSpeed + WSTEXTEDIT_LIB;%(PreprocessorDefinitions) + + + Windows + false + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WsTextEdit/WsTextEdit.vcxproj.filters b/WsTextEdit/WsTextEdit.vcxproj.filters new file mode 100644 index 0000000..d3cc3cd --- /dev/null +++ b/WsTextEdit/WsTextEdit.vcxproj.filters @@ -0,0 +1,37 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} + ts + + + + + Header Files + + + Header Files + + + Source Files + + + + diff --git a/WsTextEdit/wstextedit.cpp b/WsTextEdit/wstextedit.cpp new file mode 100644 index 0000000..9c0847d --- /dev/null +++ b/WsTextEdit/wstextedit.cpp @@ -0,0 +1,5 @@ +#include "wstextedit.h" + +WsTextEdit::WsTextEdit() +{ +} diff --git a/WsTextEdit/wstextedit.h b/WsTextEdit/wstextedit.h new file mode 100644 index 0000000..0dfe704 --- /dev/null +++ b/WsTextEdit/wstextedit.h @@ -0,0 +1,9 @@ +#pragma once + +#include "wstextedit_global.h" + +class WSTEXTEDIT_EXPORT WsTextEdit +{ +public: + WsTextEdit(); +}; diff --git a/WsTextEdit/wstextedit_global.h b/WsTextEdit/wstextedit_global.h new file mode 100644 index 0000000..3bce03a --- /dev/null +++ b/WsTextEdit/wstextedit_global.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +#ifndef BUILD_STATIC +# if defined(WSTEXTEDIT_LIB) +# define WSTEXTEDIT_EXPORT Q_DECL_EXPORT +# else +# define WSTEXTEDIT_EXPORT Q_DECL_IMPORT +# endif +#else +# define WSTEXTEDIT_EXPORT +#endif diff --git a/libWsTextEdit/libWsTextEdit.vcxproj b/libWsTextEdit/libWsTextEdit.vcxproj new file mode 100644 index 0000000..de00282 --- /dev/null +++ b/libWsTextEdit/libWsTextEdit.vcxproj @@ -0,0 +1,102 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {DB6BC034-92EF-457C-B1B9-7997857E782B} + QtVS_v304 + 10.0 + 10.0.22621.0 + $(MSBuildProjectDirectory)\QtMsBuild + + + + DynamicLibrary + v143 + + + DynamicLibrary + v143 + + + + + + + 5.12.11_msvc2017_64 + core + debug + + + 5.12.11_msvc2017_64 + core + release + + + + + + + + + + + + + + + + + + + + + + true + true + ProgramDatabase + Disabled + LIBWSTEXTEDIT_LIB;%(PreprocessorDefinitions) + + + Windows + true + + + + + true + true + None + MaxSpeed + LIBWSTEXTEDIT_LIB;%(PreprocessorDefinitions) + + + Windows + false + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libWsTextEdit/libWsTextEdit.vcxproj.filters b/libWsTextEdit/libWsTextEdit.vcxproj.filters new file mode 100644 index 0000000..cbdfdf1 --- /dev/null +++ b/libWsTextEdit/libWsTextEdit.vcxproj.filters @@ -0,0 +1,52 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C} + ts + + + + + Header Files + + + Header Files + + + Source Files + + + Header Files + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/libWsTextEdit/libwstextedit.cpp b/libWsTextEdit/libwstextedit.cpp new file mode 100644 index 0000000..c2bc254 --- /dev/null +++ b/libWsTextEdit/libwstextedit.cpp @@ -0,0 +1,5 @@ +#include "libwstextedit.h" + +libWsTextEdit::libWsTextEdit() +{ +} diff --git a/libWsTextEdit/libwstextedit.h b/libWsTextEdit/libwstextedit.h new file mode 100644 index 0000000..7adbd57 --- /dev/null +++ b/libWsTextEdit/libwstextedit.h @@ -0,0 +1,9 @@ +#pragma once + +#include "libwstextedit_global.h" + +class LIBWSTEXTEDIT_EXPORT libWsTextEdit +{ +public: + libWsTextEdit(); +}; diff --git a/libWsTextEdit/libwstextedit_global.h b/libWsTextEdit/libwstextedit_global.h new file mode 100644 index 0000000..406df4f --- /dev/null +++ b/libWsTextEdit/libwstextedit_global.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +#ifndef BUILD_STATIC +# if defined(LIBWSTEXTEDIT_LIB) +# define LIBWSTEXTEDIT_EXPORT Q_DECL_EXPORT +# else +# define LIBWSTEXTEDIT_EXPORT Q_DECL_IMPORT +# endif +#else +# define LIBWSTEXTEDIT_EXPORT +#endif diff --git a/libWsTextEdit/textmodels.cpp b/libWsTextEdit/textmodels.cpp new file mode 100644 index 0000000..aa5fc77 --- /dev/null +++ b/libWsTextEdit/textmodels.cpp @@ -0,0 +1,147 @@ +#include "textmodels.h" + +using namespace wstext_model; +using namespace wstext_present; + +void WsDocument::bindFormat(std::shared_ptr f) { this->document_format = f; } + +std::shared_ptr WsDocument::getFormat() const { return this->document_format; } + +uint32_t WsDocument::blockCount() const +{ + return this->block_store.size(); +} + +QList > WsDocument::getBlocks(uint32_t offset, uint32_t count) const +{ + QList> retvs; + + for (auto idx = offset; idx < this->block_store.size(); ++idx) + retvs << this->block_store.at(idx); + + return retvs; +} + +void WsDocument::delBlocks(uint32_t offset, uint32_t count) +{ + for (auto idx = offset; idx < this->block_store.size();) { + this->block_store.removeAt(idx); + } +} + +void WsDocument::addBlocks(const QList> &blks, uint32_t offset) +{ + if (offset < this->block_store.size()) { + for (auto ptr : blks) + this->block_store.insert(offset, ptr); + } + else { + this->block_store.append(blks); + } +} + +QString WsDocument::toPlainText() const +{ + QString text_content; + for (auto idx = 0; idx < blockCount(); ++idx) { + text_content += getBlocks(idx).at(0)->toText(); + } + return text_content; +} + +void WsDocument::setPlainText(const QString &text) +{ + auto sections = text.split("\n"); + QList> blocks; + for (auto &t : sections) { + auto binst = std::make_shared(); + blocks.append(binst); + + // ת»»Îı¾ÎªÄÚ´æÊµÀý + auto codes = CharSetU16::combineToU(t); + auto chars = WsChar::convertFrom(codes); + + // Ìî³ä¶ÎÂäʵÀý + QList buffers; + for (auto &ptr : chars) { + ptr->bindFormat(this->getFormat()->defaultCharFormat()); + ptr->refer(binst); + buffers.append(ptr); + } + binst->addElements(buffers); + } + + addBlocks(blocks); +} + +void WsBlock::addElements(const QList &text, uint32_t offset) { + if (offset < this->element_store.size()) { + for (auto *ptr : text) + this->element_store.insert(offset, ptr); + } + else { + this->element_store.append(text); + } +} + +QList WsBlock::getElements(uint32_t offset, uint32_t count) const +{ + QList retvs; + + for (auto idx = offset; idx < this->element_store.size(); ++idx) + retvs << this->element_store.at(idx); + + return retvs; +} + +void WsBlock::delElements(uint32_t offset, uint32_t count) +{ + for (auto idx = offset; idx < this->element_store.size();) { + delete element_store.at(idx); + this->element_store.removeAt(idx); + } +} + +QString WsBlock::toText() const +{ + QString text_content; + for (auto &it : element_store) + text_content += it->toText(); + return text_content; +} + + +wstext_model::WsChar::WsChar(uint32_t code) { this->code_store = code; } + +uint32_t wstext_model::WsChar::code() const { return code_store; } + +QList> WsChar::convertFrom(const QString &text) +{ + QList> buffers; + + for(auto &code : CharSetU16::combineToU(text)) + buffers << std::make_shared(code); + + return buffers; +} + + + +Element::Element(AssembleType t) : type_store(t) {} + +Element::Element(const Element &other) : Element(other.baseType()) { +} + + +AssembleType Element::baseType() const { return type_store; } + +qulonglong Element::hashCode() const { return (qulonglong)this; } + +std::shared_ptr Element::clone() const { + return std::make_shared(this->type_store); +} + +qulonglong wstext_model::Element::pos() const +{ + return 0; +} diff --git a/libWsTextEdit/textmodels.h b/libWsTextEdit/textmodels.h new file mode 100644 index 0000000..9b01e23 --- /dev/null +++ b/libWsTextEdit/textmodels.h @@ -0,0 +1,103 @@ +#pragma once + +#include "textpresents.h" + +namespace wstext_model { + typedef QList CharStream; + + class CharSetU16 { + public: + static CharStream combineToU(const QString &buffer); + static QString splitToC(const CharStream &buffer); + static bool contains(uint32_t code); + static uint size(); + }; + + /** + * @brief ¾ÛºÏÌåÀàÐÍ + */ + enum class AssembleType { + INLINE_ELEMENT, + FRAGMENT, + DOCUMENT, + }; + + /** + * @brief ÄÚ´æÊµÀý½Ó¿Ú + */ + class Element : public std::enable_shared_from_this { + public: + explicit Element(AssembleType t); + explicit Element(const Element & other); + + AssembleType baseType() const; + qulonglong hashCode() const; + + virtual std::shared_ptr clone() const; + virtual qulonglong pos() const; + + private: + AssembleType type_store; + }; + + class WsChar : public Element { + private: + uint32_t code_store; + + public: + explicit WsChar(uint32_t code); + virtual ~WsChar() = default; + + uint32_t code() const; + + static QList> convertFrom(const QString &text); + }; + + + class WsPart : public Element { + public: + /** + * »ñȡָ¶¨ÔªËصÄËùÓÐȨ. + * + * \param text + * \param offset + */ + std::shared_ptr insertChars(const QList> &text, uint32_t offset = -1); + QList> getChars(uint32_t offset, uint32_t count) const; + std::shared_ptr delChars(uint32_t offset, uint32_t count); + + std::shared_ptr mergeFrom(const QList> &mbrs); + }; + + class LIBWSTEXTEDIT_EXPORT WsBlock { + private: + QList element_store; + + public: + uint32_t blockIndex() const; + void addElements(const QList &text, uint32_t offset = UINT32_MAX); + QList getElements(uint32_t offset, uint32_t count) const; + void delElements(uint32_t offset, uint32_t count); + QString toText() const; + }; + + class LIBWSTEXTEDIT_EXPORT WsDocument : public QObject { + Q_OBJECT + private: + std::shared_ptr document_format; + QList> block_store; + + public: + void bindFormat(std::shared_ptr f); + std::shared_ptr getFormat() const; + + void addBlocks(const QList> &blks, uint32_t offset = UINT32_MAX); + uint32_t blockCount() const; + QList> getBlocks(uint32_t offset, uint32_t count = 1) const; + void delBlocks(uint32_t offset, uint32_t count = 1); + + QString toPlainText() const; + void setPlainText(const QString &text); + + }; +} diff --git a/libWsTextEdit/textpresents.cpp b/libWsTextEdit/textpresents.cpp new file mode 100644 index 0000000..4e6c813 --- /dev/null +++ b/libWsTextEdit/textpresents.cpp @@ -0,0 +1,192 @@ +#include "wspresentmodel.h" +#include + +using namespace std; +using namespace wstext_present; + +CharStream CharSetU16::combineToU(const QString &buffer) { + QList retvs; + + if (buffer.size() == 0) + return retvs; + + tuple combine_current; + auto aval = buffer[0]; + if (buffer.size() < 2) + combine_current = std::make_tuple(aval.unicode(), 1); + + else if (buffer.size() >= 2) { + auto bval = buffer[1]; + if (aval.isHighSurrogate() && bval.isLowSurrogate()) { + uint32_t avalx = aval.unicode(); + combine_current = std::make_tuple((avalx << 16) + bval.unicode(), 2); + } + else { + combine_current = std::make_tuple(aval.unicode(), 1); + } + } + + retvs.append(std::get<0>(combine_current)); + retvs.append(combineToU(buffer.mid(std::get<1>(combine_current)))); + return retvs; +} + +QString CharSetU16::splitToC(const CharStream &buffer) { + if (!buffer.size()) + return ""; + + QString acc_str = ""; + auto head = buffer[0]; + if (head > 0xffffu) { + auto high_v = (head & 0xffff0000u) >> 16; + auto low_v = head & 0xffffu; + + auto hc = QChar((ushort)high_v); + auto lc = QChar((ushort)low_v); + acc_str.append(hc); + acc_str.append(lc); + } + else { + acc_str.append(QChar((ushort)head & 0xffffu)); + } + + acc_str.append(splitToC(buffer.mid(1))); + return acc_str; +} + +bool CharSetU16::contains(uint32_t code) { + if (code <= 0xffffu) + return true; + else { + auto high_v = (code & 0xffff0000u) >> 16; + auto low_v = code & 0xffffu; + + auto hc = QChar((ushort)high_v); + auto lc = QChar((ushort)low_v); + return hc.isHighSurrogate() && lc.isLowSurrogate(); + } +} + +uint CharSetU16::size() { return 1114111u; } + +CharFormat::CharFormat(qulonglong format_id) { + this->unique_id = format_id; +} + +CharFormat::CharFormat(const CharFormat &other) { + this->unique_id = other.unique_id; + + this->point_size = other.point_size; + this->fontfamily_store = other.fontfamily_store; + this->bold_store = other.bold_store; + this->italic_flag = other.italic_flag; + this->kerning_flag = other.kerning_flag; + this->overline_flag = other.overline_flag; + this->underline_flag = other.underline_flag; + this->float_Height = other.float_Height; + this->weight_store = other.weight_store; +} + +qulonglong CharFormat::formatID() const { return unique_id; } + +uint32_t CharFormat::pointSize() const { return point_size; } + +QString CharFormat::fontFamily() const { return fontfamily_store; } + +bool CharFormat::bold() const { return bold_store; } + +bool CharFormat::italic() const { return italic_flag; } + +bool CharFormat::kerning() const { return kerning_flag; } + +bool CharFormat::overline() const { return overline_flag; } + +bool CharFormat::underline() const { return underline_flag; } + +double CharFormat::floatHeight() const { return float_Height; } + +QFont::Weight CharFormat::weight() const { return weight_store; } + +void CharFormat::setPointSize(uint32_t val) { this->point_size = val; } + +void CharFormat::setFontFamily(const QString &name) { this->fontfamily_store = name; } + +void CharFormat::setBold(bool ste) { this->bold_store = ste; } + +void CharFormat::setItalic(bool ste) { this->italic_flag = ste; } + +void CharFormat::setKerning(bool ste) { this->kerning_flag = ste; } + +void CharFormat::setOverline(bool ste) { this->overline_flag = ste; } + +void CharFormat::setUnderline(bool ste) { this->underline_flag = ste; } + +void CharFormat::setFloatHeight(double val) { this->float_Height = val; } + +void CharFormat::setWeight(QFont::Weight val) { this->weight_store = val; } + +bool CharFormat::operator==(const CharFormat &other) { + return this->point_size == other.point_size && + this->fontfamily_store == other.fontfamily_store && + this->bold_store == other.bold_store && + this->italic_flag == other.italic_flag && + this->kerning_flag == other.kerning_flag && + this->overline_flag == other.overline_flag && + this->underline_flag == other.underline_flag && + this->float_Height == other.float_Height && + this->weight_store == other.weight_store; +} + +CharFormat &CharFormat::operator=(const CharFormat &other) { + this->point_size = other.point_size; + this->fontfamily_store = other.fontfamily_store; + this->bold_store = other.bold_store; + this->italic_flag = other.italic_flag; + this->kerning_flag = other.kerning_flag; + this->overline_flag = other.overline_flag; + this->underline_flag = other.underline_flag; + this->float_Height = other.float_Height; + this->weight_store = other.weight_store; + + return *this; +} + + +DocFormat::DocFormat() {} + +DocFormat::DocFormat(const DocFormat &other) { + this->char_format = other.char_format; + this->line_height = other.line_height; + this->indent_char_count = other.indent_char_count; + this->margins_store = other.margins_store; + this->visible_of_additional = other.visible_of_additional; +} + +double DocFormat::lineHeight() const { return line_height; } + +QMargins DocFormat::margins() const { return margins_store; } + +double DocFormat::indentChars() const { return indent_char_count; } + +bool DocFormat::additionalVisible() const { return visible_of_additional; } + +std::shared_ptr DocFormat::defaultCharFormat() const { return this->char_format; } + +void DocFormat::setLineHeight(double val) { this->line_height = val; } + +void DocFormat::setMargins(const QMargins &val) { this->margins_store = val; } + +void DocFormat::setIndentChars(double n) { this->indent_char_count = n; } + +void DocFormat::setAdditionalVisible(bool ste) { this->visible_of_additional = ste; } + +void DocFormat::setDefaultCharFormat(std::shared_ptr format) { this->char_format = format; } + +DocFormat &DocFormat::operator=(const DocFormat &other) { + this->char_format = other.char_format; + this->line_height = other.line_height; + this->indent_char_count = other.indent_char_count; + this->margins_store = other.margins_store; + this->visible_of_additional = other.visible_of_additional; + return *this; +} \ No newline at end of file diff --git a/libWsTextEdit/textpresents.h b/libWsTextEdit/textpresents.h new file mode 100644 index 0000000..a562788 --- /dev/null +++ b/libWsTextEdit/textpresents.h @@ -0,0 +1,81 @@ +#pragma once +#include "libwstextedit_global.h" + +#include +#include + +namespace wstext_present { + /** + * ×Ö·û¸ñʽ¶¨Òå. + */ + class LIBWSTEXTEDIT_EXPORT CharFormat { + private: + qulonglong unique_id; + + uint32_t point_size; + QString fontfamily_store; + bool bold_store; + bool italic_flag; + bool kerning_flag; + bool overline_flag; + bool underline_flag; + double float_Height; + QFont::Weight weight_store; + + public: + CharFormat(qulonglong format_id); + CharFormat(const CharFormat& other); + + qulonglong formatID() const; + + uint32_t pointSize() const; + QString fontFamily() const; + bool bold() const; + bool italic() const; + bool kerning() const; + bool overline() const; + bool underline() const; + double floatHeight() const; + QFont::Weight weight() const; + + void setPointSize(uint32_t val); + void setFontFamily(const QString &name); + void setBold(bool ste); + void setItalic(bool ste); + void setKerning(bool ste); + void setOverline(bool ste); + void setUnderline(bool ste); + void setFloatHeight(double val); + void setWeight(QFont::Weight val); + + bool operator==(const CharFormat &other); + CharFormat &operator=(const CharFormat &other); + }; + + class LIBWSTEXTEDIT_EXPORT DocFormat { + private: + std::shared_ptr char_format; + double line_height = 20; + double indent_char_count = 2; + QMargins margins_store = QMargins(5, 5, 5, 5); + bool visible_of_additional = false; + + public: + DocFormat(); + DocFormat(const DocFormat &other); + + double lineHeight() const; + QMargins margins() const; + double indentChars() const; + bool additionalVisible() const; + std::shared_ptr defaultCharFormat() const; + + void setLineHeight(double val); + void setMargins(const QMargins &val); + void setIndentChars(double n); + void setAdditionalVisible(bool ste); + void setDefaultCharFormat(std::shared_ptr format); + + DocFormat& operator=(const DocFormat &other); + }; +}