From 6100d5660375fe4a8ab5e6ed708c97cc91f0db3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Mon, 22 May 2017 21:51:29 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=87=86=E5=A4=87=E8=AF=BB=E5=8F=96=20OFD?= =?UTF-8?q?=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/OFD_DocConvertor.cpp | 6 ++ ofdEditor/model/Convert/OFD_DocConvertor.h | 15 +++++ ofdEditor/model/Tool/UnitTool.h | 3 +- ofdEditor/model/Widget/FontSettingDialog.cpp | 14 ++++ ofdEditor/model/Widget/FontSettingDialog.h | 22 +++++++ ofdEditor/model/Widget/FontSettingDialog.ui | 67 ++++++++++++++++++++ ofdEditor/model/model.pro | 11 +++- ofdEditor/ofd/Loaders/ZipTool.cpp | 24 +++++++ ofdEditor/ofd/Loaders/ZipTool.h | 7 +- ofdEditor/ofd/ofd.pro | 30 ++++----- ofdEditor/ofd/ofd_parser.cpp | 4 +- ofdEditor/ofd/ofd_parser.h | 3 +- ofdEditor/ofd/ofd_writer.h | 3 +- ofdEditor/start/ui/PassageMainWindow.cpp | 45 +++++++++++++ ofdEditor/start/ui/PassageMainWindow.h | 2 + 15 files changed, 232 insertions(+), 24 deletions(-) create mode 100644 ofdEditor/model/Convert/OFD_DocConvertor.cpp create mode 100644 ofdEditor/model/Convert/OFD_DocConvertor.h create mode 100644 ofdEditor/model/Widget/FontSettingDialog.cpp create mode 100644 ofdEditor/model/Widget/FontSettingDialog.h create mode 100644 ofdEditor/model/Widget/FontSettingDialog.ui diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.cpp b/ofdEditor/model/Convert/OFD_DocConvertor.cpp new file mode 100644 index 0000000..7906961 --- /dev/null +++ b/ofdEditor/model/Convert/OFD_DocConvertor.cpp @@ -0,0 +1,6 @@ +#include "OFD_DocConvertor.h" + +OFD_DocConvertor::OFD_DocConvertor() +{ + +} diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.h b/ofdEditor/model/Convert/OFD_DocConvertor.h new file mode 100644 index 0000000..0cc1189 --- /dev/null +++ b/ofdEditor/model/Convert/OFD_DocConvertor.h @@ -0,0 +1,15 @@ +#ifndef OFD_DOCCONVERTOR_H +#define OFD_DOCCONVERTOR_H + +#include "model_global.h" +#include + +class MODELSHARED_EXPORT OFD_DocConvertor + :public QObject +{ + Q_OBJECT +public: + OFD_DocConvertor(); +}; + +#endif // OFD_DOCCONVERTOR_H diff --git a/ofdEditor/model/Tool/UnitTool.h b/ofdEditor/model/Tool/UnitTool.h index 1418e78..6dce92e 100644 --- a/ofdEditor/model/Tool/UnitTool.h +++ b/ofdEditor/model/Tool/UnitTool.h @@ -18,7 +18,8 @@ public: static int mmToPixel(double mm); // 将毫米单位和像素单位进行换算 static double pixelToMM(double pixel); // 将像素单位转换为毫米单位 - static QRectF getBox(QPointF& point1, QPointF& point2); // 获得两个点组成的方形 + static QRectF getBox(QPointF& point1, + QPointF& point2); // 获得两个点组成的方形 }; #endif // UNITTOOL_H diff --git a/ofdEditor/model/Widget/FontSettingDialog.cpp b/ofdEditor/model/Widget/FontSettingDialog.cpp new file mode 100644 index 0000000..fe21d07 --- /dev/null +++ b/ofdEditor/model/Widget/FontSettingDialog.cpp @@ -0,0 +1,14 @@ +#include "FontSettingDialog.h" +#include "ui_FontSettingDialog.h" + +FontSettingDialog::FontSettingDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::FontSettingDialog) +{ + ui->setupUi(this); +} + +FontSettingDialog::~FontSettingDialog() +{ + delete ui; +} diff --git a/ofdEditor/model/Widget/FontSettingDialog.h b/ofdEditor/model/Widget/FontSettingDialog.h new file mode 100644 index 0000000..c7ec093 --- /dev/null +++ b/ofdEditor/model/Widget/FontSettingDialog.h @@ -0,0 +1,22 @@ +#ifndef FONTSETTINGDIALOG_H +#define FONTSETTINGDIALOG_H + +#include + +namespace Ui { +class FontSettingDialog; +} + +class FontSettingDialog : public QDialog +{ + Q_OBJECT + +public: + explicit FontSettingDialog(QWidget *parent = 0); + ~FontSettingDialog(); + +private: + Ui::FontSettingDialog *ui; +}; + +#endif // FONTSETTINGDIALOG_H diff --git a/ofdEditor/model/Widget/FontSettingDialog.ui b/ofdEditor/model/Widget/FontSettingDialog.ui new file mode 100644 index 0000000..d23eb4c --- /dev/null +++ b/ofdEditor/model/Widget/FontSettingDialog.ui @@ -0,0 +1,67 @@ + + FontSettingDialog + + + + 0 + 0 + 480 + 640 + + + + Dialog + + + + + 10 + 600 + 461 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + buttonBox + accepted() + FontSettingDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + FontSettingDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/ofdEditor/model/model.pro b/ofdEditor/model/model.pro index 344d3d5..de9256b 100644 --- a/ofdEditor/model/model.pro +++ b/ofdEditor/model/model.pro @@ -45,7 +45,9 @@ SOURCES += model.cpp \ Tool/UnitTool.cpp \ Doc/DocPageScene.cpp \ Widget/ParagraphFormatWidget.cpp \ - Widget/ParagraphFormatDialog.cpp + Widget/ParagraphFormatDialog.cpp \ + Widget/FontSettingDialog.cpp \ + Convert/OFD_DocConvertor.cpp HEADERS += model.h\ model_global.h \ @@ -70,7 +72,9 @@ HEADERS += model.h\ Tool/UnitTool.h \ Doc/DocPageScene.h \ Widget/ParagraphFormatWidget.h \ - Widget/ParagraphFormatDialog.h + Widget/ParagraphFormatDialog.h \ + Widget/FontSettingDialog.h \ + Convert/OFD_DocConvertor.h DESTDIR = ../bin # 生成文件在这 MOC_DIR = ./moc # Q_OBJECT 类转换后的文件 @@ -97,4 +101,5 @@ win32{ FORMS += \ Widget/ParagraphFormatWidget.ui \ - Widget/ParagraphFormatDialog.ui + Widget/ParagraphFormatDialog.ui \ + Widget/FontSettingDialog.ui diff --git a/ofdEditor/ofd/Loaders/ZipTool.cpp b/ofdEditor/ofd/Loaders/ZipTool.cpp index a27f162..d910294 100644 --- a/ofdEditor/ofd/Loaders/ZipTool.cpp +++ b/ofdEditor/ofd/Loaders/ZipTool.cpp @@ -1,6 +1,8 @@ #include "ZipTool.h" #include +#include #include +#include #include "JlCompress.h" // 压缩文件库 @@ -139,6 +141,28 @@ void ZipTool::deleteFolder(const QString &folderFullPath) * 而不删除folderFullPath本身,则删掉本行即可 */ } +/** + * @Author Chaoqun + * @brief 将文件名按照一定规则转换成文件夹名 + * @param const QString &filePath + * @return QString + * @date 2017/05/22 + */ +QString ZipTool::FilePathToFloderPath(const QString &filePath) +{ + + QString fileName = filePath.section('/',-1); // 依据分隔符获得文件名 + fileName = fileName.replace(QString("."),QString("_")); // 将 . 替换成 _ +// qDebug() << fileName; + QDir temp = QDir::temp(); + temp.mkdir(fileName ); // 创建临时文件夹 + temp.cd(fileName ); // 进入临时文件夹 +// qDebug() << temp.cd("%"+fileName +"%"); +// qDebug() << temp.path(); // 测试临时目录 + return temp.path(); + +} + ZipTool::ZipTool() { diff --git a/ofdEditor/ofd/Loaders/ZipTool.h b/ofdEditor/ofd/Loaders/ZipTool.h index 6b578c0..8f16206 100644 --- a/ofdEditor/ofd/Loaders/ZipTool.h +++ b/ofdEditor/ofd/Loaders/ZipTool.h @@ -16,6 +16,7 @@ class OFDSHARED_EXPORT ZipTool { public: + ZipTool(); static QStringList getFileList(QString fileCompressed); // 获取压缩文件中的所有文件名 @@ -25,8 +26,10 @@ public: QString dir,bool deleteDir = false); // 压缩目录 static void deleteFolder(const QString& folderFullPath); -private: - ZipTool(); // 不允许实例化 + + QString FilePathToFloderPath(const QString& filePath); + + }; diff --git a/ofdEditor/ofd/ofd.pro b/ofdEditor/ofd/ofd.pro index 98c5b4d..5816cb2 100644 --- a/ofdEditor/ofd/ofd.pro +++ b/ofdEditor/ofd/ofd.pro @@ -43,32 +43,32 @@ HEADERS +=\ DataTypes/Color/CT_ColorSpace.h \ # DataTypes/Color/CT_Pattern.h \ # DataTypes/Color/CT_RadialShd.h \ - DataTypes/document/CT_CommonData.h \ - DataTypes/document/CT_DocInfo.h \ - DataTypes/document/CT_OutlineElem.h \ - DataTypes/document/CT_Outlines.h \ - DataTypes/document/DocBody.h \ - DataTypes/document/Document.h \ - DataTypes/document/OFD.h \ + DataTypes/document/ct_commondata.h \ + DataTypes/document/ct_docinfo.h \ + DataTypes/document/ct_outlineelem.h \ + DataTypes/document/ct_outlines.h \ + DataTypes/document/docbody.h \ + DataTypes/document/document.h \ + DataTypes/document/ofd.h \ # DataTypes/image/CT_Clip.h \ DataTypes/image/CT_DrawParam.h \ DataTypes/image/CT_GraphicUnit.h \ DataTypes/image/CT_Image.h \ DataTypes/image/CT_Path.h \ - DataTypes/page/CT_Layer.h \ + DataTypes/page/ct_layer.h \ DataTypes/page/CT_PageArea.h \ - DataTypes/page/CT_PageBlock.h \ - DataTypes/page/CT_Pages.h \ - DataTypes/page/Page.h \ + DataTypes/page/ct_pageblock.h \ + DataTypes/page/ct_pages.h \ + DataTypes/page/page.h \ ofd_parser.h \ DataTypes/document/res.h\ # DataTypes/text/CT_CGTransform.h \ - DataTypes/text/CT_Font.h \ - DataTypes/text/CT_Text.h \ - DataTypes/text/TextCode.h \ + DataTypes/text/ct_font.h \ + DataTypes/text/ct_text.h \ + DataTypes/text/textcode.h \ ofd_global.h \ ofd_writer.h \ - DataTypes/document/CustomTags.h \ + DataTypes/document/customtags.h \ Loaders/ZipTool.h diff --git a/ofdEditor/ofd/ofd_parser.cpp b/ofdEditor/ofd/ofd_parser.cpp index 6972aab..e998474 100644 --- a/ofdEditor/ofd/ofd_parser.cpp +++ b/ofdEditor/ofd/ofd_parser.cpp @@ -1,7 +1,9 @@ #include "ofd_parser.h" #include -OFDParser::OFDParser(QString _path) : current_path("OFD", _path) { +OFDParser::OFDParser(QString _path) : + current_path("OFD", _path) +{ document = new QDomDocument(); data = readOFD(); } diff --git a/ofdEditor/ofd/ofd_parser.h b/ofdEditor/ofd/ofd_parser.h index be54483..80f1f7d 100644 --- a/ofdEditor/ofd/ofd_parser.h +++ b/ofdEditor/ofd/ofd_parser.h @@ -10,10 +10,11 @@ #include "DataTypes/page/Page.h" #include "DataTypes/basic_datatype.h" #include "DataTypes/Color/CT_Color.h" +#include "ofd_global.h" class OFD; -class OFDParser { //解析OFD.xml +class OFDSHARED_EXPORT OFDParser { //解析OFD.xml OFD * data; //保存了解析出来的数据信息 ST_Loc current_path; //当前文档的路径 QDomDocument *document; //保存了ofd文档信息的树形结构 diff --git a/ofdEditor/ofd/ofd_writer.h b/ofdEditor/ofd/ofd_writer.h index cb2fa46..4fda0a2 100644 --- a/ofdEditor/ofd/ofd_writer.h +++ b/ofdEditor/ofd/ofd_writer.h @@ -11,8 +11,9 @@ #include "DataTypes/page/Page.h" #include "DataTypes/basic_datatype.h" #include "DataTypes/Color/CT_Color.h" +#include "ofd_global.h" -class OFDWriter +class OFDSHARED_EXPORT OFDWriter { private: OFD * data; //OFD文档的数据 diff --git a/ofdEditor/start/ui/PassageMainWindow.cpp b/ofdEditor/start/ui/PassageMainWindow.cpp index f7ac045..0d17a94 100644 --- a/ofdEditor/start/ui/PassageMainWindow.cpp +++ b/ofdEditor/start/ui/PassageMainWindow.cpp @@ -19,6 +19,9 @@ #include "Doc/DocPassage.h" #include "ActionConnector/ActionConnector.h" +#include "Loaders/ZipTool.h" // 压缩文件工具 +#include "ofd_parser.h" +#include "DataTypes/document/ofd.h" PassageMainWindow::PassageMainWindow(QWidget *parent) :QMainWindow(parent) @@ -244,6 +247,9 @@ void PassageMainWindow::connectAction() connect(this->newFileAction, &QAction::triggered, this,&PassageMainWindow::createMdiChild); // 新建窗口 + connect(this->openFileAtcion, &QAction::triggered, + this, &PassageMainWindow::openFile); //打开文件 + connect(this->insertNewPageAction, &QAction::triggered, this->connector, &ActionConnector::addNewPage); // 在文章尾部加入新的一页 @@ -272,6 +278,45 @@ void PassageMainWindow::disconnectAction() } +/** + * @Author Chaoqun + * @brief 打开 *.ofd 文件 + * @param void + * @return void + * @date 2017/05/22 + */ +void PassageMainWindow::openFile() +{ + QFileDialog * fileDialog = new QFileDialog(this); // 新建一个QFileDialog +// fileDialog->setWindowIcon(QIcon(":/icon/source/open.png")); // 设置打开文件图标 + fileDialog->setAcceptMode(QFileDialog::AcceptOpen); // 设置对话框为打开文件类型 + fileDialog->setFileMode(QFileDialog::ExistingFile); // 设置文件对话框能够存在的文件 + fileDialog->setViewMode(QFileDialog::Detail); // 文件以细节形式显示出来 + fileDialog->setNameFilter(tr("JSON files(*.ofd)")); // 设置文件过滤器 + fileDialog->setWindowTitle(tr("Choose an ofd document file!")); + + if(fileDialog->exec() == QDialog::Accepted) + { + QString path = fileDialog->selectedFiles()[0]; // 用户选择文件名 + qDebug() << path; + + ZipTool zipTool; + QString tempPath = zipTool.FilePathToFloderPath(path); + qDebug() << "Temp path is :" << tempPath; + + ZipTool::extractDir(path,tempPath); // 解压到临时文件夹 + + // 解读文件 +// OFDParser ofdParser("C:\\Users\\User\\AppData\\Local\\Temp\\%表格.ofd%\\OFD.xml"); + OFDParser ofdParser(tempPath + "/OFD.xml"); // 新建临时路径 + OFD* data = ofdParser.getData(); // 读取出OFD文件 + + + + + } +} + /** * @Author Chaoqun * @brief 获取激活的窗口 diff --git a/ofdEditor/start/ui/PassageMainWindow.h b/ofdEditor/start/ui/PassageMainWindow.h index 5de476d..a2d922b 100644 --- a/ofdEditor/start/ui/PassageMainWindow.h +++ b/ofdEditor/start/ui/PassageMainWindow.h @@ -80,6 +80,8 @@ private: void connectAction(); // 链接QAction的相应事件 void disconnectAction(); // 断开事件响应 + void openFile(); // 打开新文件 + -- Gitee From d77a44b8a029a6a2b52246c98d976ce7ecb936b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Tue, 23 May 2017 11:12:19 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=B0=86=E6=96=87=E6=9C=AC=E6=A1=86?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA=E8=83=8C=E6=99=AF=E9=80=8F=E6=98=8E?= =?UTF-8?q?=EF=BC=8C=E4=B9=8B=E5=90=8E=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=9D=A5=E5=86=B3=E5=AE=9A=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=A1=86=E6=98=AF=E5=90=A6=E6=98=BE=E7=A4=BA=E8=BE=B9=E6=A1=86?= =?UTF-8?q?=E3=80=82=20=E6=AD=A3=E5=9C=A8=E8=BF=9B=E8=A1=8C=E7=9A=84?= =?UTF-8?q?=E6=98=AFOFD->Doc=E7=9A=84=E7=B1=BB=E5=9E=8B=E8=BD=AC=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E4=B8=80=E4=BA=9BCT=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E7=A7=81=E6=9C=89=E5=8F=98=E9=87=8F=E7=AE=80=E5=8D=95?= =?UTF-8?q?=E7=B2=97=E6=9A=B4=E7=9A=84=E8=BD=AC=E6=8D=A2=E4=B8=BA=E5=85=AC?= =?UTF-8?q?=E6=9C=89=E5=8F=98=E9=87=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/OFD_DocConvertor.cpp | 35 ++++ ofdEditor/model/Convert/OFD_DocConvertor.h | 18 ++ ofdEditor/model/Doc/DocBlock.cpp | 2 + ofdEditor/model/Doc/DocPassage.cpp | 28 +++- ofdEditor/model/Doc/DocPassage.h | 12 +- ofdEditor/model/Doc/DocTextBlock.cpp | 10 ++ ofdEditor/ofd/DataTypes/document/CT_DocInfo.h | 21 +++ ofdEditor/ofd/DataTypes/document/DocBody.h | 1 + ofdEditor/ofd/DataTypes/document/Document.h | 1 + ofdEditor/ofd/DataTypes/document/OFD.h | 5 +- ofdEditor/ofd/DataTypes/document/ct_docinfo.h | 21 +++ ofdEditor/ofd/DataTypes/document/docbody.h | 1 + ofdEditor/ofd/DataTypes/document/document.h | 1 + ofdEditor/ofd/DataTypes/document/ofd.h | 5 +- ofdEditor/ofd/ofd_parser.cpp | 154 +++++++++++------- ofdEditor/start/ui/PassageMainWindow.cpp | 1 + 16 files changed, 257 insertions(+), 59 deletions(-) diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.cpp b/ofdEditor/model/Convert/OFD_DocConvertor.cpp index 7906961..5efa1fc 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.cpp +++ b/ofdEditor/model/Convert/OFD_DocConvertor.cpp @@ -1,6 +1,41 @@ #include "OFD_DocConvertor.h" +#include "Doc/DocPassage.h" +#include "DataTypes/document/ofd.h" +#include "DataTypes/document/document.h" +#include "DataTypes/page/ct_pages.h" +#include "DataTypes/page/page.h" + + OFD_DocConvertor::OFD_DocConvertor() { } + +/** + * @Author Chaoqun + * @brief 将ofd格式转换成doc格式 + * @param OFD * ofd + * @return DocPassage * + * @date 2017/05/23 + */ +DocPassage *OFD_DocConvertor::ofd_to_doc(OFD *ofd) +{ + DocPassage * passage = new DocPassage(); + + // version + passage->setVersion(ofd->version); + passage->setDocType(ofd->doc_type); + passage->setDocInfo((*(ofd->docbodys))[0]->doc_info); + + CT_Pages pages = (*(ofd->docs))[0]->pages; // 获得页数 + + + + return NULL; +} + +DocPage *OFD_DocConvertor::buildDocPage(Page *ct_page) +{ + return NULL; +} diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.h b/ofdEditor/model/Convert/OFD_DocConvertor.h index 0cc1189..0eb424b 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.h +++ b/ofdEditor/model/Convert/OFD_DocConvertor.h @@ -4,12 +4,30 @@ #include "model_global.h" #include +class DocPassage; +class OFD; +class Document; +class DocPage; +class Page; + + +/** + * @Author Chaoqun + * @brief 将OFD格式转换为Doc类型 + * @date 2017/05/23 + */ class MODELSHARED_EXPORT OFD_DocConvertor :public QObject { Q_OBJECT public: OFD_DocConvertor(); + + DocPassage * ofd_to_doc(OFD * ofd); // 生成文档 + +private: + DocPage * buildDocPage(Page * ct_page); // 生成页 + }; #endif // OFD_DOCCONVERTOR_H diff --git a/ofdEditor/model/Doc/DocBlock.cpp b/ofdEditor/model/Doc/DocBlock.cpp index be407d9..8de6f3b 100644 --- a/ofdEditor/model/Doc/DocBlock.cpp +++ b/ofdEditor/model/Doc/DocBlock.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include DocBlock::DocBlock(QGraphicsItem *parent , Qt::WindowFlags wFlags) :QGraphicsProxyWidget(parent,wFlags) diff --git a/ofdEditor/model/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index c3a3d60..645c7b6 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -21,7 +21,7 @@ DocPassage::DocPassage(QWidget *parent) :docType("OFD"),version("1.0"),QScrollArea(parent) { this->scaleFactor = 1.0; // 缩放100% - //this->docInfo = new CT_DocInfo(); + this->docInfo = new CT_DocInfo(); // 文档元信息 // this->commonData = new CT_CommonData(); this->init(); // 初始化界面 @@ -138,6 +138,32 @@ void DocPassage::appendNewPage(DocPage *page) this->addPage(page); // 此处调用addPage } +/** + * @Author Chaoqun + * @brief 设置文档原信息 + * @param CT_DocInfo &docInfo + * @return void + * @date 2017/05/23 + */ +void DocPassage::setDocInfo(CT_DocInfo &docInfo) +{ + this->docInfo->copy(docInfo); +} + +/** + * @Author Chaoqun + * @brief 获得文档原信息 + * @param void + * @return CT_DocInfo + * @date 2017/05/23 + */ +CT_DocInfo DocPassage::getDocInfo() +{ + CT_DocInfo docInfo; + docInfo.copy( *this->docInfo); + return docInfo; +} + /** * @Author Chaoqun * @brief 设置重置响应事件,窗口大小发生调整,将会调用这个函数u diff --git a/ofdEditor/model/Doc/DocPassage.h b/ofdEditor/model/Doc/DocPassage.h index 6f6d3cc..ea0d448 100644 --- a/ofdEditor/model/Doc/DocPassage.h +++ b/ofdEditor/model/Doc/DocPassage.h @@ -35,6 +35,16 @@ public: void addPassage(QVector& passage); // 添加很多界面 void appendNewPage(DocPage *page = NULL); // 如果为空,则代表假如空白页 + void setDocInfo( CT_DocInfo & docInfo ); + CT_DocInfo getDocInfo(); + + void setVersion(QString version){this->version = version;} + QString getVersion( ){return this->version;} + + void setDocType(QString docType){this->docType = docType;} + QString getDocType( ){return this->docType;} + + protected: void resizeEvent(QResizeEvent* event); @@ -45,7 +55,7 @@ private: // 数据区 QString version; // OFD 版本默认 1.0 QString docType; // 类型默认是 OFD -// CT_DocInfo* docInfo; // 文档元数据结构 ofd/CT_DocInfo + CT_DocInfo* docInfo; // 文档元数据结构 ofd/CT_DocInfo //CT_CommonData* commonData; // 文档公用文档数据 QVector pages; // 既作为数据,也作为渲染 diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index 8d78f97..72779bb 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -254,6 +254,16 @@ void DocTextBlock::init() this->currentTextCharFormat = new QTextCharFormat(); // 初始化 + // 关闭滑动条 + this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + // 设置为背景透明 + this->viewport()->setAttribute(Qt::WA_TranslucentBackground, true); + // 无边框 +// this->setFrameStyle(QFrame::NoFrame); + + // 连接当前charFormat改变函数 connect(this, &DocTextBlock::currentCharFormatChanged, diff --git a/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h b/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h index 1391308..c76bf61 100644 --- a/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h +++ b/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h @@ -5,6 +5,8 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_DocInfo { //文档员数据信息 + +public: QString doc_id; //由32位字符组成的文件标识 QString creation_date; //创建日期 QString mod_date; //修改日期 @@ -18,6 +20,8 @@ class OFDSHARED_EXPORT CT_DocInfo { //文档员数据信息 ST_Loc cover; //文档的封面,此路径指向一个图片文件 //ST_Array keywords; //关键词集合 QVector *custom_datas; //每个CustomData元素为2元QStringList,其中[0]为"Name"属性,[1]为值 + +public: CT_DocInfo() { custom_datas = new QVector(); } @@ -76,6 +80,23 @@ public: QVector * getCustomDatas() { return custom_datas; } + + void copy(const CT_DocInfo & docInfo) + { + this->abstract = docInfo.abstract; + this->author = docInfo.author; + this->cover = docInfo.cover; + this->creation_date = docInfo.creation_date; + this->creator = docInfo.creator; + this->creator_version = docInfo.creator_version; + this->custom_datas = docInfo.custom_datas; + this->doc_id = docInfo.doc_id; + this->doc_usage = docInfo.doc_usage; + this->mod_date = docInfo.mod_date; + this->subject = docInfo.subject; + this->title = docInfo.title; + } + }; #endif // CT_DOCINFO_H diff --git a/ofdEditor/ofd/DataTypes/document/DocBody.h b/ofdEditor/ofd/DataTypes/document/DocBody.h index 78a1a7d..8e8ac70 100644 --- a/ofdEditor/ofd/DataTypes/document/DocBody.h +++ b/ofdEditor/ofd/DataTypes/document/DocBody.h @@ -6,6 +6,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT DocBody { //文档对象入口,在一个文件中可以有多个文档 +public: CT_DocInfo *doc_info; //文档元数据信息描述 ST_Loc doc_root; //指向文档根节点 ST_Loc signatures; //数字签名 to be implemented diff --git a/ofdEditor/ofd/DataTypes/document/Document.h b/ofdEditor/ofd/DataTypes/document/Document.h index e7b89d3..5283c26 100644 --- a/ofdEditor/ofd/DataTypes/document/Document.h +++ b/ofdEditor/ofd/DataTypes/document/Document.h @@ -9,6 +9,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT Document { +public: CT_CommonData * common_data; //文档公共数据,定义了默认页面单位、页面区域定义、公共资源等数据 CT_Outlines * outlines; //大纲树 ST_Loc custom_tags; //指向自定义标引文件 diff --git a/ofdEditor/ofd/DataTypes/document/OFD.h b/ofdEditor/ofd/DataTypes/document/OFD.h index 2c098ab..d462df9 100644 --- a/ofdEditor/ofd/DataTypes/document/OFD.h +++ b/ofdEditor/ofd/DataTypes/document/OFD.h @@ -7,7 +7,9 @@ #include "Document.h" -class OFDSHARED_EXPORT OFD { //主入口文件的根元素 +class OFDSHARED_EXPORT OFD +{ //主入口文件的根元素 +public: //成员 ST_Loc root_path; //ofd.xml的绝对路径,应由应用程序提供 QString version; //版本号 @@ -22,6 +24,7 @@ class OFDSHARED_EXPORT OFD { //主入口文件的根元素 docbodys = new QVector(); docs = new QVector(); } + public: friend class OFDParser; //外部查询数据的接口 diff --git a/ofdEditor/ofd/DataTypes/document/ct_docinfo.h b/ofdEditor/ofd/DataTypes/document/ct_docinfo.h index 1391308..c76bf61 100644 --- a/ofdEditor/ofd/DataTypes/document/ct_docinfo.h +++ b/ofdEditor/ofd/DataTypes/document/ct_docinfo.h @@ -5,6 +5,8 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_DocInfo { //文档员数据信息 + +public: QString doc_id; //由32位字符组成的文件标识 QString creation_date; //创建日期 QString mod_date; //修改日期 @@ -18,6 +20,8 @@ class OFDSHARED_EXPORT CT_DocInfo { //文档员数据信息 ST_Loc cover; //文档的封面,此路径指向一个图片文件 //ST_Array keywords; //关键词集合 QVector *custom_datas; //每个CustomData元素为2元QStringList,其中[0]为"Name"属性,[1]为值 + +public: CT_DocInfo() { custom_datas = new QVector(); } @@ -76,6 +80,23 @@ public: QVector * getCustomDatas() { return custom_datas; } + + void copy(const CT_DocInfo & docInfo) + { + this->abstract = docInfo.abstract; + this->author = docInfo.author; + this->cover = docInfo.cover; + this->creation_date = docInfo.creation_date; + this->creator = docInfo.creator; + this->creator_version = docInfo.creator_version; + this->custom_datas = docInfo.custom_datas; + this->doc_id = docInfo.doc_id; + this->doc_usage = docInfo.doc_usage; + this->mod_date = docInfo.mod_date; + this->subject = docInfo.subject; + this->title = docInfo.title; + } + }; #endif // CT_DOCINFO_H diff --git a/ofdEditor/ofd/DataTypes/document/docbody.h b/ofdEditor/ofd/DataTypes/document/docbody.h index 78a1a7d..8e8ac70 100644 --- a/ofdEditor/ofd/DataTypes/document/docbody.h +++ b/ofdEditor/ofd/DataTypes/document/docbody.h @@ -6,6 +6,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT DocBody { //文档对象入口,在一个文件中可以有多个文档 +public: CT_DocInfo *doc_info; //文档元数据信息描述 ST_Loc doc_root; //指向文档根节点 ST_Loc signatures; //数字签名 to be implemented diff --git a/ofdEditor/ofd/DataTypes/document/document.h b/ofdEditor/ofd/DataTypes/document/document.h index e7b89d3..5283c26 100644 --- a/ofdEditor/ofd/DataTypes/document/document.h +++ b/ofdEditor/ofd/DataTypes/document/document.h @@ -9,6 +9,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT Document { +public: CT_CommonData * common_data; //文档公共数据,定义了默认页面单位、页面区域定义、公共资源等数据 CT_Outlines * outlines; //大纲树 ST_Loc custom_tags; //指向自定义标引文件 diff --git a/ofdEditor/ofd/DataTypes/document/ofd.h b/ofdEditor/ofd/DataTypes/document/ofd.h index 2c098ab..d462df9 100644 --- a/ofdEditor/ofd/DataTypes/document/ofd.h +++ b/ofdEditor/ofd/DataTypes/document/ofd.h @@ -7,7 +7,9 @@ #include "Document.h" -class OFDSHARED_EXPORT OFD { //主入口文件的根元素 +class OFDSHARED_EXPORT OFD +{ //主入口文件的根元素 +public: //成员 ST_Loc root_path; //ofd.xml的绝对路径,应由应用程序提供 QString version; //版本号 @@ -22,6 +24,7 @@ class OFDSHARED_EXPORT OFD { //主入口文件的根元素 docbodys = new QVector(); docs = new QVector(); } + public: friend class OFDParser; //外部查询数据的接口 diff --git a/ofdEditor/ofd/ofd_parser.cpp b/ofdEditor/ofd/ofd_parser.cpp index e998474..d7d1535 100644 --- a/ofdEditor/ofd/ofd_parser.cpp +++ b/ofdEditor/ofd/ofd_parser.cpp @@ -4,8 +4,11 @@ OFDParser::OFDParser(QString _path) : current_path("OFD", _path) { + this->error_msg = "Analysis dom file failed"; + document = new QDomDocument(); data = readOFD(); + qDebug()<<"OFD file read finished"; } void OFDParser::openFile() { @@ -15,12 +18,20 @@ void OFDParser::openFile() { qDebug() << "xml文件打开出现错误。 " << endl; abort(); } + + qDebug() <<"xml File Open Successfully:" + <setContent(&ofd_file, //解析OFD文档并将树状内容存在document文件中 false, &error_msg, &error_line, &error_column)) { ofd_file.close(); + + qDebug() <<"xml File analysis Successfully:" + <firstChildElement("ofd:OFD"); OFD *ofd_data = nullptr; if (!new_ofd.isNull()) { @@ -110,7 +121,7 @@ OFD * OFDParser::readOFD() { Document * OFDParser::readDocument(){ openFile(); -// qDebug() << "Entering readDocument module..." << endl; + qDebug() << "Entering readDocument module..." << endl; QDomElement new_document = document->firstChildElement("ofd:Document"); Document *document_data; if (!new_document.isNull()) { @@ -219,20 +230,25 @@ Document * OFDParser::readDocument(){ } void OFDParser::readPage(Page * page_data) { + + qDebug() << "Entering readPage module..." << endl; openFile(); -// qDebug() << "Entering readPage module..." << endl; + QDomElement new_page = document->firstChildElement("ofd:Page"); - if (!new_page.isNull()) { + if (!new_page.isNull()) + { QDomElement t; - if (!(t = new_page.firstChildElement("ofd:Area")).isNull()) { -// qDebug() << "Start to read PageArea..." << endl; + if (!(t = new_page.firstChildElement("ofd:Area")).isNull()) + { + qDebug() << "Start to read PageArea..." << endl; CT_PageArea * area_data = new CT_PageArea(); readPageArea(area_data, t); page_data->area = area_data; } t = new_page.firstChildElement("ofd:PageRes"); - while (!t.isNull()) { + while (!t.isNull()) + { ST_Loc p("PageRes", t.text(), current_path); Res * new_res = new Res(); current_path = p; @@ -241,8 +257,9 @@ void OFDParser::readPage(Page * page_data) { t = t.nextSiblingElement("ofd:PageRes"); } - if (!(t = new_page.firstChildElement("ofd:Content")).isNull()) { -// qDebug() << "Start to read Content..." << endl; + if (!(t = new_page.firstChildElement("ofd:Content")).isNull()) + { + qDebug() << "Start to read Content..." << endl; QDomElement new_layer = t.firstChildElement("ofd:Layer"); while (!new_layer.isNull()) { CT_Layer * layer_data = new CT_Layer(); @@ -263,100 +280,127 @@ void OFDParser::readPage(Page * page_data) { bool is_first_textcode_x = true, is_first_textcode_y = true; double last_x = 0.0, last_y = 0.0; t = new_layer.firstChildElement("ofd:TextObject"); - while (!t.isNull()) { - //qDebug() << "Start to read TextObject..." << endl; + while (!t.isNull()) + { + qDebug() << "Start to read TextObject" << endl; CT_Text * text_data = new CT_Text(); layer_data->text_object->push_back(text_data); readGraphicUnit(text_data, t); //Read TextObject attributes - if (t.hasAttribute("Font")) { + if (t.hasAttribute("Font")) + { ST_RefID ri(t.attribute("Font").toInt()); text_data->font = ri; - } else { + } + else + { //Error abort(); } - if (t.hasAttribute("Size")) { + if (t.hasAttribute("Size")) + { text_data->size = t.attribute("Size").toDouble(); text_data->size_used = true; - } else { + } + else + { //Error + qDebug() <<"t don't has attribute size"; abort(); } //many optional attributes to be implemented QDomElement t2; - if (!(t2 = t.firstChildElement("ofd:TextCode")).isNull()) { + if (!(t2 = t.firstChildElement("ofd:TextCode")).isNull()) + { + qDebug() << "ofd:TextCode"; + TextCode * text_code_data = new TextCode(); text_data->text_code = text_code_data; - if (t2.hasAttribute("X")) { + if (t2.hasAttribute("X")) + { last_x = text_code_data->x = t2.attribute("X").toDouble(); if (is_first_textcode_x) is_first_textcode_x = false; - } else { + } + else + { if (!is_first_textcode_x && !is_first_textcode_y) text_code_data->x = last_x; - else { + else + { //Error + qDebug() << "ofd:TextCode" + << "if (!is_first_textcode_x && !is_first_textcode_y)"; abort(); } } - if (t2.hasAttribute("Y")) { + if (t2.hasAttribute("Y")) + { last_y = text_code_data->y = t2.attribute("Y").toDouble(); if (is_first_textcode_y) is_first_textcode_y = false; - } else { + } else + { if (!is_first_textcode_x && !is_first_textcode_y) text_code_data->y = last_y; - else { + else + { //Error + qDebug() << "ofd:TextCode if (!is_first_textcode_x && !is_first_textcode_y)"; abort(); } } - if (t2.hasAttribute("DeltaX")) { + if (t2.hasAttribute("DeltaX")) + { ST_Array delta_x_data("DeltaX", t2.attribute("DeltaX")); text_code_data->delta_x = delta_x_data; } - if (t2.hasAttribute("DeltaY")) { + + if (t2.hasAttribute("DeltaY")) + { ST_Array delta_y_data("DeltaX", t2.attribute("DeltaY")); text_code_data->delta_y = delta_y_data; } text_code_data->text = t2.text(); - } else { + } + else + { //Error + qDebug() << "if (!(t2 = t.firstChildElement(\"ofd:TextCode\")).isNull())"; abort(); } t = t.nextSiblingElement("ofd:TextObject"); } - //解析矢量图对象 - t = new_layer.firstChildElement("ofd:PathObject"); - while (!t.isNull()) { - CT_Path * path_data = new CT_Path(); - layer_data->path_object->push_back(path_data); - readGraphicUnit(path_data, t); - if (t.hasAttribute("Stroke")) { - path_data->stroke = t.attribute("Stroke") == "false" ? false : true; - } - if (t.hasAttribute("Fill")) { - path_data->fill = t.attribute("Fill") == "false" ? false : true; - } - if (t.hasAttribute("Rule")) { - if (t.attribute("Rule") == "NonZero") - path_data->rule = "NonZero"; - else if (t.attribute("rule") == "Even-Odd") - path_data->rule = "Even-Odd"; - else { - //Error! - abort(); - } - } - if (!t.firstChildElement("ofd:AbbreviatedData").isNull()) { - path_data->abbreviated_data = t.firstChildElement("ofd:AbbreviatedData").text(); - } - t = t.nextSiblingElement("ofd:PathObject"); - } +// //解析矢量图对象 +// t = new_layer.firstChildElement("ofd:PathObject"); +// while (!t.isNull()) { +// CT_Path * path_data = new CT_Path(); +// layer_data->path_object->push_back(path_data); +// readGraphicUnit(path_data, t); +// if (t.hasAttribute("Stroke")) { +// path_data->stroke = t.attribute("Stroke") == "false" ? false : true; +// } +// if (t.hasAttribute("Fill")) { +// path_data->fill = t.attribute("Fill") == "false" ? false : true; +// } +// if (t.hasAttribute("Rule")) { +// if (t.attribute("Rule") == "NonZero") +// path_data->rule = "NonZero"; +// else if (t.attribute("rule") == "Even-Odd") +// path_data->rule = "Even-Odd"; +// else { +// //Error! +// abort(); +// } +// } +// if (!t.firstChildElement("ofd:AbbreviatedData").isNull()) { +// path_data->abbreviated_data = t.firstChildElement("ofd:AbbreviatedData").text(); +// } +// t = t.nextSiblingElement("ofd:PathObject"); +// } //解析位图对象 t = new_layer.firstChildElement("ofd:ImageObject"); @@ -378,7 +422,7 @@ void OFDParser::readPage(Page * page_data) { t = t.nextSiblingElement("ofd:ImageObject"); } //Other GraphicUnit objects to be implemented - //qDebug() << "End of reading content..." << endl; + qDebug() << "End of reading content..." << endl; new_layer = new_layer.nextSiblingElement("ofd:Layer"); } } @@ -473,7 +517,7 @@ void OFDParser::readGraphicUnit(CT_GraphicUnit *data, QDomElement &root_node) { void OFDParser::readResource(Res * res_data) { openFile(); QDomElement new_res = document->firstChildElement("ofd:Res"); -// qDebug() << "Entering readResource module..." << endl; + qDebug() << "Entering readResource module..." << endl; if (!new_res.isNull()) { //读取属性 if (new_res.hasAttribute("BaseLoc")) { @@ -519,7 +563,7 @@ void OFDParser::readResource(Res * res_data) { //Error abort(); } - //qDebug() << "End of reading Resourse..." << endl; + qDebug() << "End of reading Resourse..." << endl; } void OFDParser::readColor(CT_Color *data, QDomElement & root_node) { diff --git a/ofdEditor/start/ui/PassageMainWindow.cpp b/ofdEditor/start/ui/PassageMainWindow.cpp index 0d17a94..c930838 100644 --- a/ofdEditor/start/ui/PassageMainWindow.cpp +++ b/ofdEditor/start/ui/PassageMainWindow.cpp @@ -309,6 +309,7 @@ void PassageMainWindow::openFile() // 解读文件 // OFDParser ofdParser("C:\\Users\\User\\AppData\\Local\\Temp\\%表格.ofd%\\OFD.xml"); OFDParser ofdParser(tempPath + "/OFD.xml"); // 新建临时路径 +// OFDParser ofdParser("C:/Users/User/Desktop/表格/OFD.xml"); OFD* data = ofdParser.getData(); // 读取出OFD文件 -- Gitee From f9266170a46b5bf90c7c55229a4c02f1accc54b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Tue, 23 May 2017 21:30:34 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=AD=E7=9A=84=E6=96=87=E5=AD=97=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E3=80=81=E6=96=87=E5=AD=97=E5=AD=97=E4=BD=93=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E3=80=81=E6=A1=86=E4=BF=A1=E6=81=AF=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/OFD_DocConvertor.cpp | 220 +++++++++++++++++- ofdEditor/model/Convert/OFD_DocConvertor.h | 16 +- ofdEditor/model/Doc/DocPage.cpp | 7 +- ofdEditor/model/Doc/DocPassage.cpp | 57 +++-- ofdEditor/model/Doc/DocPassage.h | 21 +- ofdEditor/model/Doc/DocTextBlock.cpp | 2 +- ofdEditor/model/Tool/UnitTool.cpp | 15 ++ ofdEditor/model/Tool/UnitTool.h | 1 + .../ofd/DataTypes/document/CT_CommonData.h | 13 ++ .../ofd/DataTypes/document/ct_commondata.h | 13 ++ .../ofd/DataTypes/image/CT_GraphicUnit.h | 2 +- ofdEditor/ofd/DataTypes/page/CT_Layer.h | 6 +- ofdEditor/ofd/DataTypes/page/CT_PageArea.h | 1 + ofdEditor/ofd/DataTypes/page/CT_PageBlock.h | 2 +- ofdEditor/ofd/DataTypes/page/CT_Pages.h | 1 + ofdEditor/ofd/DataTypes/page/Page.h | 1 + ofdEditor/ofd/DataTypes/page/ct_layer.h | 6 +- ofdEditor/ofd/DataTypes/page/ct_pageblock.h | 2 +- ofdEditor/ofd/DataTypes/page/ct_pages.h | 1 + ofdEditor/ofd/DataTypes/page/page.h | 1 + ofdEditor/ofd/DataTypes/text/CT_Text.h | 1 + ofdEditor/ofd/DataTypes/text/TextCode.h | 1 + ofdEditor/ofd/DataTypes/text/ct_text.h | 1 + ofdEditor/ofd/DataTypes/text/textcode.h | 1 + ofdEditor/start/ui/PassageMainWindow.cpp | 30 ++- ofdEditor/start/ui/PassageMainWindow.h | 3 + 26 files changed, 383 insertions(+), 42 deletions(-) diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.cpp b/ofdEditor/model/Convert/OFD_DocConvertor.cpp index 5efa1fc..94db2d2 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.cpp +++ b/ofdEditor/model/Convert/OFD_DocConvertor.cpp @@ -1,10 +1,16 @@ #include "OFD_DocConvertor.h" +#include +#include #include "Doc/DocPassage.h" +#include "Doc/DocPage.h" #include "DataTypes/document/ofd.h" #include "DataTypes/document/document.h" #include "DataTypes/page/ct_pages.h" #include "DataTypes/page/page.h" +#include "Doc/DocTextBlock.h" +#include "Doc/DocBlock.h" +#include "Tool/UnitTool.h" OFD_DocConvertor::OFD_DocConvertor() @@ -21,21 +27,219 @@ OFD_DocConvertor::OFD_DocConvertor() */ DocPassage *OFD_DocConvertor::ofd_to_doc(OFD *ofd) { - DocPassage * passage = new DocPassage(); + DocPassage * passage = NULL; - // version - passage->setVersion(ofd->version); - passage->setDocType(ofd->doc_type); - passage->setDocInfo((*(ofd->docbodys))[0]->doc_info); + try{ - CT_Pages pages = (*(ofd->docs))[0]->pages; // 获得页数 + passage = new DocPassage(); + // version + passage->setVersion(ofd->version); + passage->setDocType(ofd->doc_type); + DocBody * docBody = (*ofd->docbodys)[0]; // DocBody + passage->setDocInfo(*(docBody->doc_info)); - return NULL; + Document * document = (*ofd->docs)[0]; // Document + + CT_CommonData * commonData = document->getCommonData(); // 获取common_data + + // CT_Pages pages = document->pages; // 获得文档中的页 + QVector * pages = document->pages->pages; // 获得页属性 + for(int i = 0; i length(); i++) + { + + // 生成每一页 + DocPage * newPage = this->buildDocPage((*pages)[i]); + newPage->setVisible(true); + passage->addPage(newPage); + } + } + catch(...) + { + qDebug() << "ofd_to_doc:exception."; + } + + return passage; } DocPage *OFD_DocConvertor::buildDocPage(Page *ct_page) { - return NULL; + DocPage * page; + try + { + if(ct_page->area != NULL) + { + // 如果定义了纸张尺寸 + ST_Box physical_box = ct_page->area->physical_box; + page = new DocPage(physical_box.getDeltaX(), + physical_box.getDeltaY(), + 1.0); // 设置纸张大小 + } + else + { + page = new DocPage(); + } + + page->setVisible(false); // 先隐藏显示 + + // 将每一层加入到页中 + QVector* layers = ct_page->content; // 获得文章中的层信息 + for(int i = 0; i < layers->size(); i++) + { + CT_Layer* layer = (*layers)[i]; + qDebug() << "excute insertLayer: " << i; + this->insertLayer(page,layer); // 将该层的内容加入到页面中 + } + + } + catch(...) + { + qDebug() << "OFD_DocConvertor::buildDocPage exception."; + } + + + return page; +} + +/** + * @Author Chaoqun + * @brief 处理CT_Layer + * @param DocPage *page + * @param CT_Layer *layer + * @return void + * @date 2017/05/23 + */ +void OFD_DocConvertor::insertLayer(DocPage *page, CT_Layer *layer) +{ + try + { + + this->insertPageBlock(page,layer,layer); // 先将CT_Layer当作PageBlock处理 + + } + catch(...) + { + qDebug() << "OFD_DocConvertor::insertLayer has exception"; + } +} + +/** + * @Author Chaoqun + * @brief 处理插入pageblock + * @param DocPage *page + * @param CT_Layer *layer + * @param CT_PageBlock* + * @return 返回值 + * @date 2017/xx/xx + */ +void OFD_DocConvertor::insertPageBlock(DocPage *page, CT_Layer *layer, CT_PageBlock *pageBlock) +{ + + CT_Layer::LayerType cttype = layer->type; // 首先获得层 + DocPage::Layer doctype; + switch (cttype) { + case CT_Layer::Foreground: + doctype = DocPage::Foreground; + break; + case CT_Layer::Body: + doctype = DocPage::Body; + break; + case CT_Layer::Background: + doctype = DocPage::Background; + default: + break; + } + + // 处理 CT_Text + QVector * texts = pageBlock->getTextObject(); + for(int i = 0; ilength(); i++) + { + this->insertCT_Text(page,doctype,(*texts)[i]); // 插入文字 + } + + // 处理 CT_Path + + // 处理 CT_Image + + +} + + +/** + * @Author Chaoqun + * @brief 将文字块插入到页面中 + * @param DocPage *page + * @param DocPage::Layer *layer + * @param CT_Text *text + * @return 返回值 + * @date 2017/05/23 + */ +void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Text *text) +{ + TextCode* textCode = text->text_code; // 获得text_code; + // 先简单点 + QString content = textCode->text; // 文本内容 + + DocTextBlock *textBlock = new DocTextBlock(); + DocBlock *block = new DocBlock(); + block->setWidget(textBlock); + + ST_Box box = text->boundary; + block->resize(UnitTool::mmToPixel(box.getDeltaX()), + UnitTool::mmToPixel(box.getDeltaY())); + block->setPos(UnitTool::mmToPixel(box.getX()), + UnitTool::mmToPixel(box.getY())); + + QTextCursor cursor = textBlock->textCursor(); // 获得光标 + + // 去掉QTextEdit的无用的边框 + textBlock->document()->setDocumentMargin(0); // document + QTextFrame * frame = textBlock->document()->rootFrame(); + QTextFrameFormat frameFormat = frame->frameFormat(); // frameFormat + // 清除没用的边缘距离 + frameFormat.setTopMargin(0); + frameFormat.setBottomMargin(0); + frameFormat.setLeftMargin(0); + frameFormat.setRightMargin(0); + frameFormat.setPadding(0); + + frame->setFrameFormat(frameFormat); // 应用Frame格式 + + QTextBlockFormat blockFormat = cursor.blockFormat(); // 块格式 + QTextCharFormat charFormat = cursor.charFormat(); // 字符格式 + QFont font = charFormat.font(); // 字体 + + // 字号 + font.setPixelSize(UnitTool::mmToPixel(text->size)); // 字号 + + // 上下间距 + blockFormat.setTopMargin(0); + blockFormat.setBottomMargin(0); + blockFormat.setLeftMargin(0); + blockFormat.setRightMargin(0); + blockFormat.setLineHeight(0,QTextBlockFormat::MinimumHeight); + + + // 应用格式 + charFormat.setFont(font); // 应用字体格式 + cursor.setCharFormat(charFormat); // 应用字符格式 + cursor.setBlockFormat(blockFormat); // 应用文字块样式 + + cursor.insertText(content); + + + // 插入到场景中 + page->addBlock(block,layer); + +} + +void OFD_DocConvertor::insertCT_Path(DocPage *page, CT_Layer *layer, CT_Path *path) +{ + +} + +void OFD_DocConvertor::insertCT_Image(DocPage *page, DocPage::Layer layer, CT_Image *image) +{ + } diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.h b/ofdEditor/model/Convert/OFD_DocConvertor.h index 0eb424b..1b2601f 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.h +++ b/ofdEditor/model/Convert/OFD_DocConvertor.h @@ -3,13 +3,17 @@ #include "model_global.h" #include +#include "Doc/DocPage.h" class DocPassage; class OFD; class Document; -class DocPage; class Page; - +class CT_Layer; +class CT_PageBlock; +class CT_Text; +class CT_Path; +class CT_Image; /** * @Author Chaoqun @@ -26,7 +30,15 @@ public: DocPassage * ofd_to_doc(OFD * ofd); // 生成文档 private: + OFD * ofdFile; // 当前处理时使用的ofd文件-用来方便获取到公用的特征 + + DocPage * buildDocPage(Page * ct_page); // 生成页 + void insertLayer(DocPage * page, CT_Layer * layer ); // 将每一层加入到页中 + void insertPageBlock(DocPage * page, CT_Layer * layer, CT_PageBlock* pageBlock); // 用于针对块可能嵌套的情况 + void insertCT_Text(DocPage * page, DocPage::Layer layer, CT_Text *text); // 插入CT_Text类 + void insertCT_Path(DocPage * page, CT_Layer * layer, CT_Path *path); // 插入CT_Path + void insertCT_Image(DocPage * page, DocPage::Layer layer, CT_Image *image); // 插入CT_Image }; diff --git a/ofdEditor/model/Doc/DocPage.cpp b/ofdEditor/model/Doc/DocPage.cpp index 188fb12..70107fa 100644 --- a/ofdEditor/model/Doc/DocPage.cpp +++ b/ofdEditor/model/Doc/DocPage.cpp @@ -23,7 +23,7 @@ DocPage::DocPage(QWidget *parent) :QGraphicsView(parent) { - this->setSize(210,297); + this->setSize(210,297); // 默认A4纸张大小 this->scaleFactor = 1.0; this->init(); @@ -98,12 +98,15 @@ void DocPage::addBlock(DocBlock *block, DocPage::Layer layer) switch (layer) { case Body: this->bodyLayer->addBlock(block); + block->setZValue(0); break; case Foreground: this->foregroundLayer->addBlock(block); + block->setZValue(1000); break; case Background: this->backgroundLayer->addBlock(block); + block->setZValue(-1000); break; default: break; @@ -370,6 +373,8 @@ void DocPage::mouseReleaseEvent(QMouseEvent *event) */ void DocPage::init() { + this->setWindowFlags(Qt::Widget); + this->docScene = new DocPageScene(); // 新建 this->setScene(this->docScene); // 设置场景 diff --git a/ofdEditor/model/Doc/DocPassage.cpp b/ofdEditor/model/Doc/DocPassage.cpp index 645c7b6..347c987 100644 --- a/ofdEditor/model/Doc/DocPassage.cpp +++ b/ofdEditor/model/Doc/DocPassage.cpp @@ -2,6 +2,7 @@ #include "DocPage.h" #include "DataTypes/document/CT_DocInfo.h" +#include "DataTypes/document/ct_commondata.h" #include #include @@ -10,7 +11,6 @@ #include #include -//#include "DataTypes/document/CT_CommonData.h" /** * @Author Chaoqun @@ -25,7 +25,7 @@ DocPassage::DocPassage(QWidget *parent) // this->commonData = new CT_CommonData(); this->init(); // 初始化界面 - this->addPage(new DocPage()); // 添加一个空白页面 +// this->addPage(new DocPage()); // 添加一个空白页面 setAttribute(Qt::WA_DeleteOnClose); @@ -61,19 +61,19 @@ DocPassage::~DocPassage() // this->commonData = NULL; // } - // 释放this->pages - int pages_length = this->pages.size(); - for(int i = 0; i < pages_length; i++) - { - // 需要挨个释放内存空间 - DocPage* temp = this->pages.at(i); - if(temp != NULL) - { - delete temp; - (this->pages)[i] = NULL; - } - } - this->pages.clear(); +// 释放this->pages +// int pages_length = this->pages.size(); +// for(int i = 0; i < pages_length; i++) +// { +// // 需要挨个释放内存空间 +// DocPage* temp = this->pages.at(i); +// if(temp != NULL) +// { +// delete temp; +// (this->pages)[i] = NULL; +// } +// } +// this->pages.clear(); } @@ -164,6 +164,33 @@ CT_DocInfo DocPassage::getDocInfo() return docInfo; } +/** + * @Author Chaoqun + * @brief 设置CommonData,深拷贝 + * @param CT_CommonData &commonData + * @return void + * @date 2017/05/23 + */ +//void DocPassage::setCommonData(CT_CommonData* commonData) +//{ +// (this->commonData)->copy(commonData); +//} + +/** + * @Author Chaoqun + * @brief 获取CommonData,新建立对象 + * @param void + * @return CT_CommonData + * @date 2017/05/23 + */ +//CT_CommonData DocPassage::getCommonData() +//{ +// CT_CommonData common; +// common.copy(this->commonData); + +// return common; +//} + /** * @Author Chaoqun * @brief 设置重置响应事件,窗口大小发生调整,将会调用这个函数u diff --git a/ofdEditor/model/Doc/DocPassage.h b/ofdEditor/model/Doc/DocPassage.h index ea0d448..1e817a8 100644 --- a/ofdEditor/model/Doc/DocPassage.h +++ b/ofdEditor/model/Doc/DocPassage.h @@ -35,12 +35,19 @@ public: void addPassage(QVector& passage); // 添加很多界面 void appendNewPage(DocPage *page = NULL); // 如果为空,则代表假如空白页 + // DocInfo void setDocInfo( CT_DocInfo & docInfo ); CT_DocInfo getDocInfo(); + // CommonData +// void setCommonData(CT_CommonData* commonData); +// CT_CommonData getCommonData(); + + // Version void setVersion(QString version){this->version = version;} QString getVersion( ){return this->version;} + // DocType void setDocType(QString docType){this->docType = docType;} QString getDocType( ){return this->docType;} @@ -53,12 +60,12 @@ protected: private: // 数据区 - QString version; // OFD 版本默认 1.0 - QString docType; // 类型默认是 OFD - CT_DocInfo* docInfo; // 文档元数据结构 ofd/CT_DocInfo - //CT_CommonData* commonData; // 文档公用文档数据 + QString version; // OFD 版本默认 1.0 + QString docType; // 类型默认是 OFD + CT_DocInfo* docInfo; // 文档元数据结构 ofd/CT_DocInfo +// CT_CommonData* commonData; // 文档公用文档数据 - QVector pages; // 既作为数据,也作为渲染 + QVector pages; // 既作为数据,也作为渲染 // 渲染区 QVBoxLayout * layout; // 纵向排列 @@ -73,9 +80,9 @@ private: private: - void init(); // 初始化 + void init(); // 初始化 void adjustScrollBar(QScrollBar *scrollBar, - double factor); // 调整滑动条 + double factor); // 调整滑动条 void adjustScrollBarRange(); //调整滑动条范围 void adjustWidgetSize(); // 根据页数来自动调整widget大小 diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index 72779bb..d2a3dd5 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -250,7 +250,7 @@ void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) */ void DocTextBlock::init() { - this->setMinimumSize(15,15); // 为了正确显示缩放标识 + this->setMinimumSize(5,5); // 为了正确显示缩放标识 this->currentTextCharFormat = new QTextCharFormat(); // 初始化 diff --git a/ofdEditor/model/Tool/UnitTool.cpp b/ofdEditor/model/Tool/UnitTool.cpp index 4a494a9..4eac2eb 100644 --- a/ofdEditor/model/Tool/UnitTool.cpp +++ b/ofdEditor/model/Tool/UnitTool.cpp @@ -81,3 +81,18 @@ QRectF UnitTool::getBox(QPointF &point1, QPointF &point2) return QRectF(x,y,w,h); } + +/** + * @Author Chaoqun + * @brief 判断两个数是否相等,因为公文的误差要求是 1mm, + * 对于边框的要求没有那么高。 + * 因此,我这里两者差的绝对值小于 0.05mm即视为相等。 + * @param 参数 + * @return 返回值 + * @date 2017/05/23 + */ +bool UnitTool::equal(double a, double b) +{ + return ((a-b) > -0.05 + && (a-b) < 0.05); +} diff --git a/ofdEditor/model/Tool/UnitTool.h b/ofdEditor/model/Tool/UnitTool.h index 6dce92e..92b5552 100644 --- a/ofdEditor/model/Tool/UnitTool.h +++ b/ofdEditor/model/Tool/UnitTool.h @@ -20,6 +20,7 @@ public: static QRectF getBox(QPointF& point1, QPointF& point2); // 获得两个点组成的方形 + static bool equal(double a, double b); // 因为double的误差,用来判断两个数是否相等 }; #endif // UNITTOOL_H diff --git a/ofdEditor/ofd/DataTypes/document/CT_CommonData.h b/ofdEditor/ofd/DataTypes/document/CT_CommonData.h index 00e9eee..2b731eb 100644 --- a/ofdEditor/ofd/DataTypes/document/CT_CommonData.h +++ b/ofdEditor/ofd/DataTypes/document/CT_CommonData.h @@ -5,6 +5,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_CommonData { +public: ST_ID max_unit_id; //当前文档中所有对象使用的最大标识 CT_PageArea *page_area; //指定多个页面区域的大小和位置 QVector *public_res; //公共资源序列,每个资源指向OFD包内部的一个XML文件 @@ -24,6 +25,18 @@ public: delete public_res; delete page_area; } + + /** + * @Author Chaoqun + * @brief CT_CommonData 深拷贝函数 + * @param CT_CommonData * commonData + * @return void + * @date 2017/05/23 + */ + void copy(CT_CommonData * commonData) + { + // 预计5月30日前实现 + } }; #endif // CT_COMMONDATA_H diff --git a/ofdEditor/ofd/DataTypes/document/ct_commondata.h b/ofdEditor/ofd/DataTypes/document/ct_commondata.h index 00e9eee..2b731eb 100644 --- a/ofdEditor/ofd/DataTypes/document/ct_commondata.h +++ b/ofdEditor/ofd/DataTypes/document/ct_commondata.h @@ -5,6 +5,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_CommonData { +public: ST_ID max_unit_id; //当前文档中所有对象使用的最大标识 CT_PageArea *page_area; //指定多个页面区域的大小和位置 QVector *public_res; //公共资源序列,每个资源指向OFD包内部的一个XML文件 @@ -24,6 +25,18 @@ public: delete public_res; delete page_area; } + + /** + * @Author Chaoqun + * @brief CT_CommonData 深拷贝函数 + * @param CT_CommonData * commonData + * @return void + * @date 2017/05/23 + */ + void copy(CT_CommonData * commonData) + { + // 预计5月30日前实现 + } }; #endif // CT_COMMONDATA_H diff --git a/ofdEditor/ofd/DataTypes/image/CT_GraphicUnit.h b/ofdEditor/ofd/DataTypes/image/CT_GraphicUnit.h index 81568a7..40435a1 100644 --- a/ofdEditor/ofd/DataTypes/image/CT_GraphicUnit.h +++ b/ofdEditor/ofd/DataTypes/image/CT_GraphicUnit.h @@ -13,7 +13,7 @@ // 基本图元对象定义 class OFDSHARED_EXPORT CT_GraphicUnit : public CT_Base { -protected: +public: ST_Box boundary; // 被引用图元对象的外接矩形,采用当前空间坐标系。 QString name; // 图元对象的名字。 bool visible; // 图元是否可见。 diff --git a/ofdEditor/ofd/DataTypes/page/CT_Layer.h b/ofdEditor/ofd/DataTypes/page/CT_Layer.h index 32069c3..9340b19 100644 --- a/ofdEditor/ofd/DataTypes/page/CT_Layer.h +++ b/ofdEditor/ofd/DataTypes/page/CT_Layer.h @@ -5,7 +5,9 @@ #include "../../ofd_global.h" // 生成库文件需要 -class OFDSHARED_EXPORT CT_Layer : public CT_PageBlock { +class OFDSHARED_EXPORT CT_Layer + : public CT_PageBlock +{ public: friend class OFDParser; enum LayerType {Body = 1, Foreground, Background}; @@ -24,7 +26,7 @@ public: } //从CT_PageBlock继承了几个接口 -private: +public: LayerType type; ST_RefID draw_param; CT_Layer() : CT_PageBlock(){ diff --git a/ofdEditor/ofd/DataTypes/page/CT_PageArea.h b/ofdEditor/ofd/DataTypes/page/CT_PageArea.h index 4e4723c..d94a15e 100644 --- a/ofdEditor/ofd/DataTypes/page/CT_PageArea.h +++ b/ofdEditor/ofd/DataTypes/page/CT_PageArea.h @@ -8,6 +8,7 @@ class OFDSHARED_EXPORT CT_PageArea { +public: ST_Box physical_box; // 页面物理区域, // 以其左上角为页面空间坐标系的原点。 ST_Box application_box; // (可选)显示区域, diff --git a/ofdEditor/ofd/DataTypes/page/CT_PageBlock.h b/ofdEditor/ofd/DataTypes/page/CT_PageBlock.h index 0ae7a06..baa2040 100644 --- a/ofdEditor/ofd/DataTypes/page/CT_PageBlock.h +++ b/ofdEditor/ofd/DataTypes/page/CT_PageBlock.h @@ -8,7 +8,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_PageBlock : public CT_Base{ -protected: +public: QVector * text_object; QVector * path_object; QVector * image_object; diff --git a/ofdEditor/ofd/DataTypes/page/CT_Pages.h b/ofdEditor/ofd/DataTypes/page/CT_Pages.h index 9152525..0ffadd7 100644 --- a/ofdEditor/ofd/DataTypes/page/CT_Pages.h +++ b/ofdEditor/ofd/DataTypes/page/CT_Pages.h @@ -6,6 +6,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_Pages { +public: QVector * pages; CT_Pages() { pages = new QVector(); diff --git a/ofdEditor/ofd/DataTypes/page/Page.h b/ofdEditor/ofd/DataTypes/page/Page.h index 0947f89..5e726e9 100644 --- a/ofdEditor/ofd/DataTypes/page/Page.h +++ b/ofdEditor/ofd/DataTypes/page/Page.h @@ -7,6 +7,7 @@ #include "../document/res.h" class OFDSHARED_EXPORT Page : public CT_Base{ +public: ST_Loc base_loc; CT_PageArea * area; QVector * page_res; diff --git a/ofdEditor/ofd/DataTypes/page/ct_layer.h b/ofdEditor/ofd/DataTypes/page/ct_layer.h index 32069c3..9340b19 100644 --- a/ofdEditor/ofd/DataTypes/page/ct_layer.h +++ b/ofdEditor/ofd/DataTypes/page/ct_layer.h @@ -5,7 +5,9 @@ #include "../../ofd_global.h" // 生成库文件需要 -class OFDSHARED_EXPORT CT_Layer : public CT_PageBlock { +class OFDSHARED_EXPORT CT_Layer + : public CT_PageBlock +{ public: friend class OFDParser; enum LayerType {Body = 1, Foreground, Background}; @@ -24,7 +26,7 @@ public: } //从CT_PageBlock继承了几个接口 -private: +public: LayerType type; ST_RefID draw_param; CT_Layer() : CT_PageBlock(){ diff --git a/ofdEditor/ofd/DataTypes/page/ct_pageblock.h b/ofdEditor/ofd/DataTypes/page/ct_pageblock.h index 0ae7a06..baa2040 100644 --- a/ofdEditor/ofd/DataTypes/page/ct_pageblock.h +++ b/ofdEditor/ofd/DataTypes/page/ct_pageblock.h @@ -8,7 +8,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_PageBlock : public CT_Base{ -protected: +public: QVector * text_object; QVector * path_object; QVector * image_object; diff --git a/ofdEditor/ofd/DataTypes/page/ct_pages.h b/ofdEditor/ofd/DataTypes/page/ct_pages.h index 9152525..0ffadd7 100644 --- a/ofdEditor/ofd/DataTypes/page/ct_pages.h +++ b/ofdEditor/ofd/DataTypes/page/ct_pages.h @@ -6,6 +6,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_Pages { +public: QVector * pages; CT_Pages() { pages = new QVector(); diff --git a/ofdEditor/ofd/DataTypes/page/page.h b/ofdEditor/ofd/DataTypes/page/page.h index 0947f89..5e726e9 100644 --- a/ofdEditor/ofd/DataTypes/page/page.h +++ b/ofdEditor/ofd/DataTypes/page/page.h @@ -7,6 +7,7 @@ #include "../document/res.h" class OFDSHARED_EXPORT Page : public CT_Base{ +public: ST_Loc base_loc; CT_PageArea * area; QVector * page_res; diff --git a/ofdEditor/ofd/DataTypes/text/CT_Text.h b/ofdEditor/ofd/DataTypes/text/CT_Text.h index 3a88614..3d14385 100644 --- a/ofdEditor/ofd/DataTypes/text/CT_Text.h +++ b/ofdEditor/ofd/DataTypes/text/CT_Text.h @@ -10,6 +10,7 @@ class OFDSHARED_EXPORT CT_Text : public CT_GraphicUnit { //文字对象 +public: //属性 ST_RefID font; //字体 double size; //字号 diff --git a/ofdEditor/ofd/DataTypes/text/TextCode.h b/ofdEditor/ofd/DataTypes/text/TextCode.h index 5318f57..c84ae10 100644 --- a/ofdEditor/ofd/DataTypes/text/TextCode.h +++ b/ofdEditor/ofd/DataTypes/text/TextCode.h @@ -4,6 +4,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT TextCode { //文字内容,也就是一段字符编码串。需要进行XML转义 +public: double x, y; //首字形的绘制点的横纵坐标 ST_Array delta_x, delta_y; //字形绘制点横纵方向偏移 QString text; //!!!!!文本内容 diff --git a/ofdEditor/ofd/DataTypes/text/ct_text.h b/ofdEditor/ofd/DataTypes/text/ct_text.h index 3a88614..3d14385 100644 --- a/ofdEditor/ofd/DataTypes/text/ct_text.h +++ b/ofdEditor/ofd/DataTypes/text/ct_text.h @@ -10,6 +10,7 @@ class OFDSHARED_EXPORT CT_Text : public CT_GraphicUnit { //文字对象 +public: //属性 ST_RefID font; //字体 double size; //字号 diff --git a/ofdEditor/ofd/DataTypes/text/textcode.h b/ofdEditor/ofd/DataTypes/text/textcode.h index 5318f57..c84ae10 100644 --- a/ofdEditor/ofd/DataTypes/text/textcode.h +++ b/ofdEditor/ofd/DataTypes/text/textcode.h @@ -4,6 +4,7 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT TextCode { //文字内容,也就是一段字符编码串。需要进行XML转义 +public: double x, y; //首字形的绘制点的横纵坐标 ST_Array delta_x, delta_y; //字形绘制点横纵方向偏移 QString text; //!!!!!文本内容 diff --git a/ofdEditor/start/ui/PassageMainWindow.cpp b/ofdEditor/start/ui/PassageMainWindow.cpp index c930838..b58260f 100644 --- a/ofdEditor/start/ui/PassageMainWindow.cpp +++ b/ofdEditor/start/ui/PassageMainWindow.cpp @@ -22,6 +22,7 @@ #include "Loaders/ZipTool.h" // 压缩文件工具 #include "ofd_parser.h" #include "DataTypes/document/ofd.h" +#include "Convert/OFD_DocConvertor.h" // OFD 转 Doc 工具 PassageMainWindow::PassageMainWindow(QWidget *parent) :QMainWindow(parent) @@ -44,10 +45,12 @@ PassageMainWindow::~PassageMainWindow() DocPassage *PassageMainWindow::createMdiChild() { DocPassage * child = new DocPassage(this); + child->addPage(new DocPage()); // 添加一个空白页 + this->area->addSubWindow(child); child->setVisible(true); // 设置可见 child->showMaximized(); - return NULL; + return child; } /** @@ -311,6 +314,10 @@ void PassageMainWindow::openFile() OFDParser ofdParser(tempPath + "/OFD.xml"); // 新建临时路径 // OFDParser ofdParser("C:/Users/User/Desktop/表格/OFD.xml"); OFD* data = ofdParser.getData(); // 读取出OFD文件 + OFD_DocConvertor convert; + DocPassage* passage = convert.ofd_to_doc(data); + + this->addDocPassage(passage); // 添加文章 @@ -331,3 +338,24 @@ DocPassage *PassageMainWindow::activeMdiChild() return qobject_cast(activeSubWindow->widget()); return 0; } + +/** + * @Author Chaoqun + * @brief 添加一个文章 + * @param DocPassage *passage + * @return DocPassage * + * @date 2017/05/23 + */ +DocPassage *PassageMainWindow::addDocPassage(DocPassage *passage) +{ + if(passage == NULL) // 如果参数为NULL 不执行并返回NULL + { + qDebug() << "DocPassage Pointer is NULL."; + return NULL; + } + + this->area->addSubWindow(passage); + passage->setVisible(true); // 设置可见 + passage->showMaximized(); + return passage; +} diff --git a/ofdEditor/start/ui/PassageMainWindow.h b/ofdEditor/start/ui/PassageMainWindow.h index a2d922b..4f18ba2 100644 --- a/ofdEditor/start/ui/PassageMainWindow.h +++ b/ofdEditor/start/ui/PassageMainWindow.h @@ -23,6 +23,9 @@ public: DocPassage *createMdiChild(); // 创建一个新文档 DocPassage *activeMdiChild(); // 获取活动的窗口 +public slots: + DocPassage *addDocPassage(DocPassage * passage); + private: // 菜单栏 -- Gitee From 4fb14074a7dd127687cf88cd4e0a6fe06e05faa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Thu, 25 May 2017 22:17:33 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=AE=B5=E8=90=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Doc/DocTextBlock.cpp | 98 ++- ofdEditor/model/Doc/DocTextBlock.h | 15 +- ofdEditor/model/Widget/FontSettingDialog.cpp | 114 ++++ ofdEditor/model/Widget/FontSettingDialog.h | 31 +- ofdEditor/model/Widget/FontSettingDialog.ui | 584 +++++++++++++++++- .../model/Widget/ParagraphFormatDialog.cpp | 193 +++--- .../model/Widget/ParagraphFormatDialog.ui | 6 +- .../model/Widget/ParagraphFormatWidget.ui | 39 ++ 8 files changed, 956 insertions(+), 124 deletions(-) diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index d2a3dd5..cd3f1a4 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -1,6 +1,7 @@ #include "DocTextBlock.h" #include "Doc/DocParagraph.h" #include "Widget/ParagraphFormatDialog.h" +#include "Widget/FontSettingDialog.h" #include #include @@ -74,6 +75,14 @@ void DocTextBlock::currentCharFormatChangedEvent( const QTextCharFormat &format) { + QTextCursor cursor = this->textCursor(); + QTextBlockFormat blockFormat = cursor.blockFormat(); + + ParagraphFormatDialog * para = new ParagraphFormatDialog( + blockFormat,this); + + para->exec(); + } /** @@ -202,6 +211,13 @@ void DocTextBlock::textFontDialog() } +void DocTextBlock::customFontDialog() +{ + + FontSettingDialog * font = new FontSettingDialog(); + font->exec(); +} + /** * @Author Chaoqun * @brief 设置当前选中的段落的格式 @@ -226,6 +242,27 @@ void DocTextBlock::setTextBlockFormat( } +/** + * @Author Chaoqun + * @brief 直接修改选中的文字的CharFormat + * @param const QTextCharFormat &format + * @return void + * @date 2017/05/25 + */ +void DocTextBlock::setCharFormatOnWordOrSelection( + const QTextCharFormat &format) +{ + QTextCursor cursor = this->textCursor(); // 新建光标 + if(!cursor.hasSelection()) + { + // 如果没有选择文字段落 + cursor.select(QTextCursor::WordUnderCursor); + qDebug() << "cursor has no selection!"; + } + cursor.setCharFormat(format); // 设置光标下的 QTextCharFormat + this->setCurrentCharFormat(format); // 合并当前的 QTextCharFormat +} + /** * @Author Chaoqun * @brief 显示右键菜单 @@ -241,6 +278,32 @@ void DocTextBlock::contextMenuEvent(QContextMenuEvent *event) } +/** + * @Author Chaoqun + * @brief 焦点聚焦,显示边框 + * @param QFocusEvent *e + * @return void + * @date 2017/05/25 + */ +void DocTextBlock::focusInEvent(QFocusEvent *e) +{ + this->setFrameStyle(QFrame::Box); + QTextEdit::focusInEvent(e); +} + +/** + * @Author Chaoqun + * @brief 焦点移出,隐藏边框 + * @param QFocusEvent *e + * @return void + * @date 2017/05/25 + */ +void DocTextBlock::focusOutEvent(QFocusEvent *e) +{ + this->setFrameStyle(QFrame::NoFrame); + QTextEdit::focusOutEvent(e); +} + /** * @Author Chaoqun * @brief 初始化函数 @@ -252,8 +315,6 @@ void DocTextBlock::init() { this->setMinimumSize(5,5); // 为了正确显示缩放标识 - this->currentTextCharFormat = new QTextCharFormat(); // 初始化 - // 关闭滑动条 this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -261,7 +322,9 @@ void DocTextBlock::init() // 设置为背景透明 this->viewport()->setAttribute(Qt::WA_TranslucentBackground, true); // 无边框 -// this->setFrameStyle(QFrame::NoFrame); + this->setFrameStyle(QFrame::NoFrame); + + this->initFormat(); // 初始化格式 @@ -322,11 +385,17 @@ void DocTextBlock::initAcitons() this->connect(this->actionFontSet,&QAction::triggered, this,&DocTextBlock::textFontDialog); + // 段落 this->actionParagraph = new QAction(tr("Paragraph")); - this->connect(this->actionParagraph,&QAction::triggered, this,&DocTextBlock::textParagraph); + + // 字体窗口测试 + this->actionFontSetTest = new QAction(tr("FontDialogTest")); + this->connect(this->actionFontSetTest, &QAction::triggered, + this, &DocTextBlock::customFontDialog); + // 右键菜单 this->ContextMenu = createStandardContextMenu(); // 拓展标准菜单 this->ContextMenu->addAction(this->actionBold); @@ -335,4 +404,25 @@ void DocTextBlock::initAcitons() this->ContextMenu->addSeparator(); this->ContextMenu->addAction(this->actionFontSet); this->ContextMenu->addAction(this->actionParagraph); + + this->ContextMenu->addAction(this->actionFontSetTest); +} + + +/** + * @Author Chaoqun + * @brief 初始化文字的样式 + * @param void + * @return void + * @date 2017/05/25 + */ +void DocTextBlock::initFormat() +{ + QTextCursor cursor = this->textCursor(); // 获得当前光标 + + QTextCharFormat charFormat = cursor.charFormat(); // 字符格式 + charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); + + this->mergeCurrentCharFormat(charFormat); + } diff --git a/ofdEditor/model/Doc/DocTextBlock.h b/ofdEditor/model/Doc/DocTextBlock.h index 9eb687b..c627f59 100644 --- a/ofdEditor/model/Doc/DocTextBlock.h +++ b/ofdEditor/model/Doc/DocTextBlock.h @@ -37,19 +37,26 @@ public slots: // void textColor(); // void textAlign(QAction *a); void textFontDialog(); // 通过字体小窗口设置字体 + void customFontDialog(); // 自定义的字体窗口设置 void setTextBlockFormat( const QTextBlockFormat& blockFormat); // 设置块格式 + void setCharFormatOnWordOrSelection( + const QTextCharFormat &format); // 设置选中字段的QTextCharFormat + + void mergeFormatOnWordOrSelection( + const QTextCharFormat &format); // 合并格式 + protected: void contextMenuEvent(QContextMenuEvent *event); // 右键菜单重载 + void focusInEvent(QFocusEvent *e); + void focusOutEvent(QFocusEvent *e); private slots: - void mergeFormatOnWordOrSelection( - const QTextCharFormat &format); // 合并格式 void currentCharFormatChangedEvent( const QTextCharFormat &format); // 选中的文字格式发生了变化 void cursorPositionChangedEvent( ); // 光标位置发生改变 @@ -58,9 +65,9 @@ private slots: private: QString content; // 文字内容 - QTextCharFormat* currentTextCharFormat; // 当前 QTextCharFormat样式 void init(); // 初始化 void initAcitons(); // 初始化事件 + void initFormat(); // 初始化文字样式 // QActions QAction * actionBold; // 加粗 @@ -69,6 +76,8 @@ private: QAction * actionFontSet; // 设置字体 QAction * actionParagraph; // 设置段落 + QAction * actionFontSetTest; // 新字体窗口测试 + QMenu * ContextMenu; // 右键菜单 diff --git a/ofdEditor/model/Widget/FontSettingDialog.cpp b/ofdEditor/model/Widget/FontSettingDialog.cpp index fe21d07..0e675ac 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.cpp +++ b/ofdEditor/model/Widget/FontSettingDialog.cpp @@ -1,6 +1,11 @@ #include "FontSettingDialog.h" #include "ui_FontSettingDialog.h" +#include +#include +#include "Doc/DocTextBlock.h" +#include + FontSettingDialog::FontSettingDialog(QWidget *parent) : QDialog(parent), ui(new Ui::FontSettingDialog) @@ -8,7 +13,116 @@ FontSettingDialog::FontSettingDialog(QWidget *parent) : ui->setupUi(this); } +FontSettingDialog::FontSettingDialog(DocTextBlock *textBlock + , QWidget *parent) + :QDialog(parent), + ui(new Ui::FontSettingDialog) +{ + ui->setupUi(this); + this->textBlock = textBlock; +} + FontSettingDialog::~FontSettingDialog() { delete ui; } + +/** + * @Author Chaoqun + * @brief 根据ComboBox的Index来查找字体的点大小 + * @param int comboIndex + * @return double + * @date 2017/05/25 + */ +double FontSettingDialog::pointSizeF(int comboIndex) +{ + QMap::iterator iter = this->pointSizeTable.find(comboIndex); + return *iter; +} + +/** + * @Author Chaoqun + * @brief 根据pointSizeF来查找 + * @param 参数 + * @return 返回值 + * @date 2017/05/25 + */ +int FontSettingDialog::comboIndex(double pointSizeF) +{ + // 如果查询不到,则返回-1 + int index = this->pointSizeTable.key(pointSizeF, -1); + return index; +} + +/** + * @Author Chaoqun + * @brief 用来更新预览窗口中文字的效果 + * @param const QTextCharFormat &charFormat + * @return void + * @date 2017/05/25 + */ +void FontSettingDialog::updatePreview(const QTextCharFormat &charFormat) +{ + +} + +/** + * @Author Chaoqun + * @brief 初始化界面 + * @param const QTextCharFormat &charFormat + * @return void + * @date 2017/05/25 + */ +void FontSettingDialog::init(const QTextCharFormat &charFormat) +{ + this->charFormat = new QTextCharFormat(charFormat); // 存下这个charFormat,后面可以使用 + + QFont font = charFormat.font(); // 获得字体 + + // 点大小与Index的对应关系 + this->pointSizeTable.insert(0,42); // 初号 + this->pointSizeTable.insert(1,36); // 小初 + this->pointSizeTable.insert(2,27.5); // 一号 + this->pointSizeTable.insert(3,24); // 小一 + this->pointSizeTable.insert(4,21); // 二号 + this->pointSizeTable.insert(5,18); // 小二 + this->pointSizeTable.insert(6,16); // 三号 + this->pointSizeTable.insert(7,15); // 小三 + this->pointSizeTable.insert(8,14); // 四号 + this->pointSizeTable.insert(9,12); // 小四 + this->pointSizeTable.insert(10,10.5); // 五号 + this->pointSizeTable.insert(11,9); // 小五 + this->pointSizeTable.insert(12,7.5); // 六号 + this->pointSizeTable.insert(13,6.5); // 小六 + this->pointSizeTable.insert(14,5.25); // 七号 + this->pointSizeTable.insert(15,4.5); // 八号 + this->pointSizeTable.insert(16,5); + this->pointSizeTable.insert(17,5.5); + this->pointSizeTable.insert(18,6.5); + this->pointSizeTable.insert(19,7.5); + this->pointSizeTable.insert(20,8); + this->pointSizeTable.insert(21,9); + this->pointSizeTable.insert(22,10); + this->pointSizeTable.insert(23,10.5); + this->pointSizeTable.insert(24,11); + this->pointSizeTable.insert(25,12); + this->pointSizeTable.insert(26,14); + this->pointSizeTable.insert(27,16); + this->pointSizeTable.insert(29,18); + this->pointSizeTable.insert(30,20); + this->pointSizeTable.insert(31,22); + this->pointSizeTable.insert(32,24); + this->pointSizeTable.insert(33,26); + this->pointSizeTable.insert(34,28); + this->pointSizeTable.insert(35,36); + this->pointSizeTable.insert(36,48); + this->pointSizeTable.insert(37,72); + + + + // 设置字体栏 + this->ui->comboFont->setCurrentFont(font); + + + +} diff --git a/ofdEditor/model/Widget/FontSettingDialog.h b/ofdEditor/model/Widget/FontSettingDialog.h index c7ec093..9a066b3 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.h +++ b/ofdEditor/model/Widget/FontSettingDialog.h @@ -1,22 +1,51 @@ #ifndef FONTSETTINGDIALOG_H #define FONTSETTINGDIALOG_H +#include "model_global.h" +#include +#include #include +#include + +class QTextCharFormat; +class QTextBlockFormat; +class QFont; +class DocTextBlock; namespace Ui { class FontSettingDialog; } -class FontSettingDialog : public QDialog +class MODELSHARED_EXPORT FontSettingDialog : public QDialog { Q_OBJECT public: explicit FontSettingDialog(QWidget *parent = 0); + FontSettingDialog(DocTextBlock* textBlock,QWidget *parent = 0); ~FontSettingDialog(); +signals: + void sendFont(const QTextCharFormat& charFormat); // 返回结果给DocTextBlock的信号 + void signal_updatePreview(const QTextCharFormat& charFormat); // 更新预览框的信号 + private: Ui::FontSettingDialog *ui; + + DocTextBlock * textBlock; // 指向待调整文本框 + QTextCharFormat* charFormat; // 预览框的格式 + + QTextCharFormat getQTextCharFormat(); // 获得更新后的字体 + + + QMap pointSizeTable; // 字号与Index对应表 + double pointSizeF(int comboIndex); // 获取字号大小与Index的对应关系 + int comboIndex(double pointSizeF); // 获得Index与pointSize的对应关系 + +private slots: + void updatePreview(const QTextCharFormat& charFormat); // 设置为预览,用来更新预览文字的效果 + + void init(const QTextCharFormat& charFormat); }; #endif // FONTSETTINGDIALOG_H diff --git a/ofdEditor/model/Widget/FontSettingDialog.ui b/ofdEditor/model/Widget/FontSettingDialog.ui index d23eb4c..fd7081e 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.ui +++ b/ofdEditor/model/Widget/FontSettingDialog.ui @@ -1,3 +1,4 @@ + FontSettingDialog @@ -5,28 +6,585 @@ 0 0 - 480 - 640 + 481 + 606 + + + 0 + 0 + + Dialog - + - 10 - 600 - 461 - 32 + 20 + 20 + 451 + 571 - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + + + + + + 200 + 250 + + + + + 480 + 400 + + + + 字体 + + + + + 10 + 30 + 421 + 184 + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + 粗体 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 字体 + + + Qt::AlignCenter + + + + + + + 字号 + + + Qt::AlignCenter + + + + + + + 下划线 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 字体效果预览 + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">文字测试样例</p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Text Demo</p></body></html> + + + + + + + 斜体 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QComboBox::AdjustToContents + + + + 初号 + + + + + 小初 + + + + + 一号 + + + + + 小一 + + + + + 二号 + + + + + 小二 + + + + + 三号 + + + + + 小三 + + + + + 四号 + + + + + 小四 + + + + + 五号 + + + + + 小五 + + + + + 六号 + + + + + 小六 + + + + + 七号 + + + + + 八号 + + + + + 5 + + + + + 5.5 + + + + + 6.5 + + + + + 7.5 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 10.5 + + + + + 11 + + + + + 12 + + + + + 14 + + + + + 16 + + + + + 18 + + + + + 20 + + + + + 22 + + + + + 24 + + + + + 26 + + + + + 28 + + + + + 36 + + + + + 48 + + + + + 72 + + + + + + + + QComboBox::AdjustToContents + + + + 黑体 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + 200 + 200 + + + + + 480 + 400 + + + + 高级 + + + + + 10 + 30 + 421 + 151 + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + 字间距 + + + Qt::AlignCenter + + + + + + + 拉伸字体 + + + Qt::AlignCenter + + + + + + + 字体粗细 + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + + + + + + + + + 等宽字体 + + + + + + + + + + + + 0 + 50 + + + + + 16777215 + 100 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 40 + + + + + diff --git a/ofdEditor/model/Widget/ParagraphFormatDialog.cpp b/ofdEditor/model/Widget/ParagraphFormatDialog.cpp index 9616438..1fc96b7 100644 --- a/ofdEditor/model/Widget/ParagraphFormatDialog.cpp +++ b/ofdEditor/model/Widget/ParagraphFormatDialog.cpp @@ -25,16 +25,18 @@ QTextBlockFormat ParagraphFormatDialog::getQTextBlockFormat() QTextBlockFormat blockFormat; // 用来纪录格式的 Qt::Alignment horizontalFlag; - Qt::Alignment verticalFlag; +// Qt::Alignment verticalFlag; // 水平布局 int comboHAlignIndex = ui->comboHAlignment->currentIndex(); switch (comboHAlignIndex) { case 0: - horizontalFlag = (Qt::AlignLeft | Qt::AlignAbsolute); +// horizontalFlag = (Qt::AlignLeft | Qt::AlignAbsolute); + horizontalFlag = (Qt::AlignLeft); break; case 1: - horizontalFlag = (Qt::AlignRight | Qt::AlignAbsolute); +// horizontalFlag = (Qt::AlignRight | Qt::AlignAbsolute); + horizontalFlag = (Qt::AlignRight); break; case 2: horizontalFlag = Qt::AlignHCenter; @@ -47,40 +49,42 @@ QTextBlockFormat ParagraphFormatDialog::getQTextBlockFormat() } - // 竖直布局 - int comboVAlignIndex = ui->comboVAlignment->currentIndex(); - switch (comboVAlignIndex) { - case 0: - verticalFlag = Qt::AlignTop; - break; - case 1: - verticalFlag = Qt::AlignBottom; - break; - case 2: - verticalFlag = Qt::AlignVCenter; - break; - default: - break; - } +// // 竖直布局 +// int comboVAlignIndex = ui->comboVAlignment->currentIndex(); +// switch (comboVAlignIndex) { +// case 0: +// verticalFlag = Qt::AlignTop; +// break; +// case 1: +// verticalFlag = Qt::AlignBottom; +// break; +// case 2: +// verticalFlag = Qt::AlignVCenter; +// break; +// default: +// break; +// } // 设置布局规则 - blockFormat.setAlignment(horizontalFlag | verticalFlag); - - // 设置文字方向 - Qt::LayoutDirection textDirection; - int textDirectionIndex = ui->comboTextDirection->currentIndex(); - switch (textDirectionIndex) { - case 0: - textDirection = Qt::LeftToRight; - break; - case 1: - textDirection = Qt::RightToLeft; - break; - default: - textDirection = Qt::LeftToRight; - break; - } - blockFormat.setLayoutDirection(textDirection); +// blockFormat.setAlignment(verticalFlag | horizontalFlag); + blockFormat.setAlignment(horizontalFlag); + +// // 设置文字方向 + // 无法使用,仅对部分语言有效 +// Qt::LayoutDirection textDirection; +// int textDirectionIndex = ui->comboTextDirection->currentIndex(); +// switch (textDirectionIndex) { +// case 0: +// textDirection = Qt::LeftToRight; +// break; +// case 1: +// textDirection = Qt::RightToLeft; +// break; +// default: +// textDirection = Qt::LeftToRight; +// break; +// } +// blockFormat.setLayoutDirection(textDirection); // 缩进规则 int paraIndent = ui->paraIndent->value(); @@ -97,9 +101,9 @@ QTextBlockFormat ParagraphFormatDialog::getQTextBlockFormat() blockFormat.setTopMargin(spaceBefore); blockFormat.setBottomMargin(spaceAfter); - // 设置行距 - int comboLineHeightIndex = ui->comboLineHeight->currentIndex(); - double lineHeight = ui->doubleLineHight->value(); + // 设置行高 + int comboLineHeightIndex = ui->comboLineHeight->currentIndex(); // 判断行高类型 + double lineHeight = ui->doubleLineHight->value(); // 获得行高 switch (comboLineHeightIndex) { case 0: @@ -155,78 +159,67 @@ void ParagraphFormatDialog::init(const QTextBlockFormat &blockFormat) // 设置对齐部分 Qt::Alignment flag = blockFormat.alignment(); // 先获取对齐的样式 Qt::Alignment horizontalFlag; - Qt::Alignment verticalFlag; +// Qt::Alignment verticalFlag; + + horizontalFlag = flag & Qt::AlignHorizontal_Mask; +// verticalFlag = flag & Qt::AlignVertical_Mask; - // 水平样式 - if((flag&(Qt::AlignLeft | Qt::AlignAbsolute)) - == (Qt::AlignLeft | Qt::AlignAbsolute)) - { - // 如果水平居左 + // 水平对齐 + switch (horizontalFlag) { + case Qt::AlignLeft: ui->comboHAlignment->setCurrentIndex(0); - } - else if((flag & (Qt::AlignRight | Qt::AlignAbsolute)) - == (Qt::AlignRight | Qt::AlignAbsolute)) - { - // 如果水平居右 + break; + case Qt::AlignRight: ui->comboHAlignment->setCurrentIndex(1); - } - else if((flag & Qt::AlignHCenter) - == Qt::AlignHCenter) - { - // 如果水平居中 + break; + case Qt::AlignHCenter: ui->comboHAlignment->setCurrentIndex(2); - } - else if((flag & Qt::AlignJustify) - == Qt::AlignJustify) - { - // 如果是两端对齐模式 - ui->comboHAlignment->setCurrentIndex(3); - } - else - { - // 如果样式未设置水平样式 - ui->comboHAlignment->setCurrentIndex(-1); - } - - // 竖直样式 - if((flag & Qt::AlignTop) - == Qt::AlignTop) - { - // 如果设置的是居上对齐 - ui->comboVAlignment->setCurrentIndex(0); - } - else if((flag & Qt::AlignBottom) - == Qt::AlignBottom) - { - // 如果设置的是居下对齐 - ui->comboVAlignment->setCurrentIndex(1); - } - else if((flag & Qt::AlignVCenter) - == Qt::AlignVCenter) - { - // 如果设置的是竖直居中对齐 - ui->comboVAlignment->setCurrentIndex(2); - } - else - { - // 如果未设置竖直对齐样式 - ui->comboVAlignment->setCurrentIndex(3); - } - - //文字方向 - Qt::LayoutDirection textDirection = blockFormat.layoutDirection(); - switch (textDirection) { - case Qt::LeftToRight: - ui->comboTextDirection->setCurrentIndex(0); break; - case Qt::RightToLeft: - ui->comboTextDirection->setCurrentIndex(1); + case Qt::AlignJustify: + ui->comboHAlignment->setCurrentIndex(3); break; default: - ui->comboTextDirection->setCurrentIndex(0); + ui->comboHAlignment->setCurrentIndex(-1); break; } +// // 竖直对齐 +// switch (verticalFlag) { +// case Qt::AlignTop: +// ui->comboVAlignment->setCurrentIndex(0); +// break; +// case Qt::AlignBottom: +// ui->comboVAlignment->setCurrentIndex(1); +// break; +// case Qt::AlignCenter: +// ui->comboVAlignment->setCurrentIndex(2); +// break; +// default: +// ui->comboVAlignment->setCurrentIndex(-1); +// break; +// } + + // 因竖直对齐的调整并没有效果,这里选择去掉 + this->ui->comboVAlignment->setVisible(false); + this->ui->label_12->setVisible(false); + +// 因为文字方向无法使用,所以将其隐藏掉 +// //文字方向 +// Qt::LayoutDirection textDirection = blockFormat.layoutDirection(); +// switch (textDirection) { +// case Qt::LeftToRight: +// ui->comboTextDirection->setCurrentIndex(0); +// break; +// case Qt::RightToLeft: +// ui->comboTextDirection->setCurrentIndex(1); +// break; +// default: +// ui->comboTextDirection->setCurrentIndex(0); +// break; +// } + this->ui->comboTextDirection->setVisible(false); + this->ui->label_13->setVisible(false); + // 整段缩进 int indent = blockFormat.indent(); ui->paraIndent->setValue(indent); diff --git a/ofdEditor/model/Widget/ParagraphFormatDialog.ui b/ofdEditor/model/Widget/ParagraphFormatDialog.ui index ef8b257..661cb5e 100644 --- a/ofdEditor/model/Widget/ParagraphFormatDialog.ui +++ b/ofdEditor/model/Widget/ParagraphFormatDialog.ui @@ -150,7 +150,7 @@ - 竖直 + 文字方向 @@ -329,7 +329,7 @@ - 行高值 + @@ -375,7 +375,7 @@ - 行高策略 + 行距策略 diff --git a/ofdEditor/model/Widget/ParagraphFormatWidget.ui b/ofdEditor/model/Widget/ParagraphFormatWidget.ui index 5d641b4..993df7d 100644 --- a/ofdEditor/model/Widget/ParagraphFormatWidget.ui +++ b/ofdEditor/model/Widget/ParagraphFormatWidget.ui @@ -532,6 +532,45 @@ 取消 + + + + 250 + 40 + 70 + 25 + + + + 文字方向 + + + + + + 340 + 40 + 100 + 25 + + + + QComboBox::AdjustToMinimumContentsLength + + + 10 + + + + 自左向右 + + + + + 自右向左 + + + -- Gitee From 220f926445cfa8faec175cc3a896a1d3184785ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Fri, 26 May 2017 11:16:11 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=AD=90=E4=BD=93=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=99=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/OFD_DocConvertor.cpp | 6 + ofdEditor/model/Doc/DocPage.cpp | 2 +- ofdEditor/model/Doc/DocTextBlock.cpp | 31 ++- ofdEditor/model/Widget/FontSettingDialog.cpp | 211 +++++++++++++++++-- ofdEditor/model/Widget/FontSettingDialog.h | 17 +- ofdEditor/model/Widget/FontSettingDialog.ui | 23 +- 6 files changed, 248 insertions(+), 42 deletions(-) diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.cpp b/ofdEditor/model/Convert/OFD_DocConvertor.cpp index 94db2d2..2b45ab5 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.cpp +++ b/ofdEditor/model/Convert/OFD_DocConvertor.cpp @@ -177,10 +177,14 @@ void OFD_DocConvertor::insertPageBlock(DocPage *page, CT_Layer *layer, CT_PageBl */ void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Text *text) { +// qDebug() << "execute insert CT_Text"; + TextCode* textCode = text->text_code; // 获得text_code; // 先简单点 QString content = textCode->text; // 文本内容 +// qDebug() << "insert Content:" << content; + DocTextBlock *textBlock = new DocTextBlock(); DocBlock *block = new DocBlock(); block->setWidget(textBlock); @@ -226,6 +230,8 @@ void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Tex cursor.setCharFormat(charFormat); // 应用字符格式 cursor.setBlockFormat(blockFormat); // 应用文字块样式 +// qDebug() <<"Set Format"; + cursor.insertText(content); diff --git a/ofdEditor/model/Doc/DocPage.cpp b/ofdEditor/model/Doc/DocPage.cpp index 70107fa..ad3c760 100644 --- a/ofdEditor/model/Doc/DocPage.cpp +++ b/ofdEditor/model/Doc/DocPage.cpp @@ -93,7 +93,7 @@ void DocPage::addBlock(DocBlock *block, DocPage::Layer layer) qDebug() << "DocPage::addBlock excuted"; this->docScene->addItem(block); // 添加元素 - qDebug() << "DocPage::addBlock excuted this->docScene->addItem(block);"; +// qDebug() << "DocPage::addBlock excuted this->docScene->addItem(block);"; switch (layer) { case Body: diff --git a/ofdEditor/model/Doc/DocTextBlock.cpp b/ofdEditor/model/Doc/DocTextBlock.cpp index cd3f1a4..305bdf5 100644 --- a/ofdEditor/model/Doc/DocTextBlock.cpp +++ b/ofdEditor/model/Doc/DocTextBlock.cpp @@ -75,14 +75,6 @@ void DocTextBlock::currentCharFormatChangedEvent( const QTextCharFormat &format) { - QTextCursor cursor = this->textCursor(); - QTextBlockFormat blockFormat = cursor.blockFormat(); - - ParagraphFormatDialog * para = new ParagraphFormatDialog( - blockFormat,this); - - para->exec(); - } /** @@ -99,11 +91,15 @@ void DocTextBlock::cursorPositionChangedEvent() void DocTextBlock::setFont(const QFont &font) { - QTextCharFormat currentFormat = - this->currentCharFormat(); // 当前选择文字的样式 +// QTextCharFormat currentFormat = +// this->currentCharFormat(); // 当前选择文字的样式 + QTextCursor cursor = this->textCursor(); + QTextCharFormat currentFormat = cursor.charFormat(); + currentFormat.setFont(font); // 设置字体 - mergeCurrentCharFormat(currentFormat); +// mergeCurrentCharFormat(currentFormat); + mergeFormatOnWordOrSelection(currentFormat); } @@ -190,13 +186,16 @@ void DocTextBlock::textParagraph() void DocTextBlock::textFontDialog() { bool btn_ok; // 确认按键 - QTextCharFormat currentFormat = - this->currentCharFormat(); // 当前选择文字的样式 + QTextCursor cursor = this->textCursor(); + QTextCharFormat currentFormat = cursor.charFormat(); +// QTextCharFormat currentFormat = +// this->currentCharFormat(); // 当前选择文字的样式 QFont oldFont = currentFormat.font(); // 获取之前的字体样式 QFont newFont = QFontDialog::getFont( &btn_ok, oldFont,NULL,tr("Set the font"), - QFontDialog::ScalableFonts); // 选择字体框 + QFontDialog::ScalableFonts|QFontDialog::NonScalableFonts + |QFontDialog::MonospacedFonts|QFontDialog::ProportionalFonts); // 选择字体框 if(btn_ok) { @@ -214,7 +213,7 @@ void DocTextBlock::textFontDialog() void DocTextBlock::customFontDialog() { - FontSettingDialog * font = new FontSettingDialog(); + FontSettingDialog * font = new FontSettingDialog(this,0); font->exec(); } @@ -321,7 +320,7 @@ void DocTextBlock::init() // 设置为背景透明 this->viewport()->setAttribute(Qt::WA_TranslucentBackground, true); - // 无边框 +// // 无边框 this->setFrameStyle(QFrame::NoFrame); this->initFormat(); // 初始化格式 diff --git a/ofdEditor/model/Widget/FontSettingDialog.cpp b/ofdEditor/model/Widget/FontSettingDialog.cpp index 0e675ac..e81017e 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.cpp +++ b/ofdEditor/model/Widget/FontSettingDialog.cpp @@ -19,7 +19,17 @@ FontSettingDialog::FontSettingDialog(DocTextBlock *textBlock ui(new Ui::FontSettingDialog) { ui->setupUi(this); - this->textBlock = textBlock; + this->textBlock = textBlock; // 记录下负责的DocTextBlock + + this->connect(this,&FontSettingDialog::signal_updatePreview, + this,&FontSettingDialog::updatePreview); // 更新预览的链接 + + QTextCursor cursor = this->textBlock->textCursor(); // 获得文本的光标 + QTextCharFormat charFormat = cursor.charFormat(); // 获得光标的charFormat + this->init(charFormat); // 初始化字体窗口 + + initConnect(); // 初始化信号连接 + } FontSettingDialog::~FontSettingDialog() @@ -50,8 +60,48 @@ double FontSettingDialog::pointSizeF(int comboIndex) int FontSettingDialog::comboIndex(double pointSizeF) { // 如果查询不到,则返回-1 - int index = this->pointSizeTable.key(pointSizeF, -1); - return index; +// int index = this->pointSizeTable.key(pointSizeF, -1); +// return index; + + QMapIterator iter(this->pointSizeTable); // 迭代器 + int key = -1; + + while(iter.hasNext()) + { + iter.next(); + if((iter.value() - pointSizeF) > -0.01 + && (iter.value() - pointSizeF) < 0.01) // 当两个差值绝对值小于0.01即可判断相等 + { + // 判断相等 + key = iter.key(); // 赋值 + break; + } + } + + return key; + +} + +/** + * @Author Chaoqun + * @brief 初始化链接 + * @param void + * @return void + * @date 2017/05/26 + */ +void FontSettingDialog::initConnect() +{ + this->connect(this->ui->comboFont, &QFontComboBox::currentFontChanged, + this,&FontSettingDialog::updateFontFamily); // 链接字体 + + this->connect(this->ui->comboFontSize, + static_cast(&QComboBox::currentIndexChanged), + this, &FontSettingDialog::updateFontSizeF); // 链接字体大小 + + connect(this->ui->checkBold, &QCheckBox::stateChanged, + this,&FontSettingDialog::updateBold); // 链接加粗 + + } /** @@ -63,7 +113,9 @@ int FontSettingDialog::comboIndex(double pointSizeF) */ void FontSettingDialog::updatePreview(const QTextCharFormat &charFormat) { - + QTextCursor cursor = this->ui->textBrowser->textCursor(); + cursor.select(QTextCursor::Document); // 选择这篇文章 + cursor.setCharFormat(charFormat); // 设置格式 } /** @@ -77,8 +129,11 @@ void FontSettingDialog::init(const QTextCharFormat &charFormat) { this->charFormat = new QTextCharFormat(charFormat); // 存下这个charFormat,后面可以使用 - QFont font = charFormat.font(); // 获得字体 + // 字体框 + QFont font = charFormat.font(); // 获得字体 + this->ui->comboFont->setCurrentFont(font); // 设置显示 + // 字体大小框 // 点大小与Index的对应关系 this->pointSizeTable.insert(0,42); // 初号 this->pointSizeTable.insert(1,36); // 小初 @@ -108,21 +163,145 @@ void FontSettingDialog::init(const QTextCharFormat &charFormat) this->pointSizeTable.insert(25,12); this->pointSizeTable.insert(26,14); this->pointSizeTable.insert(27,16); - this->pointSizeTable.insert(29,18); - this->pointSizeTable.insert(30,20); - this->pointSizeTable.insert(31,22); - this->pointSizeTable.insert(32,24); - this->pointSizeTable.insert(33,26); - this->pointSizeTable.insert(34,28); - this->pointSizeTable.insert(35,36); - this->pointSizeTable.insert(36,48); - this->pointSizeTable.insert(37,72); + this->pointSizeTable.insert(28,18); + this->pointSizeTable.insert(29,20); + this->pointSizeTable.insert(30,22); + this->pointSizeTable.insert(31,24); + this->pointSizeTable.insert(32,26); + this->pointSizeTable.insert(33,28); + this->pointSizeTable.insert(34,36); + this->pointSizeTable.insert(35,48); + this->pointSizeTable.insert(36,72); + + + int fontsizeIndex = this->comboIndex(font.pointSizeF()); // 设置对应的字体大小 + this->ui->comboFontSize->setCurrentIndex(fontsizeIndex); + + // 粗体 + if(font.bold()) + { + this->ui->checkBold->setChecked(true); + } + else + { + this->ui->checkBold->setChecked(false); + } + + // 斜体 + if(font.italic()) + { + this->ui->checkItalic->setChecked(true); + } + else + { + this->ui->checkItalic->setChecked(false); + } + + // 下划线 + if(font.underline()) + { + this->ui->checkUnderline->setChecked(true); + } + else + { + this->ui->checkUnderline->setChecked(false); + } + + // 字间距 + double wordSpcing = font.wordSpacing(); + this->ui->doubleFontSpace->setValue(wordSpcing); + + // 拉伸字体 + int wordStrech = font.stretch(); + this->ui->doubleFontStretch->setValue(wordStrech); + + // weight + int weight = font.weight(); + this->ui->intFontWeight->setValue(weight); + + // 等宽字体 + if(font.fixedPitch()) + { + this->ui->checkFixedWidth->setChecked(true); + } + else + { + this->ui->checkFixedWidth->setChecked(false); + } + + emit signal_updatePreview(*this->charFormat); // 更新预览窗口 + +} + +/** + * @Author Chaoqun + * @brief 槽函数,更新字体类别 + * @param const QFont &font + * @return void + * @date 2017/05/26 + */ +void FontSettingDialog::updateFontFamily(const QFont &font) +{ + this->charFormat->setFontFamily(font.family()); // 设置字体 + + emit this->signal_updatePreview(*this->charFormat); // 发送信号 +} + +/** + * @Author Chaoqun + * @brief 槽函数,更新字体大小 + * @param double pointSizef + * @return void + * @date 2017/05/26 + */ +void FontSettingDialog::updateFontSizeF(int index) +{ + QFont font = this->charFormat->font(); // 获得字体 - // 设置字体栏 - this->ui->comboFont->setCurrentFont(font); + double pointsizef = this->pointSizeF(index);// 计算出点大小 + font.setPointSizeF(pointsizef); // 设置字体大小 + this->charFormat->setFont(font); // 更新字体 + emit this->signal_updatePreview(*this->charFormat); // 发射更新预览信号 +} +/** + * @Author Chaoqun + * @brief 槽函数,处理加粗 + * @param int state 0 uncheck 2checked + * @return 返回值 + * @date 2017/05/26 + */ +void FontSettingDialog::updateBold(int state) +{ + QFont font = this->charFormat->font(); // 获得字体 + + if(state == 0) + { + font.setBold(false); + } + else if(state == 2) + { + font.setBold(true); + } + else + { + font.setBold(false); + } + + this->charFormat->setFont(font); + + emit this->signal_updatePreview(*this->charFormat); +} + +void FontSettingDialog::updateItalic(int state) +{ + +} + +void FontSettingDialog::updateUnderline(int state) +{ } diff --git a/ofdEditor/model/Widget/FontSettingDialog.h b/ofdEditor/model/Widget/FontSettingDialog.h index 9a066b3..a158e94 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.h +++ b/ofdEditor/model/Widget/FontSettingDialog.h @@ -21,7 +21,7 @@ class MODELSHARED_EXPORT FontSettingDialog : public QDialog Q_OBJECT public: - explicit FontSettingDialog(QWidget *parent = 0); + FontSettingDialog(DocTextBlock* textBlock,QWidget *parent = 0); ~FontSettingDialog(); @@ -30,10 +30,11 @@ signals: void signal_updatePreview(const QTextCharFormat& charFormat); // 更新预览框的信号 private: + explicit FontSettingDialog(QWidget *parent = 0); Ui::FontSettingDialog *ui; - DocTextBlock * textBlock; // 指向待调整文本框 - QTextCharFormat* charFormat; // 预览框的格式 + DocTextBlock * textBlock; // 指向待调整文本框 + QTextCharFormat* charFormat; // 预览框的格式 QTextCharFormat getQTextCharFormat(); // 获得更新后的字体 @@ -41,11 +42,21 @@ private: QMap pointSizeTable; // 字号与Index对应表 double pointSizeF(int comboIndex); // 获取字号大小与Index的对应关系 int comboIndex(double pointSizeF); // 获得Index与pointSize的对应关系 + void initConnect(); // 初始化各种函数的链接 + private slots: void updatePreview(const QTextCharFormat& charFormat); // 设置为预览,用来更新预览文字的效果 void init(const QTextCharFormat& charFormat); + + void updateFontFamily(const QFont &font); // 更新字体 + void updateFontSizeF(int index); // 更新字体大小 + void updateBold(int state); // 加粗 + void updateItalic(int state); // 斜体 + void updateUnderline(int state); // 下划线 + + }; #endif // FONTSETTINGDIALOG_H diff --git a/ofdEditor/model/Widget/FontSettingDialog.ui b/ofdEditor/model/Widget/FontSettingDialog.ui index fd7081e..200213a 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.ui +++ b/ofdEditor/model/Widget/FontSettingDialog.ui @@ -113,7 +113,7 @@ - + 下划线 @@ -527,13 +527,14 @@ p, li { white-space: pre-wrap; } - - - - + + + 1000.000000000000000 + + - + @@ -542,6 +543,16 @@ p, li { white-space: pre-wrap; } + + + + 1 + + + 4000 + + + -- Gitee From 3dec75afd7ebd9263f42e10529458f7c64fbc988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Fri, 26 May 2017 16:06:03 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Widget/FontSettingDialog.cpp | 173 ++++++++++++++++++- ofdEditor/model/Widget/FontSettingDialog.h | 6 + ofdEditor/model/Widget/FontSettingDialog.ui | 3 + 3 files changed, 177 insertions(+), 5 deletions(-) diff --git a/ofdEditor/model/Widget/FontSettingDialog.cpp b/ofdEditor/model/Widget/FontSettingDialog.cpp index e81017e..bccc80f 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.cpp +++ b/ofdEditor/model/Widget/FontSettingDialog.cpp @@ -101,6 +101,29 @@ void FontSettingDialog::initConnect() connect(this->ui->checkBold, &QCheckBox::stateChanged, this,&FontSettingDialog::updateBold); // 链接加粗 + connect(this->ui->checkItalic, &QCheckBox::stateChanged, + this,&FontSettingDialog::updateItalic); // 链接斜体 + + connect(this->ui->checkUnderline, &QCheckBox::stateChanged, + this,&FontSettingDialog::updateUnderline); // 链接下划线 + + connect(this->ui->checkFixedWidth, &QCheckBox::stateChanged, + this,&FontSettingDialog::updatefixedPitch); // 固定字宽 + + connect(this->ui->intFontWeight, + static_cast(&QSpinBox::valueChanged), + this,&FontSettingDialog::updateWeight); // 字体粗细 + + connect(this->ui->doubleFontSpace, + static_cast(&QDoubleSpinBox::valueChanged), + this,&FontSettingDialog::updateWordSpacing); // 字间距 + + + connect(this, &FontSettingDialog::accepted, + this, &FontSettingDialog::accept_slots); // 窗口接受确认的信号 + + connect(this,&FontSettingDialog::sendFont, + this->textBlock,&DocTextBlock::setCharFormatOnWordOrSelection); // 发送字体 } @@ -208,12 +231,17 @@ void FontSettingDialog::init(const QTextCharFormat &charFormat) } // 字间距 - double wordSpcing = font.wordSpacing(); +// double wordSpcing = font.wordSpacing(); + double wordSpcing = font.letterSpacing(); this->ui->doubleFontSpace->setValue(wordSpcing); // 拉伸字体 - int wordStrech = font.stretch(); - this->ui->doubleFontStretch->setValue(wordStrech); +// int wordStrech = font.stretch(); +// this->ui->doubleFontStretch->setValue(wordStrech); + this->ui->label_5->setVisible(false); + this->ui->doubleFontStretch->setVisible(false); + this->ui->checkFixedWidth->setVisible(false); + // weight int weight = font.weight(); @@ -280,11 +308,13 @@ void FontSettingDialog::updateBold(int state) if(state == 0) { - font.setBold(false); + if(font.bold()) + font.setBold(false); } else if(state == 2) { - font.setBold(true); + if(!font.bold()) + font.setBold(true); } else { @@ -293,15 +323,148 @@ void FontSettingDialog::updateBold(int state) this->charFormat->setFont(font); + // 更新字重 + int weight = font.weight(); + this->ui->intFontWeight->setValue(weight); + emit this->signal_updatePreview(*this->charFormat); } +/** + * @Author Chaoqun + * @brief 槽函数,检测斜体 + * @param int state 0 uncheck 2 checked + * @return void + * @date 2017/05/26 + */ void FontSettingDialog::updateItalic(int state) { + if(state == 0) + { + this->charFormat->setFontItalic(false); + } + else if(state == 2) + { + this->charFormat->setFontItalic(true); + } + else + { + this->charFormat->setFontItalic(false); + } + + emit this->signal_updatePreview(*this->charFormat); } + +/** + * @Author Chaoqun + * @brief 检测下划线选项 + * @param int state + * @return void + * @date 2017/05/26 + */ void FontSettingDialog::updateUnderline(int state) { + if(state == 0) + { + this->charFormat->setFontUnderline(false); + } + else if(state == 2) + { + this->charFormat->setFontUnderline(true); + } + else + { + this->charFormat->setFontUnderline(false); + } + + emit this->signal_updatePreview(*this->charFormat); +} + +/** + * @Author Chaoqun + * @brief 更新字间距 + * @param double d + * @return void + * @date 2017/05/26 + */ +void FontSettingDialog::updateWordSpacing(double d) +{ + QFont font = this->charFormat->font(); +// font.setWordSpacing(d); + font.setLetterSpacing(QFont::PercentageSpacing,d); + this->charFormat->setFont(font); + + emit this->signal_updatePreview(*this->charFormat); +} + +/** + * @Author Chaoqun + * @brief 设置字符比例 + * @param int i + * @return void + * @date 2017/05/26 + */ +void FontSettingDialog::updateFontStrech(int i) +{ + QFont font = this->charFormat->font(); + font.setStretch(i); + this->charFormat->setFont(font); + + emit this->signal_updatePreview(*this->charFormat); +} + + +/** + * @Author Chaoqun + * @brief 是否选择了固定字宽 + * @param int state + * @return void + * @date 2017/05/26 + */ +void FontSettingDialog::updatefixedPitch(int state) +{ + if(state == 0) + this->charFormat->setFontFixedPitch(false); + else if(state == 2) + this->charFormat->setFontFixedPitch(true); + else + this->charFormat->setFontFixedPitch(false); + + emit this->signal_updatePreview(*this->charFormat); +} + +/** + * @Author Chaoqun + * @brief 对字体粗细做出反应 + * @param int i + * @return void + * @date 2017/05/26 + */ +void FontSettingDialog::updateWeight(int i) +{ + this->charFormat->setFontWeight(i); + + // 更新加粗框 + QFont font = this->charFormat->font(); + if(font.bold()) + this->ui->checkBold->setChecked(true); + else + this->ui->checkBold->setChecked(false); + + emit this->signal_updatePreview(*this->charFormat); +} + +/** + * @Author Chaoqun + * @brief 用户确定事件 + * @param void + * @return void +* @date 2017/05/26 + */ +void FontSettingDialog::accept_slots() +{ + emit this->sendFont(*this->charFormat); } diff --git a/ofdEditor/model/Widget/FontSettingDialog.h b/ofdEditor/model/Widget/FontSettingDialog.h index a158e94..be925c4 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.h +++ b/ofdEditor/model/Widget/FontSettingDialog.h @@ -55,6 +55,12 @@ private slots: void updateBold(int state); // 加粗 void updateItalic(int state); // 斜体 void updateUnderline(int state); // 下划线 + void updateWordSpacing(double d); // 更新字间距s + void updateFontStrech(int i); // 更新字比例 + void updatefixedPitch(int state); // 固定字宽 + void updateWeight(int i); // 字体粗细 + + void accept_slots(); // 向DocTextBlock传递成功事件 }; diff --git a/ofdEditor/model/Widget/FontSettingDialog.ui b/ofdEditor/model/Widget/FontSettingDialog.ui index 200213a..4a0f631 100644 --- a/ofdEditor/model/Widget/FontSettingDialog.ui +++ b/ofdEditor/model/Widget/FontSettingDialog.ui @@ -476,6 +476,9 @@ p, li { white-space: pre-wrap; } + + true + 拉伸字体 -- Gitee From c18742eeffac5d37ab8efa56ab85a595c86ff06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Fri, 26 May 2017 21:23:25 +0800 Subject: [PATCH 7/8] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 5a9ff4c36d58d7022c9c617663dbc1db56603719 Author: Pan Yanxing Date: Thu May 25 23:24:47 2017 +0800 为所有数据类添加了set方法和构造方法,并为set方法的值提供了一些检查。简单测试了一下,似乎没有什么问题(? commit 00dddcc8e97f619d1b8dbc3b492e5805b3ff9cce Author: Pan Yanxing Date: Thu May 25 01:26:50 2017 +0800 添加了组件ID的管理功能,可以通过ID查询文档中对应的组件,并且在使用注册新ID和引用已有ID时会进行检查,保证新申请的ID不重复,引用的ID必存在。给OFD的数据类型提供了修改的方法和构造函数,目前已经完成到CT_Layer,马上从CT_PageBlock继续。现在有个问题就是构造函数的参数表可能非常长,尤其是有继承关系的类。明天考虑一下如何解决 commit 2f32a60046c0b354d884f8fd5073ea8d8dc63ab1 Author: Pan Yanxing Date: Tue May 23 18:49:04 2017 +0800 增加了OFDParser和OFDWriter的异常信息,处理了OFDWriter在写OFD时的创建文件夹和文件的路径问题 commit 354b298e8eed9512dbaf198f1450e9b754c130d3 Merge: e5c1d3b 11a4e99 Author: Mcoder Date: Mon May 22 17:14:51 2017 +0800 Merge pull request !19 from Mcoder/chaoqun commit e5c1d3bc6b1674bc95420a662b4a8b6982f5e804 Merge: f309937 05121b3 Author: Mcoder Date: Sat May 20 10:29:09 2017 +0800 Merge pull request !18 from Mcoder/chaoqun # Conflicts: # ofdEditor/ofd/DataTypes/document/CT_DocInfo.h # ofdEditor/ofd/DataTypes/document/OFD.h # ofdEditor/ofd/DataTypes/document/ct_docinfo.h # ofdEditor/ofd/DataTypes/document/ofd.h # ofdEditor/ofd/DataTypes/page/CT_Layer.h # ofdEditor/ofd/DataTypes/page/ct_layer.h # ofdEditor/ofd/ofd.pro # ofdEditor/ofd/ofd_parser.cpp # ofdEditor/ofd/ofd_parser.h # ofdEditor/ofd/ofd_writer.h --- ofdEditor/ofd/DataTypes/Color/CT_ColorSpace.h | 46 ++- ofdEditor/ofd/DataTypes/basic_datatype.h | 55 ++- ofdEditor/ofd/DataTypes/basic_datatypes.cpp | 35 +- .../ofd/DataTypes/document/CT_CommonData.h | 54 ++- ofdEditor/ofd/DataTypes/document/CT_DocInfo.h | 105 +++-- ofdEditor/ofd/DataTypes/document/DocBody.h | 30 +- ofdEditor/ofd/DataTypes/document/Document.h | 122 +++++- ofdEditor/ofd/DataTypes/document/OFD.h | 69 +++- .../ofd/DataTypes/document/ct_commondata.h | 54 ++- ofdEditor/ofd/DataTypes/document/ct_docinfo.h | 105 +++-- ofdEditor/ofd/DataTypes/document/docbody.h | 30 +- ofdEditor/ofd/DataTypes/document/document.h | 122 +++++- ofdEditor/ofd/DataTypes/document/ofd.h | 69 +++- ofdEditor/ofd/DataTypes/document/res.h | 58 ++- ofdEditor/ofd/DataTypes/image/CT_DrawParam.h | 204 ++++++++-- .../ofd/DataTypes/image/CT_GraphicUnit.h | 148 ++++++- ofdEditor/ofd/DataTypes/image/CT_Image.h | 26 +- ofdEditor/ofd/DataTypes/image/CT_Path.h | 44 ++- ofdEditor/ofd/DataTypes/page/CT_Layer.h | 49 ++- ofdEditor/ofd/DataTypes/page/CT_PageArea.h | 39 +- ofdEditor/ofd/DataTypes/page/CT_PageBlock.h | 54 ++- ofdEditor/ofd/DataTypes/page/CT_Pages.h | 18 +- ofdEditor/ofd/DataTypes/page/Page.h | 52 ++- ofdEditor/ofd/DataTypes/page/ct_layer.h | 49 ++- ofdEditor/ofd/DataTypes/page/ct_pageblock.h | 54 ++- ofdEditor/ofd/DataTypes/page/ct_pages.h | 18 +- ofdEditor/ofd/DataTypes/page/page.h | 52 ++- ofdEditor/ofd/DataTypes/text/CT_Font.h | 35 ++ ofdEditor/ofd/DataTypes/text/CT_Text.h | 110 +++++- ofdEditor/ofd/DataTypes/text/TextCode.h | 45 ++- ofdEditor/ofd/DataTypes/text/ct_font.h | 35 ++ ofdEditor/ofd/DataTypes/text/ct_text.h | 110 +++++- ofdEditor/ofd/DataTypes/text/textcode.h | 45 ++- ofdEditor/ofd/main.cpp | 14 +- ofdEditor/ofd/ofd.pro | 36 +- ofdEditor/ofd/ofd_parser.cpp | 353 ++++++++--------- ofdEditor/ofd/ofd_parser.h | 6 +- ofdEditor/ofd/ofd_writer.cpp | 104 ++--- ofdEditor/ofd/ofd_writer.h | 4 +- ofdEditor/ofd/ofdexceptions.cpp | 84 ++++ ofdEditor/ofd/ofdexceptions.h | 83 ++++ ofdEditor/ofdEditor.pro | 4 +- ofdEditor/test_pan/main.cpp | 50 ++- ofdEditor/test_pan/mainwindow.cpp | 366 +----------------- ofdEditor/test_pan/ofd_parser.cpp | 6 +- ofdEditor/test_pan/test_pan.pro | 62 +-- 46 files changed, 2346 insertions(+), 967 deletions(-) create mode 100644 ofdEditor/ofd/ofdexceptions.cpp create mode 100644 ofdEditor/ofd/ofdexceptions.h diff --git a/ofdEditor/ofd/DataTypes/Color/CT_ColorSpace.h b/ofdEditor/ofd/DataTypes/Color/CT_ColorSpace.h index 8ec7df8..0b2d133 100644 --- a/ofdEditor/ofd/DataTypes/Color/CT_ColorSpace.h +++ b/ofdEditor/ofd/DataTypes/Color/CT_ColorSpace.h @@ -16,15 +16,58 @@ public : QString getType() { return type; } + + void setType(QString _type) { + QStringList possible_value; + possible_value.append("Gray"); + possible_value.append("RGB"); + possible_value.append("CMYK"); + + if (possible_value.contains(_type) || _type.isNull()) { + type = _type; + } + else throw InvalidValueException("新建CT_ColorSpace对象时Type属性使用了无效的值: " + _type); + } + int getBitsPerComponent() { return bits_per_component; } + + void setBitsPerComponent(int _bits_per_component) { + if (_bits_per_component <= 0) + throw InvalidValueException("新建CT_ColorSpace对象时BitsPerComponent属性使用了无效的值: " + QString::number(_bits_per_component)); + bits_per_component = _bits_per_component; + } + ST_Loc getProfile() { return profile; } + void setProfile(QString _profile) { + ST_Loc p("Profile", _profile); + profile = p; + } + //Other methods to be implemented + CT_ColorSpace(int _id = 0, + ID_Table * id_table = nullptr, + QString _type = "RGB", + int _bits_per_component = 8, + QString _profile = "") { + if (_id && id_table) { + if (id_table->contains(_id)) + throw InvalidIDException("新建CT_ColorSpace对象时申请了已被使用的ID: " + QString::number(_id)); + ST_ID i(_id); + CT_Base::setID(i, id_table); + } + setType(_type); + setBitsPerComponent(_bits_per_component); + if (!_profile.isNull()) { + setProfile(_profile); + } + } + private: //属性 QString type; @@ -34,9 +77,6 @@ private: // Palette // 调色版描述 //vector Palette; // 调色板描述 - CT_ColorSpace() { - bits_per_component = 8; - } }; //class OFDSHARED_EXPORT CT_ColorSpace_Palette{ diff --git a/ofdEditor/ofd/DataTypes/basic_datatype.h b/ofdEditor/ofd/DataTypes/basic_datatype.h index 54887c0..ca79756 100644 --- a/ofdEditor/ofd/DataTypes/basic_datatype.h +++ b/ofdEditor/ofd/DataTypes/basic_datatype.h @@ -5,6 +5,8 @@ #include #include "../ofd_global.h" // 生成库文件时需要 #include +#include +#include "../ofdexceptions.h" //6种基本数据类型 class OFDSHARED_EXPORT ST_Loc { @@ -104,14 +106,8 @@ public: //对QStringList的一些简单封装(在有需要时再拓展接口 } }; -class ID_Table { //为方便ID的管理,为两者建一个基类 -protected: - static QVector id_set; //凡是出现过的ID,全都在其中记录 -}; - - -class OFDSHARED_EXPORT ST_ID : public ID_Table { +class OFDSHARED_EXPORT ST_ID { long id; bool is_null; public: @@ -121,20 +117,19 @@ public: } ST_ID(int _id) { - if (id_set.contains(_id)){ - //!!!出现重复ID,报错处理 - } id = _id; is_null = false; + } operator long() { return id; } long getID() { return id; } bool isNull() { return is_null; } + }; -class OFDSHARED_EXPORT ST_RefID : public ID_Table { +class OFDSHARED_EXPORT ST_RefID { long ref_id; bool is_null; public: @@ -143,10 +138,8 @@ public: ref_id = 0; } ST_RefID(int _ref_id) { - if (!id_set.contains(_ref_id)){ - //!!!不存在的ID,报错处理 - } ref_id = _ref_id; + is_null = false; } operator long() { return ref_id; } long getRefID() { return ref_id; } @@ -187,15 +180,47 @@ public: bool isNull() { return is_null; } }; +class CT_Base; + +class OFDSHARED_EXPORT ID_Table { //为方便ID的管理,为两者建一个基类 +private: + QMap id_pool; //凡是出现过的ID,全都在其中记录 +public: + friend class ST_ID; + friend class ST_RefID; + + CT_Base * getItem(int key); //若该key对应的东西不存在,则返回空指针 + + bool contains(int key); + + int key(CT_Base * value); //返回以value为值的键值。若不存在,则返回0 + + CT_Base * remove(int key); //从集合中删去键值为key的元素,并将其返回。若不存在,则返回空指针 + + //bool insert(int key, CT_Base * value); //向集合中添加一项,若成功则返回true,否则返回false + + int size(); //返回集合中项的个数 + + bool registerItem(ST_ID key, CT_Base * value); //在集合中注册一个新的ID,若成功返回true,否则返回false + bool registerItem(int key, CT_Base * value); //重载 +}; class OFDSHARED_EXPORT CT_Base { //所有含有ID属性的元素的基类 ST_ID id; public: + ST_ID getID() { return id; } - void setID(ST_ID new_id) { + + void setID(ST_ID new_id, ID_Table * _id_table) { + if (_id_table->contains(new_id.getID())) + throw InvalidIDException("试图注册重复的ID: " + QString::number(new_id)); id = new_id; + _id_table->registerItem(new_id.getID(), this); } + }; + + #endif // COMMONDT_H diff --git a/ofdEditor/ofd/DataTypes/basic_datatypes.cpp b/ofdEditor/ofd/DataTypes/basic_datatypes.cpp index f6109ff..83a00a6 100644 --- a/ofdEditor/ofd/DataTypes/basic_datatypes.cpp +++ b/ofdEditor/ofd/DataTypes/basic_datatypes.cpp @@ -1,4 +1,37 @@ #include "basic_datatype.h" #include "../ofd_global.h" // 生成库文件时需要 -QVector ID_Table::id_set; +CT_Base * ID_Table::getItem(int key) { + if (id_pool.contains(key)) + return id_pool[key]; + else return nullptr; +} + +bool ID_Table::contains(int key) { + return id_pool.contains(key); +} + +int ID_Table::key(CT_Base * value) { + return id_pool.key(value, 0); +} + +CT_Base * ID_Table::remove(int key) { + if (id_pool.contains(key)) + return id_pool.take(key); + else return nullptr; +} + +bool ID_Table::registerItem(int key, CT_Base * value) { + if (id_pool.contains(key)) + return false; + else id_pool.insert(key, value); + return true; +} + +bool ID_Table::registerItem(ST_ID key, CT_Base * value) { + return registerItem(key.getID(), value); +} + +int ID_Table::size() { + return id_pool.size(); +} diff --git a/ofdEditor/ofd/DataTypes/document/CT_CommonData.h b/ofdEditor/ofd/DataTypes/document/CT_CommonData.h index 2b731eb..af90a1b 100644 --- a/ofdEditor/ofd/DataTypes/document/CT_CommonData.h +++ b/ofdEditor/ofd/DataTypes/document/CT_CommonData.h @@ -11,16 +11,58 @@ public: QVector *public_res; //公共资源序列,每个资源指向OFD包内部的一个XML文件 //vector template_page; //模板页序列 ST_RefID default_cs; //缺省颜色空间 +public: + friend class OFDParser; + CT_CommonData() { public_res = new QVector(); page_area = nullptr; } -public: - friend class OFDParser; - ST_ID getMaxUnitID() { return max_unit_id; } - CT_PageArea *getPageArea() { return page_area; } - QVector *getPublicRes() { return public_res; } - ST_RefID getDefaultCS() { return default_cs; } + + ST_ID getMaxUnitID() { + return max_unit_id; + } + + void setMaxUnitID(int _max_unit_id) { + if (_max_unit_id < 0) + throw InvalidValueException("Invalid Value in MaxUnitID in CT_CommonData: " + QString::number(_max_unit_id)); + ST_ID i(_max_unit_id); + max_unit_id = i; + } + + CT_PageArea *getPageArea() { + return page_area; + } + + void setPageArea(CT_PageArea * _page_area) { + if (!_page_area) + throw InvalidValueException("Invalid Value in PageArea in CT_CommonData: null pointer"); + delete page_area; + page_area = _page_area; + } + + QVector *getPublicRes() { + return public_res; + } + + void setPublicRes(QVector * _public_res) { + if (!_public_res) + throw InvalidValueException("Invalid Value in PublicRes in CT_CommonData: null pointer"); + delete public_res; + public_res = _public_res; + } + + ST_RefID getDefaultCS() { + return default_cs; + } + + void setDefaultCS(int _default_cs, ID_Table * id_table) { + if (!id_table->contains(_default_cs)) + throw InvalidIDException("Unregistered ID in DefaultCS in CT_CommonData: " + QString::number(_default_cs)); + ST_RefID ri(_default_cs); + default_cs = ri; + } + ~CT_CommonData() { delete public_res; delete page_area; diff --git a/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h b/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h index c76bf61..ba75f78 100644 --- a/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h +++ b/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h @@ -5,8 +5,6 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_DocInfo { //文档员数据信息 - -public: QString doc_id; //由32位字符组成的文件标识 QString creation_date; //创建日期 QString mod_date; //修改日期 @@ -21,14 +19,40 @@ public: //ST_Array keywords; //关键词集合 QVector *custom_datas; //每个CustomData元素为2元QStringList,其中[0]为"Name"属性,[1]为值 -public: - CT_DocInfo() { - custom_datas = new QVector(); - } - public: friend class OFDParser; + CT_DocInfo(QString _doc_id = "", + QString _title = "", + QString _author = "", + QString _subject = "", + QString _abstract = "", + QString _creation_date = "", + QString _mod_date = "", + QString _doc_usage = "", + QString _cover = "", + //QString _keywords = "", + QString _creator = "", + QString _creator_version = "", + QVector * _custom_datas = nullptr) { + if (!_doc_id.isNull()) + setDocID(_doc_id); + setTitle(_title); + setAuthor(_author); + setSubject(_subject); + setAbstract(_abstract); + setCreationDate(_creation_date); + setModDate(_mod_date); + setDocUsage(_doc_usage); + setCover(_cover); + setCreator(_creator); + setCreatorVersion(_creator_version); + if (_custom_datas) + setCustomDatas(_custom_datas); + else + custom_datas = new QVector(); + } + ~CT_DocInfo() { delete custom_datas; } @@ -37,66 +61,103 @@ public: return doc_id; } + void setDocID(QString _doc_id) { + if (_doc_id.isNull()) + throw InvalidValueException("Invalid Value in DocID in CT_DocInfo: null pointer"); + doc_id = _doc_id; + } + QString getCreationDate() { return creation_date; } + void setCreationDate(QString _creation_date) { + creation_date = _creation_date; + } + QString getModDate() { return mod_date; } + void setModDate(QString _mod_date) { + mod_date = _mod_date; + } + QString getTitle() { return title; } + void setTitle(QString _title) { + title = _title; + } + QString getAuthor() { return author; } + void setAuthor(QString _author) { + author = _author; + } + QString getSubject() { return subject; } + void setSubject(QString _subject) { + subject = _subject; + } + QString getAbstract() { return abstract; } + void setAbstract(QString _abstract) { + abstract = _abstract; + } + QString getCreator() { return creator; } + void setCreator(QString _creator) { + creator = _creator; + } + QString getCreatorVersion() { return creator_version; } + void setCreatorVersion(QString _creator_version) { + creator_version = _creator_version; + } + QString getDocUsage() { return doc_usage; } + void setDocUsage(QString _doc_usage) { + doc_usage = _doc_usage; + } + ST_Loc getCover() { return cover; } + void setCover(QString _cover_abs) { + ST_Loc i("Cover", _cover_abs); + cover = i; + } + QVector * getCustomDatas() { return custom_datas; } - void copy(const CT_DocInfo & docInfo) - { - this->abstract = docInfo.abstract; - this->author = docInfo.author; - this->cover = docInfo.cover; - this->creation_date = docInfo.creation_date; - this->creator = docInfo.creator; - this->creator_version = docInfo.creator_version; - this->custom_datas = docInfo.custom_datas; - this->doc_id = docInfo.doc_id; - this->doc_usage = docInfo.doc_usage; - this->mod_date = docInfo.mod_date; - this->subject = docInfo.subject; - this->title = docInfo.title; + void setCustomDatas(QVector * _custom_datas) { + if (!_custom_datas) + throw InvalidValueException("Invalid Value in CustomDatas in CT_DocInfo: null pointer"); + delete custom_datas; + custom_datas = _custom_datas; } - }; #endif // CT_DOCINFO_H diff --git a/ofdEditor/ofd/DataTypes/document/DocBody.h b/ofdEditor/ofd/DataTypes/document/DocBody.h index 8e8ac70..5646247 100644 --- a/ofdEditor/ofd/DataTypes/document/DocBody.h +++ b/ofdEditor/ofd/DataTypes/document/DocBody.h @@ -10,23 +10,47 @@ public: CT_DocInfo *doc_info; //文档元数据信息描述 ST_Loc doc_root; //指向文档根节点 ST_Loc signatures; //数字签名 to be implemented - DocBody() { - doc_info = nullptr; - } public: friend class OFDParser; + + DocBody(CT_DocInfo * _doc_info = nullptr, QString _doc_root = "", QString _signatures = "") { + if (_doc_info) + setDocInfo(_doc_info); + if (!_doc_root.isNull()) + setDocRoot(doc_root); + if (!_signatures.isNull()) + setSignatures(_signatures); + } + CT_DocInfo * getDocInfo() { return doc_info; } + void setDocInfo(CT_DocInfo * _doc_info) { + if (!_doc_info) + throw InvalidValueException("Invalid Value in DocInfo in DocBody: null pointer"); + doc_info = _doc_info; + } + + ST_Loc getDocRoot() { return doc_root; } + void setDocRoot(QString _doc_root_abs) { + ST_Loc p("DocRoot", _doc_root_abs); + doc_root = p; + } + ST_Loc getSignatures() { return signatures; } + void setSignatures(QString _signatures_abs) { + ST_Loc p("Signatures", _signatures_abs); + signatures = p; + } + ~DocBody() { delete doc_info; } diff --git a/ofdEditor/ofd/DataTypes/document/Document.h b/ofdEditor/ofd/DataTypes/document/Document.h index 5283c26..008c84d 100644 --- a/ofdEditor/ofd/DataTypes/document/Document.h +++ b/ofdEditor/ofd/DataTypes/document/Document.h @@ -15,25 +15,121 @@ public: ST_Loc custom_tags; //指向自定义标引文件 ST_Loc extensions; //指向拓展文件 ST_Loc annotations; //指向注释文件 - + ID_Table * id_table; //记录所有CT_Base的ID信息 QVector * public_res; CT_Pages *pages; - Document() { - public_res = new QVector(); - common_data = nullptr; - outlines = nullptr; - pages = nullptr; - } public: friend class OFDParser; - CT_CommonData * getCommonData() { return common_data; } - CT_Outlines * getOutLines() { return outlines; } - ST_Loc getCustomTags() { return custom_tags; } - ST_Loc getAnnotations() { return annotations; } - QVector * getPublicRes() { return public_res; } - CT_Pages * getPages() { return pages; } + + Document( CT_CommonData * _common_data = nullptr, + CT_Pages * _pages = nullptr, + CT_Outlines * _outlines = nullptr, + QString _custom_tags = "", + QString _extensions = "", + QString _annotations = "", + QVector * _public_res = nullptr, + ID_Table * _id_table = nullptr + ) { + if (_common_data) + setCommonData(_common_data); + if (_pages) + setPages(_pages); + setOutlines(_outlines); + if (!_custom_tags.isNull()) + setCustomTags(_custom_tags); + if (!_extensions.isNull()) + setExtensions(_extensions); + if (!_annotations.isNull()) + setAnnotations(_annotations); + if (!_public_res) + public_res = new QVector; + else public_res = _public_res; + if (!_id_table) + id_table = new ID_Table; + else id_table = _id_table; + } + + CT_CommonData * getCommonData() { + return common_data; + } + + void setCommonData(CT_CommonData * _common_data) { + if (!_common_data) + throw InvalidValueException("Invalid Value in CommonData in Document: null pointer"); + common_data = _common_data; + } + + CT_Outlines * getOutlines() { + return outlines; + } + + void setOutlines(CT_Outlines * _outlines) { + outlines = _outlines; + } + + ST_Loc getCustomTags() { + return custom_tags; + } + + void setCustomTags(QString _custom_tags_abs) { + ST_Loc p("CustomTags", _custom_tags_abs); + custom_tags = p; + } + + ST_Loc getAnnotations() { + return annotations; + } + + void setAnnotations(QString _annotations_abs) { + ST_Loc p("Annotations", _annotations_abs); + annotations = p; + } + + ST_Loc getExtensions() { + return extensions; + } + + void setExtensions(QString _extensions_abs) { + ST_Loc p("Extensions", _extensions_abs); + extensions = p; + } + + QVector * getPublicRes() { + return public_res; + } + + void setPublicRes(QVector * _public_res) { + if (!_public_res) + throw InvalidValueException("Invalid Value in PublicRes in Document: null pointer"); + for (int i = 0; i < public_res->size(); i++) + delete public_res->at(i); + delete public_res; + public_res = _public_res; + } + + CT_Pages * getPages() { + return pages; + } + + void setPages(CT_Pages * _pages) { + if (!_pages) + throw InvalidValueException("Invalid Value in Pages in Document: null pointer"); + pages = _pages; + } + + ID_Table * getIDTable() { + return id_table; + } + + void setIDTable(ID_Table * _id_table) { + if (!_id_table) + throw InvalidValueException("新建Document对象ID_Table不可为空!!"); + delete id_table; + id_table = _id_table; + } + ~Document() { for (int i = 0; i < public_res->length(); i++) delete public_res->at(i); diff --git a/ofdEditor/ofd/DataTypes/document/OFD.h b/ofdEditor/ofd/DataTypes/document/OFD.h index d462df9..e95b22e 100644 --- a/ofdEditor/ofd/DataTypes/document/OFD.h +++ b/ofdEditor/ofd/DataTypes/document/OFD.h @@ -7,47 +7,98 @@ #include "Document.h" -class OFDSHARED_EXPORT OFD -{ //主入口文件的根元素 -public: +class OFDSHARED_EXPORT OFD { //主入口文件的根元素 //成员 ST_Loc root_path; //ofd.xml的绝对路径,应由应用程序提供 QString version; //版本号 QString doc_type; //文档子集类型 - QVector * docbodys; QVector * docs; //私有方法 - OFD() { - docbodys = new QVector(); - docs = new QVector(); - } - public: friend class OFDParser; + + OFD(QString _root_path = "", + QString _version = "", + QString _doc_type = "", + QVector * _docbodys = nullptr, + QVector * _docs = nullptr + ) { + if (!_root_path.isNull()) + setRootPath(_root_path); + if (!_version.isNull()) + setOfdVersion(_version); + if (!_doc_type.isNull()) + setDocType(_doc_type); + if (!_docbodys) + docbodys = new QVector(); + else + docbodys = _docbodys; + if (!_docs) + docs = new QVector(); + else + docs = _docs; + } + //外部查询数据的接口 QVector * getDocBodies() { return docbodys; } + void setDocBodies(QVector * _docbodys) { + if (!_docbodys) + throw InvalidValueException("Invalid Value in DocBodys in OFD: null pointer"); + for (int i = 0; i < docbodys->size(); i++) + delete docbodys->at(i); + delete docbodys; + docbodys = _docbodys; + } + ST_Loc getRootPath() { return root_path; } + void setRootPath(QString _root_path_abs) { + ST_Loc p("RootPath", _root_path_abs); + root_path = p; + } + QVector * getDocuments() { return docs; } + void setDocument(QVector * _docs) { + if (!docs) + throw InvalidValueException("Invalid Value in Documents in OFD: null pointer"); + for (int i = 0; i < docs->size(); i++) + delete docs->at(i); + delete docs; + docs = _docs; + } + QString getOfdVersion() { return version; } + void setOfdVersion(QString _version) { + if (_version.isNull()) + throw InvalidValueException("Invalid Value in Version in OFD: null"); + version = _version; + } + QString getDocType() { return doc_type; } + void setDocType(QString _doc_type) { + if (_doc_type.isNull()) + throw InvalidValueException("Invalid Value in DocType in OFD: null"); + doc_type = _doc_type; + } + + ~OFD() { for (int i = 0; i < docbodys->length(); i++) delete docbodys->at(i); diff --git a/ofdEditor/ofd/DataTypes/document/ct_commondata.h b/ofdEditor/ofd/DataTypes/document/ct_commondata.h index 2b731eb..af90a1b 100644 --- a/ofdEditor/ofd/DataTypes/document/ct_commondata.h +++ b/ofdEditor/ofd/DataTypes/document/ct_commondata.h @@ -11,16 +11,58 @@ public: QVector *public_res; //公共资源序列,每个资源指向OFD包内部的一个XML文件 //vector template_page; //模板页序列 ST_RefID default_cs; //缺省颜色空间 +public: + friend class OFDParser; + CT_CommonData() { public_res = new QVector(); page_area = nullptr; } -public: - friend class OFDParser; - ST_ID getMaxUnitID() { return max_unit_id; } - CT_PageArea *getPageArea() { return page_area; } - QVector *getPublicRes() { return public_res; } - ST_RefID getDefaultCS() { return default_cs; } + + ST_ID getMaxUnitID() { + return max_unit_id; + } + + void setMaxUnitID(int _max_unit_id) { + if (_max_unit_id < 0) + throw InvalidValueException("Invalid Value in MaxUnitID in CT_CommonData: " + QString::number(_max_unit_id)); + ST_ID i(_max_unit_id); + max_unit_id = i; + } + + CT_PageArea *getPageArea() { + return page_area; + } + + void setPageArea(CT_PageArea * _page_area) { + if (!_page_area) + throw InvalidValueException("Invalid Value in PageArea in CT_CommonData: null pointer"); + delete page_area; + page_area = _page_area; + } + + QVector *getPublicRes() { + return public_res; + } + + void setPublicRes(QVector * _public_res) { + if (!_public_res) + throw InvalidValueException("Invalid Value in PublicRes in CT_CommonData: null pointer"); + delete public_res; + public_res = _public_res; + } + + ST_RefID getDefaultCS() { + return default_cs; + } + + void setDefaultCS(int _default_cs, ID_Table * id_table) { + if (!id_table->contains(_default_cs)) + throw InvalidIDException("Unregistered ID in DefaultCS in CT_CommonData: " + QString::number(_default_cs)); + ST_RefID ri(_default_cs); + default_cs = ri; + } + ~CT_CommonData() { delete public_res; delete page_area; diff --git a/ofdEditor/ofd/DataTypes/document/ct_docinfo.h b/ofdEditor/ofd/DataTypes/document/ct_docinfo.h index c76bf61..ba75f78 100644 --- a/ofdEditor/ofd/DataTypes/document/ct_docinfo.h +++ b/ofdEditor/ofd/DataTypes/document/ct_docinfo.h @@ -5,8 +5,6 @@ #include "../../ofd_global.h" // 生成库文件需要 class OFDSHARED_EXPORT CT_DocInfo { //文档员数据信息 - -public: QString doc_id; //由32位字符组成的文件标识 QString creation_date; //创建日期 QString mod_date; //修改日期 @@ -21,14 +19,40 @@ public: //ST_Array keywords; //关键词集合 QVector *custom_datas; //每个CustomData元素为2元QStringList,其中[0]为"Name"属性,[1]为值 -public: - CT_DocInfo() { - custom_datas = new QVector(); - } - public: friend class OFDParser; + CT_DocInfo(QString _doc_id = "", + QString _title = "", + QString _author = "", + QString _subject = "", + QString _abstract = "", + QString _creation_date = "", + QString _mod_date = "", + QString _doc_usage = "", + QString _cover = "", + //QString _keywords = "", + QString _creator = "", + QString _creator_version = "", + QVector * _custom_datas = nullptr) { + if (!_doc_id.isNull()) + setDocID(_doc_id); + setTitle(_title); + setAuthor(_author); + setSubject(_subject); + setAbstract(_abstract); + setCreationDate(_creation_date); + setModDate(_mod_date); + setDocUsage(_doc_usage); + setCover(_cover); + setCreator(_creator); + setCreatorVersion(_creator_version); + if (_custom_datas) + setCustomDatas(_custom_datas); + else + custom_datas = new QVector(); + } + ~CT_DocInfo() { delete custom_datas; } @@ -37,66 +61,103 @@ public: return doc_id; } + void setDocID(QString _doc_id) { + if (_doc_id.isNull()) + throw InvalidValueException("Invalid Value in DocID in CT_DocInfo: null pointer"); + doc_id = _doc_id; + } + QString getCreationDate() { return creation_date; } + void setCreationDate(QString _creation_date) { + creation_date = _creation_date; + } + QString getModDate() { return mod_date; } + void setModDate(QString _mod_date) { + mod_date = _mod_date; + } + QString getTitle() { return title; } + void setTitle(QString _title) { + title = _title; + } + QString getAuthor() { return author; } + void setAuthor(QString _author) { + author = _author; + } + QString getSubject() { return subject; } + void setSubject(QString _subject) { + subject = _subject; + } + QString getAbstract() { return abstract; } + void setAbstract(QString _abstract) { + abstract = _abstract; + } + QString getCreator() { return creator; } + void setCreator(QString _creator) { + creator = _creator; + } + QString getCreatorVersion() { return creator_version; } + void setCreatorVersion(QString _creator_version) { + creator_version = _creator_version; + } + QString getDocUsage() { return doc_usage; } + void setDocUsage(QString _doc_usage) { + doc_usage = _doc_usage; + } + ST_Loc getCover() { return cover; } + void setCover(QString _cover_abs) { + ST_Loc i("Cover", _cover_abs); + cover = i; + } + QVector * getCustomDatas() { return custom_datas; } - void copy(const CT_DocInfo & docInfo) - { - this->abstract = docInfo.abstract; - this->author = docInfo.author; - this->cover = docInfo.cover; - this->creation_date = docInfo.creation_date; - this->creator = docInfo.creator; - this->creator_version = docInfo.creator_version; - this->custom_datas = docInfo.custom_datas; - this->doc_id = docInfo.doc_id; - this->doc_usage = docInfo.doc_usage; - this->mod_date = docInfo.mod_date; - this->subject = docInfo.subject; - this->title = docInfo.title; + void setCustomDatas(QVector * _custom_datas) { + if (!_custom_datas) + throw InvalidValueException("Invalid Value in CustomDatas in CT_DocInfo: null pointer"); + delete custom_datas; + custom_datas = _custom_datas; } - }; #endif // CT_DOCINFO_H diff --git a/ofdEditor/ofd/DataTypes/document/docbody.h b/ofdEditor/ofd/DataTypes/document/docbody.h index 8e8ac70..5646247 100644 --- a/ofdEditor/ofd/DataTypes/document/docbody.h +++ b/ofdEditor/ofd/DataTypes/document/docbody.h @@ -10,23 +10,47 @@ public: CT_DocInfo *doc_info; //文档元数据信息描述 ST_Loc doc_root; //指向文档根节点 ST_Loc signatures; //数字签名 to be implemented - DocBody() { - doc_info = nullptr; - } public: friend class OFDParser; + + DocBody(CT_DocInfo * _doc_info = nullptr, QString _doc_root = "", QString _signatures = "") { + if (_doc_info) + setDocInfo(_doc_info); + if (!_doc_root.isNull()) + setDocRoot(doc_root); + if (!_signatures.isNull()) + setSignatures(_signatures); + } + CT_DocInfo * getDocInfo() { return doc_info; } + void setDocInfo(CT_DocInfo * _doc_info) { + if (!_doc_info) + throw InvalidValueException("Invalid Value in DocInfo in DocBody: null pointer"); + doc_info = _doc_info; + } + + ST_Loc getDocRoot() { return doc_root; } + void setDocRoot(QString _doc_root_abs) { + ST_Loc p("DocRoot", _doc_root_abs); + doc_root = p; + } + ST_Loc getSignatures() { return signatures; } + void setSignatures(QString _signatures_abs) { + ST_Loc p("Signatures", _signatures_abs); + signatures = p; + } + ~DocBody() { delete doc_info; } diff --git a/ofdEditor/ofd/DataTypes/document/document.h b/ofdEditor/ofd/DataTypes/document/document.h index 5283c26..008c84d 100644 --- a/ofdEditor/ofd/DataTypes/document/document.h +++ b/ofdEditor/ofd/DataTypes/document/document.h @@ -15,25 +15,121 @@ public: ST_Loc custom_tags; //指向自定义标引文件 ST_Loc extensions; //指向拓展文件 ST_Loc annotations; //指向注释文件 - + ID_Table * id_table; //记录所有CT_Base的ID信息 QVector * public_res; CT_Pages *pages; - Document() { - public_res = new QVector(); - common_data = nullptr; - outlines = nullptr; - pages = nullptr; - } public: friend class OFDParser; - CT_CommonData * getCommonData() { return common_data; } - CT_Outlines * getOutLines() { return outlines; } - ST_Loc getCustomTags() { return custom_tags; } - ST_Loc getAnnotations() { return annotations; } - QVector * getPublicRes() { return public_res; } - CT_Pages * getPages() { return pages; } + + Document( CT_CommonData * _common_data = nullptr, + CT_Pages * _pages = nullptr, + CT_Outlines * _outlines = nullptr, + QString _custom_tags = "", + QString _extensions = "", + QString _annotations = "", + QVector * _public_res = nullptr, + ID_Table * _id_table = nullptr + ) { + if (_common_data) + setCommonData(_common_data); + if (_pages) + setPages(_pages); + setOutlines(_outlines); + if (!_custom_tags.isNull()) + setCustomTags(_custom_tags); + if (!_extensions.isNull()) + setExtensions(_extensions); + if (!_annotations.isNull()) + setAnnotations(_annotations); + if (!_public_res) + public_res = new QVector; + else public_res = _public_res; + if (!_id_table) + id_table = new ID_Table; + else id_table = _id_table; + } + + CT_CommonData * getCommonData() { + return common_data; + } + + void setCommonData(CT_CommonData * _common_data) { + if (!_common_data) + throw InvalidValueException("Invalid Value in CommonData in Document: null pointer"); + common_data = _common_data; + } + + CT_Outlines * getOutlines() { + return outlines; + } + + void setOutlines(CT_Outlines * _outlines) { + outlines = _outlines; + } + + ST_Loc getCustomTags() { + return custom_tags; + } + + void setCustomTags(QString _custom_tags_abs) { + ST_Loc p("CustomTags", _custom_tags_abs); + custom_tags = p; + } + + ST_Loc getAnnotations() { + return annotations; + } + + void setAnnotations(QString _annotations_abs) { + ST_Loc p("Annotations", _annotations_abs); + annotations = p; + } + + ST_Loc getExtensions() { + return extensions; + } + + void setExtensions(QString _extensions_abs) { + ST_Loc p("Extensions", _extensions_abs); + extensions = p; + } + + QVector * getPublicRes() { + return public_res; + } + + void setPublicRes(QVector * _public_res) { + if (!_public_res) + throw InvalidValueException("Invalid Value in PublicRes in Document: null pointer"); + for (int i = 0; i < public_res->size(); i++) + delete public_res->at(i); + delete public_res; + public_res = _public_res; + } + + CT_Pages * getPages() { + return pages; + } + + void setPages(CT_Pages * _pages) { + if (!_pages) + throw InvalidValueException("Invalid Value in Pages in Document: null pointer"); + pages = _pages; + } + + ID_Table * getIDTable() { + return id_table; + } + + void setIDTable(ID_Table * _id_table) { + if (!_id_table) + throw InvalidValueException("新建Document对象ID_Table不可为空!!"); + delete id_table; + id_table = _id_table; + } + ~Document() { for (int i = 0; i < public_res->length(); i++) delete public_res->at(i); diff --git a/ofdEditor/ofd/DataTypes/document/ofd.h b/ofdEditor/ofd/DataTypes/document/ofd.h index d462df9..e95b22e 100644 --- a/ofdEditor/ofd/DataTypes/document/ofd.h +++ b/ofdEditor/ofd/DataTypes/document/ofd.h @@ -7,47 +7,98 @@ #include "Document.h" -class OFDSHARED_EXPORT OFD -{ //主入口文件的根元素 -public: +class OFDSHARED_EXPORT OFD { //主入口文件的根元素 //成员 ST_Loc root_path; //ofd.xml的绝对路径,应由应用程序提供 QString version; //版本号 QString doc_type; //文档子集类型 - QVector * docbodys; QVector * docs; //私有方法 - OFD() { - docbodys = new QVector(); - docs = new QVector(); - } - public: friend class OFDParser; + + OFD(QString _root_path = "", + QString _version = "", + QString _doc_type = "", + QVector * _docbodys = nullptr, + QVector * _docs = nullptr + ) { + if (!_root_path.isNull()) + setRootPath(_root_path); + if (!_version.isNull()) + setOfdVersion(_version); + if (!_doc_type.isNull()) + setDocType(_doc_type); + if (!_docbodys) + docbodys = new QVector(); + else + docbodys = _docbodys; + if (!_docs) + docs = new QVector(); + else + docs = _docs; + } + //外部查询数据的接口 QVector * getDocBodies() { return docbodys; } + void setDocBodies(QVector * _docbodys) { + if (!_docbodys) + throw InvalidValueException("Invalid Value in DocBodys in OFD: null pointer"); + for (int i = 0; i < docbodys->size(); i++) + delete docbodys->at(i); + delete docbodys; + docbodys = _docbodys; + } + ST_Loc getRootPath() { return root_path; } + void setRootPath(QString _root_path_abs) { + ST_Loc p("RootPath", _root_path_abs); + root_path = p; + } + QVector * getDocuments() { return docs; } + void setDocument(QVector * _docs) { + if (!docs) + throw InvalidValueException("Invalid Value in Documents in OFD: null pointer"); + for (int i = 0; i < docs->size(); i++) + delete docs->at(i); + delete docs; + docs = _docs; + } + QString getOfdVersion() { return version; } + void setOfdVersion(QString _version) { + if (_version.isNull()) + throw InvalidValueException("Invalid Value in Version in OFD: null"); + version = _version; + } + QString getDocType() { return doc_type; } + void setDocType(QString _doc_type) { + if (_doc_type.isNull()) + throw InvalidValueException("Invalid Value in DocType in OFD: null"); + doc_type = _doc_type; + } + + ~OFD() { for (int i = 0; i < docbodys->length(); i++) delete docbodys->at(i); diff --git a/ofdEditor/ofd/DataTypes/document/res.h b/ofdEditor/ofd/DataTypes/document/res.h index e47a5f7..5d74adf 100644 --- a/ofdEditor/ofd/DataTypes/document/res.h +++ b/ofdEditor/ofd/DataTypes/document/res.h @@ -15,29 +15,77 @@ class OFDSHARED_EXPORT Res { QVector * draw_params; //Other resource collections to be implemented - Res() { - fonts = new QVector(); - colorspaces = new QVector(); - draw_params = new QVector(); - } public: friend class OFDParser; + + Res(QString _base_loc = "", + QVector * _fonts = nullptr, + QVector * _colorspaces = nullptr, + QVector * _draw_params = nullptr) { + if (!_base_loc.isNull()) + setBaseLoc(_base_loc); + if (!_fonts) + fonts = new QVector(); + else + fonts = _fonts; + if (!_colorspaces) + colorspaces = new QVector(); + else + colorspaces = _colorspaces; + if (!_draw_params) + draw_params = new QVector(); + else + draw_params = _draw_params; + } + ST_Loc getBaseLoc() { return base_loc; } + void setBaseLoc(QString _base_loc_abs) { + ST_Loc p("Resource", _base_loc_abs); + base_loc = p; + } + QVector * getFonts() { return fonts; } + void setFonts(QVector * _fonts) { + if (!_fonts) + throw InvalidValueException("Invalid value in Fonts in Res: null pointer"); + for (int i = 0; i < fonts->size(); i++) + delete fonts->at(i); + delete fonts; + fonts = _fonts; + } + QVector * getColorSpaces() { return colorspaces; } + void setColorSpaces(QVector * _colorspaces) { + if (!_colorspaces) + throw InvalidValueException("Invalid value in ColorSpaces in Res: null pointer"); + for (int i = 0; i < colorspaces->size(); i++) + delete colorspaces->at(i); + delete colorspaces; + colorspaces = _colorspaces; + } + QVector * getDrawParams() { return draw_params; } + void setDrawParams(QVector * _draw_params) { + if (!_draw_params) + throw InvalidValueException("Invalid value in DrawParams in Res: null pointer"); + for (int i = 0; i < draw_params->size(); i++) + delete draw_params->at(i); + delete draw_params; + draw_params = _draw_params; + } + ~Res() { for (int i = 0; i < fonts->size(); i++) delete fonts->at(i); diff --git a/ofdEditor/ofd/DataTypes/image/CT_DrawParam.h b/ofdEditor/ofd/DataTypes/image/CT_DrawParam.h index 2a93057..7deebac 100644 --- a/ofdEditor/ofd/DataTypes/image/CT_DrawParam.h +++ b/ofdEditor/ofd/DataTypes/image/CT_DrawParam.h @@ -20,17 +20,39 @@ class OFDSHARED_EXPORT CT_Color { // CT_RadialShd* radial_shd; // 径向渐变 int shd_selected; // 0表示选择轴向,1表示选择径向,默认值-1 - CT_Color() { - alpha = 255; - index_used = false; - } +// CT_Color() { +// alpha = 255; +// index_used = false; +// } public: friend class OFDParser; friend class CT_DrawParam; + + CT_Color(QString _value = "", + int _index = 0, + int _color_space = 0, + ID_Table * _id_table = nullptr, + int _alpha = 255) { + if (!_value.isNull()) + setValue(_value); + if (_index) + setIndex(_index); + else + index_used = false; + if (_color_space && _id_table) + setColorSpace(_color_space, _id_table); + setAlpha(_alpha); + } + ST_Array getValue() { return value; } + void setValue(QString _value) { + ST_Array a("Value", _value); + value = a; + } + bool indexUsed() { return index_used; } @@ -39,22 +61,36 @@ public: if (index_used) return index; else { - //Error! Try to access unused data - abort(); + throw IllegalAccessException("Try to access uninitialized value Index in CT_Color"); } } + void setIndex(int _index) { + if (_index < 0) + throw InvalidValueException("Try to assign a negative value to Index in CT_Color"); + index = _index; + index_used = true; + } + ST_RefID getColorSpace() { return color_space; } + void setColorSpace(int _color_space, ID_Table * id_table) { + if (!id_table->contains(_color_space)) + throw InvalidIDException("CT_Color的ColorSpace属性引用了未被注册的ID: " + QString::number(_color_space)); + ST_RefID ri(_color_space); + color_space = ri; + } + int getAlpha() { - if (alpha >= 0 && alpha < 256) - return alpha; - else { - //Error! Illegal value - abort(); - } + return alpha; + } + + void setAlpha(int _alpha) { + if (_alpha < 0 || _alpha > 255) + throw InvalidValueException("CT_Color的Alpha属性使用了无效的属性值: " + QString::number(_alpha)); + alpha = _alpha; } }; // 图元绘制参数属性 @@ -81,55 +117,147 @@ class OFDSHARED_EXPORT CT_DrawParam : public CT_Base { CT_Color* stroke_color; // 描边颜色 -默认为黑色 - 可选 bool stroke_color_used; - CT_DrawParam() { - fill_color = nullptr; - stroke_color = nullptr; - line_width = 0.353; - join = "Miter"; - cap = "Butt"; - dash_offset = 0; - miter_limit = 3.528; - fill_color = new CT_Color(); - stroke_color = new CT_Color(); - fill_color->alpha = 0; - ST_Array c1("FillColor", "0 0 0"); - ST_Array c2("StrokeColor", "0 0 0"); - fill_color->value = c1; - stroke_color->value = c2; - fill_color_used = false; - stroke_color_used = true; - } +// CT_DrawParam() { +// line_width = 0.353; +// join = "Miter"; +// cap = "Butt"; +// dash_offset = 0; +// miter_limit = 3.528; +// fill_color = new CT_Color(); +// stroke_color = new CT_Color(); +// fill_color->alpha = 0; +// ST_Array c1("FillColor", "0 0 0"); +// ST_Array c2("StrokeColor", "0 0 0"); +// fill_color->value = c1; +// stroke_color->value = c2; +// fill_color_used = false; +// stroke_color_used = true; +// } public: friend class OFDParser; + + CT_DrawParam(int _relative = 0, + ID_Table * _id_table = nullptr, + double _line_width = 0.353, + QString _join = "Miter", + QString _cap = "Butt", + double _miter_limit = 3.528, + double _dash_offset = 0, + QString _dash_pattern = "", + CT_Color * _fill_color = nullptr, + CT_Color * _stroke_color = nullptr + ) { + if (_relative && _id_table) + setRelative(_relative, _id_table); + setLineWidth(_line_width); + setJoin(_join); + setCap(_cap); + setMiterLimit(_miter_limit); + setDashOffset(_dash_offset); + setDashPattern(_dash_pattern); + if (!_fill_color) { + fill_color_used = false; + fill_color = new CT_Color(); + ST_Array c1("FillColor", "0 0 0"); + fill_color->value = c1; + } else { + fill_color = _fill_color; + fill_color_used = true; + } + if (!_stroke_color) { + stroke_color_used = false; + stroke_color = new CT_Color(); + ST_Array c1("StrokeColor", "0 0 0"); + stroke_color->value = c1; + } else { + stroke_color = _stroke_color; + stroke_color_used = true; + } + } + ST_RefID getRelative() { return relative; } + void setRelative(int _relative, ID_Table * _id_table) { + if (!_id_table->contains(_relative)) + throw InvalidIDException("CT_DrawParam对象的Relative属性引用了尚未注册的ID: " + QString::number(_relative)); + ST_RefID ri(_relative); + relative = ri; + } + double getLineWidth() { return line_width; } + void setLineWidth(double _line_width) { + if (_line_width < 0) + throw InvalidValueException("CT_DrawParam对象的LineWidth属性使用了非法的值: " + QString::number(_line_width)); + line_width = _line_width; + } + QString getJoin() { return join; } + void setJoin(QString _join) { + QStringList possible_values; + possible_values.append("Miter"); + possible_values.append("Round"); + possible_values.append("Bevel"); + if (possible_values.contains(_join)) + join = _join; + else + throw InvalidValueException("CT_DrawParam对象的Join属性使用了非法的值: " + _join); + } + QString getCap() { return cap; } + void setCap(QString _cap) { + QStringList possible_values; + possible_values.append("Butt"); + possible_values.append("Round"); + possible_values.append("Square"); + if (possible_values.contains(_cap)) + cap = _cap; + else + throw InvalidValueException("CT_DrawParam对象的Cap属性使用了非法的值: " + _cap); + } + double getDashOffset() { return dash_offset; } + void setDashOffset(double _dash_offset) { + if (dash_pattern.isNull()) + throw InvalidValueException("CT_DrawParam对象的DashOffset属性,在DashPattern未出现时设置"); + dash_offset = _dash_offset; + } + ST_Array getDashPattern() { return dash_pattern; } + void setDashPattern(QString _dash_pattern) { + if (!_dash_pattern.isNull()) { + ST_Array a("DashPattern", _dash_pattern); + dash_pattern = a; + } + } + double getMiterLimit() { return miter_limit; } + void setMiterLimit(double _miter_limit) { + if (join != "Miter") + throw InvalidValueException("Try to set MiterLimit in CT_DrawParam, when its Join is not Miter"); + miter_limit = _miter_limit; + } + bool fillColorUsed() { return fill_color_used; } @@ -138,6 +266,14 @@ public: return fill_color; } + void setFillColor(CT_Color * _fill_color) { + if (_fill_color) { + fill_color_used = true; + delete fill_color; + fill_color = _fill_color; + } + } + bool strokeColorUsed() { return stroke_color_used; } @@ -146,6 +282,14 @@ public: return stroke_color; } + void setStrokeColor(CT_Color * _stroke_color) { + if (_stroke_color) { + stroke_color_used = true; + delete stroke_color; + stroke_color = _stroke_color; + } + } + ~CT_DrawParam() { delete fill_color; delete stroke_color; diff --git a/ofdEditor/ofd/DataTypes/image/CT_GraphicUnit.h b/ofdEditor/ofd/DataTypes/image/CT_GraphicUnit.h index 40435a1..c22a7ca 100644 --- a/ofdEditor/ofd/DataTypes/image/CT_GraphicUnit.h +++ b/ofdEditor/ofd/DataTypes/image/CT_GraphicUnit.h @@ -36,41 +36,179 @@ public: // CT_Actions Actions; // 图元对象附带的动作序列。 // QVector * clips; // 图元对象的裁剪区 - CT_GraphicUnit() { - visible = true; - fill_color = nullptr; - stroke_color = nullptr; - } + public: friend class OFDParser; + + CT_GraphicUnit(double _start_x = 0, + double _start_y = 0, + double _delta_x = 0, + double _delta_y = 0, + QString _name = "", + bool _visible = true, + int _draw_param = 0, + ID_Table * _id_table = nullptr, + double _line_width = 0.353, + QString _cap = "Butt", + QString _join = "Miter", + double _miter_limit = 3.528, + double _dash_offset = 0.0, + QString _dash_pattern = "", + int _alpha = 255, + CT_Color * _fill_color = nullptr, + CT_Color * _stroke_color = nullptr + ) { + if (_start_x || _start_y || _delta_x || _delta_y) + setBoundary(_start_x, _start_y, _delta_x, _delta_y); + setName(_name); + setVisible(_visible); + if (_draw_param && _id_table) + setDrawParam(_draw_param, _id_table); + setLineWidth(_line_width); + setCap(_cap); + setJoin(_join); + setMiterLimit(_miter_limit); + dash_offset = _dash_offset; + setDashPattern(_dash_pattern); + setAlpha(_alpha); + setFillColor(_fill_color); + setStrokeColor(_stroke_color); + } + ST_Box getBoundary() { return boundary; } + void setBoundary(double _start_x, double _start_y, double _delta_x, double _delta_y) { + ST_Box b(_start_x, _start_y, _delta_x, _delta_y); + boundary = b; + } + QString getName() { return name; } + void setName(QString _name) { + name = _name; + } + bool getVisible() { return visible; } + void setVisible(bool _visible) { + visible = _visible; + } + ST_RefID getDrawParam() { return draw_param; } + void setDrawParam(int _draw_param, ID_Table * _id_table) { + if (!_id_table->contains(_draw_param)) + throw InvalidIDException("CT_GraphicUnit对象中的DrawParam属性引用了未注册的ID: " + QString::number(_draw_param)); + ST_RefID rd(_draw_param); + draw_param = rd; + } + double getLineWidth() { return line_width; } + void setLineWidth(double _line_width) { + line_width = _line_width; + } + QString getJoin() { + return join; + } + + void setJoin(QString _join) { + QStringList possible_values; + possible_values.append("Miter"); + possible_values.append("Round"); + possible_values.append("Bevel"); + if (possible_values.contains(_join)) + join = _join; + else + throw InvalidValueException("CT_GraphicUnit对象的Join属性使用了非法的值: " + _join); + } + + QString getCap() { + return cap; + } + + void setCap(QString _cap) { + QStringList possible_values; + possible_values.append("Butt"); + possible_values.append("Round"); + possible_values.append("Square"); + if (possible_values.contains(_cap)) + cap = _cap; + else + throw InvalidValueException("CT_GraphicUnit对象的Cap属性使用了非法的值: " + _cap); + } + + double getDashOffset() { + return dash_offset; + } + + void setDashOffset(double _dash_offset) { + if (dash_pattern.isNull()) + throw InvalidValueException("CT_GraphicUnit对象的DashOffset属性,在DashPattern未出现时设置"); + dash_offset = _dash_offset; + } + + ST_Array getDashPattern() { + return dash_pattern; + } + + void setDashPattern(QString _dash_pattern) { + ST_Array a("DashPattern", _dash_pattern); + dash_pattern = a; + } + + double getMiterLimit() { + return miter_limit; + } + + void setMiterLimit(double _miter_limit) { + if (join != "Miter") + throw InvalidValueException("Try to set set MiterLimit in CT_GraphicUnit, when its Join is not Miter"); + miter_limit = _miter_limit; + } + + int getAlpha() { + return alpha; + } + + void setAlpha(int _alpha) { + if (_alpha < 0 || _alpha > 255) + throw InvalidValueException("CT_GraphicUnit的Alpha属性使用了无效的属性值: " + QString::number(_alpha)); + alpha = _alpha; + } + CT_Color * getFillColor() { return fill_color; } + void setFillColor(CT_Color * _fill_color) { + if (_fill_color) { + delete fill_color; + fill_color = _fill_color; + } + } + CT_Color * getStrokeColor() { return stroke_color; } + void setStrokeColor(CT_Color * _stroke_color) { + if (_stroke_color) { + delete stroke_color; + stroke_color = _stroke_color; + } + } + ~CT_GraphicUnit() { delete fill_color; delete stroke_color; diff --git a/ofdEditor/ofd/DataTypes/image/CT_Image.h b/ofdEditor/ofd/DataTypes/image/CT_Image.h index 260a2a4..63c454c 100644 --- a/ofdEditor/ofd/DataTypes/image/CT_Image.h +++ b/ofdEditor/ofd/DataTypes/image/CT_Image.h @@ -13,15 +13,39 @@ class OFDSHARED_EXPORT CT_Image : public CT_GraphicUnit ST_RefID substitution; // (可选)指定可替换图像, // 用于某些情况如高分辨率输出时进行图像替换。 - CT_Image() {} public: friend class OFDParser; + + CT_Image(int _resource_id = 0, + ID_Table * _id_table = nullptr, + int _substitution = 0) { + if (_resource_id && _id_table) + setResourceID(_resource_id, _id_table); + if (_substitution) + setSubstitution(_substitution, _id_table); + } + ST_RefID getResourceID() { return resource_id; } + + void setResourceID(int _resource_id, ID_Table * _id_table) { + if (!_id_table->contains(_resource_id)) + throw InvalidIDException("CT_Image对象的ResourceID属性引用了未注册的ID: " + QString::number(_resource_id)); + ST_RefID ri(_resource_id); + resource_id = ri; + } + ST_RefID getSubstitution() { return substitution; } + + void setSubstitution(int _substitution, ID_Table * _id_table) { + if (!_id_table->contains(_substitution)) + throw InvalidIDException("CT_Image对象的Substitution属性引用了未注册的ID: " + QString::number(_substitution)); + ST_RefID ri(_substitution); + substitution = ri; + } }; #endif // CT_IMAGE_H diff --git a/ofdEditor/ofd/DataTypes/image/CT_Path.h b/ofdEditor/ofd/DataTypes/image/CT_Path.h index abd8f9a..a746507 100644 --- a/ofdEditor/ofd/DataTypes/image/CT_Path.h +++ b/ofdEditor/ofd/DataTypes/image/CT_Path.h @@ -17,26 +17,60 @@ class OFDSHARED_EXPORT CT_Path : public CT_GraphicUnit //成员 QString abbreviated_data; // 定义了一种路径元素描述序列, // 由一系列紧缩的操作符和操作数构成。使用对象相对坐标系。 - CT_Path() { - stroke = true; - fill = false; - rule = "NonZero"; - } public: friend class OFDParser; + + CT_Path(QString _abbreviated_data = "", + bool _stroke = true, + bool _fill = true, + QString _rule = "NonZero") { + if (!_abbreviated_data.isNull()) + setAbbreviatedData(_abbreviated_data); + setFill(_fill); + setStroke(_stroke); + setRule(_rule); + } + bool getStroke() { return stroke; } + + void setStroke(bool _stroke) { + stroke = _stroke; + } + bool getFill() { return fill; } + + void setFill(bool _fill) { + fill = _fill; + } + QString getRule() { return rule; } + + void setRule(QString _rule) { + QStringList possible_values; + possible_values.append("NonZero"); + possible_values.append("Even-Odd"); + + if (!possible_values.contains(_rule)) + throw InvalidValueException("CT_Path对象的Rule属性使用了非法值: " + _rule); + rule = _rule; + } + QString getAbbreviatedData() { return abbreviated_data; } + + void setAbbreviatedData(QString _abbreviated_data) { + if (_abbreviated_data.isNull()) + throw InvalidValueException("Invalid value in AbbreviatedData in CT_Path: null pointer"); + abbreviated_data = _abbreviated_data; + } }; #endif // CT_PATH_H diff --git a/ofdEditor/ofd/DataTypes/page/CT_Layer.h b/ofdEditor/ofd/DataTypes/page/CT_Layer.h index 9340b19..20cf862 100644 --- a/ofdEditor/ofd/DataTypes/page/CT_Layer.h +++ b/ofdEditor/ofd/DataTypes/page/CT_Layer.h @@ -5,33 +5,48 @@ #include "../../ofd_global.h" // 生成库文件需要 -class OFDSHARED_EXPORT CT_Layer - : public CT_PageBlock -{ +class OFDSHARED_EXPORT CT_Layer : public CT_PageBlock { public: friend class OFDParser; - enum LayerType {Body = 1, Foreground, Background}; + + CT_Layer(QString _type = "Body", + int _draw_param = 0, + ID_Table * _id_table = nullptr) { + setType(_type); + if (_draw_param && _id_table) + setDrawParam(_draw_param, _id_table); + } + QString getType() { - switch (type) { - case Body: - return "Body"; - case Foreground: - return "Foreground"; - case Background: - return "Background"; - } + return type; + } + + void setType(QString _type) { + QStringList possible_values; + possible_values.append("Body"); + possible_values.append("Foreground"); + possible_values.append("Background"); + + if (possible_values.contains(_type)) + type = _type; + else throw InvalidValueException("CT_Layer对象中的Type属性使用了非法值: " + _type); } + ST_RefID getDrawParam() { return draw_param; } + void setDrawParam(int _draw_param, ID_Table * _id_table) { + if (!_id_table->contains(_draw_param)) + throw InvalidIDException("CT_Layer对象中的DrawParam属性引用了未注册的ID: " + QString::number(_draw_param)); + ST_RefID rd(_draw_param); + draw_param = rd; + } + //从CT_PageBlock继承了几个接口 -public: - LayerType type; +private: + QString type; ST_RefID draw_param; - CT_Layer() : CT_PageBlock(){ - type = Body; - } }; #endif // CT_LAYER_H diff --git a/ofdEditor/ofd/DataTypes/page/CT_PageArea.h b/ofdEditor/ofd/DataTypes/page/CT_PageArea.h index d94a15e..377422d 100644 --- a/ofdEditor/ofd/DataTypes/page/CT_PageArea.h +++ b/ofdEditor/ofd/DataTypes/page/CT_PageArea.h @@ -22,10 +22,41 @@ public: public: friend class OFDParser; CT_PageArea(){} - ST_Box getPhysicalBox() { return physical_box; } - ST_Box getApplicationBox() { return application_box; } - ST_Box getContentBox() { return content_box; } - ST_Box getBleedBox() { return bleed_box; } + ST_Box getPhysicalBox() { + return physical_box; + } + + void setPhysicalBox(double _start_x, double _start_y, double _delta_x, double _delta_y) { + ST_Box b(_start_x, _start_y, _delta_x, _delta_y); + physical_box = b; + } + + ST_Box getApplicationBox() { + return application_box; + } + + void setApplicationBox(double _start_x, double _start_y, double _delta_x, double _delta_y) { + ST_Box b(_start_x, _start_y, _delta_x, _delta_y); + application_box = b; + } + + ST_Box getContentBox() { + return content_box; + } + + void setContentBox(double _start_x, double _start_y, double _delta_x, double _delta_y) { + ST_Box b(_start_x, _start_y, _delta_x, _delta_y); + content_box = b; + } + + ST_Box getBleedBox() { + return bleed_box; + } + + void setBleedBox(double _start_x, double _start_y, double _delta_x, double _delta_y) { + ST_Box b(_start_x, _start_y, _delta_x, _delta_y); + bleed_box = b; + } }; #endif // CT_PAGEAREA_H diff --git a/ofdEditor/ofd/DataTypes/page/CT_PageBlock.h b/ofdEditor/ofd/DataTypes/page/CT_PageBlock.h index baa2040..52543ca 100644 --- a/ofdEditor/ofd/DataTypes/page/CT_PageBlock.h +++ b/ofdEditor/ofd/DataTypes/page/CT_PageBlock.h @@ -13,26 +13,76 @@ public: QVector * path_object; QVector * image_object; QVector * pageblock; +public: + friend class OFDParser; + CT_PageBlock() { text_object = new QVector(); path_object = new QVector(); image_object = new QVector(); pageblock = new QVector(); } -public: - friend class OFDParser; + QVector * getTextObject() { return text_object; } + + void setTextObject(QVector * _text_object) { + if (_text_object) { + for (int i = 0; i < text_object->size(); i++) + delete text_object->at(i); + delete text_object; + text_object = _text_object; + } + else + throw InvalidValueException("Invalid value in TextObject in CT_PageBlock: null pointer"); + } + QVector * getPathObject() { return path_object; } + + void setPathObject(QVector * _path_object) { + if (_path_object) { + for (int i = 0; i < path_object->size(); i++) + delete path_object->at(i); + delete path_object; + path_object = _path_object; + } + else + throw InvalidValueException("Invalid value in PathObject in CT_PageBlock: null pointer"); + } + QVector * getImageObject() { return image_object; } + + void setImageObject(QVector * _image_object) { + if (_image_object) { + for (int i = 0; i < image_object->size(); i++) + delete image_object->at(i); + delete image_object; + image_object = _image_object; + } + else + throw InvalidValueException("Invalid value in ImageObject in CT_PageBlock: null pointer"); + } + QVector * getPageBlock() { return pageblock; } + + void setPageBlock(QVector * _pageblock) { + if (_pageblock) { + for (int i = 0; i < _pageblock->size(); i++) + delete _pageblock->at(i); + delete _pageblock; + pageblock = _pageblock; + } + else + throw InvalidValueException("Invalid value in PageBlock in CT_PageBlock: null pointer"); + } + ~CT_PageBlock() { for (int i = 0; i < text_object->length(); i++) delete text_object->at(i); diff --git a/ofdEditor/ofd/DataTypes/page/CT_Pages.h b/ofdEditor/ofd/DataTypes/page/CT_Pages.h index 0ffadd7..3c6aeec 100644 --- a/ofdEditor/ofd/DataTypes/page/CT_Pages.h +++ b/ofdEditor/ofd/DataTypes/page/CT_Pages.h @@ -8,14 +8,28 @@ class OFDSHARED_EXPORT CT_Pages { public: QVector * pages; + +public: + friend class OFDParser; CT_Pages() { pages = new QVector(); } -public: - friend class OFDParser; + QVector *getPages() { return pages; } + + void setPages(QVector * _pages) { + if (_pages) { + for (int i = 0; i < pages->size(); i++) + delete pages->at(i); + delete pages; + pages = _pages; + } + else + throw InvalidValueException("Invalid Value in Pages in CT_Pages: null pointer"); + } + ~CT_Pages() { for (int i = 0; i < pages->size(); i++) delete pages->at(i); diff --git a/ofdEditor/ofd/DataTypes/page/Page.h b/ofdEditor/ofd/DataTypes/page/Page.h index 5e726e9..90342d2 100644 --- a/ofdEditor/ofd/DataTypes/page/Page.h +++ b/ofdEditor/ofd/DataTypes/page/Page.h @@ -14,30 +14,76 @@ public: QVector * page_res_locations; QVector *content; //Actions to be implemented + +public: + friend class OFDParser; Page() { content = new QVector; page_res = new QVector; page_res_locations = new QVector; area = nullptr; } -public: - friend class OFDParser; - ST_Loc getBaseLoc() { return base_loc; } + + ST_Loc getBaseLoc() { + return base_loc; + } + + void setBaseLoc(QString _base_loc_abs) { + ST_Loc p("BaseLoc", _base_loc_abs); + base_loc = p; + } + QVector * getContent() { return content; } + + void setContent(QVector * _content) { + if (_content) { + for (int i = 0; i < content->size(); i++) + delete content->at(i); + delete content; + content = _content; + } + else + throw InvalidValueException("Invalid Value in Content in Page: null pointer"); + } + CT_PageArea * getArea() { return area; } + void setArea(CT_PageArea * _area) { + delete area; + area = _area; + } + QVector * getPageRes() { return page_res; } + void setPageRes(QVector * _page_res) { + if (_page_res) { + for (int i = 0; i < page_res->size(); i++) + delete page_res->at(i); + delete page_res; + page_res = _page_res; + } + else + throw InvalidValueException("Invalid Value in PageRes in Page: null pointer"); + } + QVector * getPageResLocations() { return page_res_locations; } + void setPageResLocations(QVector * _page_res_locations) { + if (_page_res_locations) { + delete page_res_locations; + page_res_locations = _page_res_locations; + } else + throw InvalidValueException("Invalid Value in PageResLocations in Page: null pointer"); + } + ~Page() { for (int i = 0; i < page_res->length(); i++) delete page_res->at(i); diff --git a/ofdEditor/ofd/DataTypes/page/ct_layer.h b/ofdEditor/ofd/DataTypes/page/ct_layer.h index 9340b19..20cf862 100644 --- a/ofdEditor/ofd/DataTypes/page/ct_layer.h +++ b/ofdEditor/ofd/DataTypes/page/ct_layer.h @@ -5,33 +5,48 @@ #include "../../ofd_global.h" // 生成库文件需要 -class OFDSHARED_EXPORT CT_Layer - : public CT_PageBlock -{ +class OFDSHARED_EXPORT CT_Layer : public CT_PageBlock { public: friend class OFDParser; - enum LayerType {Body = 1, Foreground, Background}; + + CT_Layer(QString _type = "Body", + int _draw_param = 0, + ID_Table * _id_table = nullptr) { + setType(_type); + if (_draw_param && _id_table) + setDrawParam(_draw_param, _id_table); + } + QString getType() { - switch (type) { - case Body: - return "Body"; - case Foreground: - return "Foreground"; - case Background: - return "Background"; - } + return type; + } + + void setType(QString _type) { + QStringList possible_values; + possible_values.append("Body"); + possible_values.append("Foreground"); + possible_values.append("Background"); + + if (possible_values.contains(_type)) + type = _type; + else throw InvalidValueException("CT_Layer对象中的Type属性使用了非法值: " + _type); } + ST_RefID getDrawParam() { return draw_param; } + void setDrawParam(int _draw_param, ID_Table * _id_table) { + if (!_id_table->contains(_draw_param)) + throw InvalidIDException("CT_Layer对象中的DrawParam属性引用了未注册的ID: " + QString::number(_draw_param)); + ST_RefID rd(_draw_param); + draw_param = rd; + } + //从CT_PageBlock继承了几个接口 -public: - LayerType type; +private: + QString type; ST_RefID draw_param; - CT_Layer() : CT_PageBlock(){ - type = Body; - } }; #endif // CT_LAYER_H diff --git a/ofdEditor/ofd/DataTypes/page/ct_pageblock.h b/ofdEditor/ofd/DataTypes/page/ct_pageblock.h index baa2040..52543ca 100644 --- a/ofdEditor/ofd/DataTypes/page/ct_pageblock.h +++ b/ofdEditor/ofd/DataTypes/page/ct_pageblock.h @@ -13,26 +13,76 @@ public: QVector * path_object; QVector * image_object; QVector * pageblock; +public: + friend class OFDParser; + CT_PageBlock() { text_object = new QVector(); path_object = new QVector(); image_object = new QVector(); pageblock = new QVector(); } -public: - friend class OFDParser; + QVector * getTextObject() { return text_object; } + + void setTextObject(QVector * _text_object) { + if (_text_object) { + for (int i = 0; i < text_object->size(); i++) + delete text_object->at(i); + delete text_object; + text_object = _text_object; + } + else + throw InvalidValueException("Invalid value in TextObject in CT_PageBlock: null pointer"); + } + QVector * getPathObject() { return path_object; } + + void setPathObject(QVector * _path_object) { + if (_path_object) { + for (int i = 0; i < path_object->size(); i++) + delete path_object->at(i); + delete path_object; + path_object = _path_object; + } + else + throw InvalidValueException("Invalid value in PathObject in CT_PageBlock: null pointer"); + } + QVector * getImageObject() { return image_object; } + + void setImageObject(QVector * _image_object) { + if (_image_object) { + for (int i = 0; i < image_object->size(); i++) + delete image_object->at(i); + delete image_object; + image_object = _image_object; + } + else + throw InvalidValueException("Invalid value in ImageObject in CT_PageBlock: null pointer"); + } + QVector * getPageBlock() { return pageblock; } + + void setPageBlock(QVector * _pageblock) { + if (_pageblock) { + for (int i = 0; i < _pageblock->size(); i++) + delete _pageblock->at(i); + delete _pageblock; + pageblock = _pageblock; + } + else + throw InvalidValueException("Invalid value in PageBlock in CT_PageBlock: null pointer"); + } + ~CT_PageBlock() { for (int i = 0; i < text_object->length(); i++) delete text_object->at(i); diff --git a/ofdEditor/ofd/DataTypes/page/ct_pages.h b/ofdEditor/ofd/DataTypes/page/ct_pages.h index 0ffadd7..3c6aeec 100644 --- a/ofdEditor/ofd/DataTypes/page/ct_pages.h +++ b/ofdEditor/ofd/DataTypes/page/ct_pages.h @@ -8,14 +8,28 @@ class OFDSHARED_EXPORT CT_Pages { public: QVector * pages; + +public: + friend class OFDParser; CT_Pages() { pages = new QVector(); } -public: - friend class OFDParser; + QVector *getPages() { return pages; } + + void setPages(QVector * _pages) { + if (_pages) { + for (int i = 0; i < pages->size(); i++) + delete pages->at(i); + delete pages; + pages = _pages; + } + else + throw InvalidValueException("Invalid Value in Pages in CT_Pages: null pointer"); + } + ~CT_Pages() { for (int i = 0; i < pages->size(); i++) delete pages->at(i); diff --git a/ofdEditor/ofd/DataTypes/page/page.h b/ofdEditor/ofd/DataTypes/page/page.h index 5e726e9..90342d2 100644 --- a/ofdEditor/ofd/DataTypes/page/page.h +++ b/ofdEditor/ofd/DataTypes/page/page.h @@ -14,30 +14,76 @@ public: QVector * page_res_locations; QVector *content; //Actions to be implemented + +public: + friend class OFDParser; Page() { content = new QVector; page_res = new QVector; page_res_locations = new QVector; area = nullptr; } -public: - friend class OFDParser; - ST_Loc getBaseLoc() { return base_loc; } + + ST_Loc getBaseLoc() { + return base_loc; + } + + void setBaseLoc(QString _base_loc_abs) { + ST_Loc p("BaseLoc", _base_loc_abs); + base_loc = p; + } + QVector * getContent() { return content; } + + void setContent(QVector * _content) { + if (_content) { + for (int i = 0; i < content->size(); i++) + delete content->at(i); + delete content; + content = _content; + } + else + throw InvalidValueException("Invalid Value in Content in Page: null pointer"); + } + CT_PageArea * getArea() { return area; } + void setArea(CT_PageArea * _area) { + delete area; + area = _area; + } + QVector * getPageRes() { return page_res; } + void setPageRes(QVector * _page_res) { + if (_page_res) { + for (int i = 0; i < page_res->size(); i++) + delete page_res->at(i); + delete page_res; + page_res = _page_res; + } + else + throw InvalidValueException("Invalid Value in PageRes in Page: null pointer"); + } + QVector * getPageResLocations() { return page_res_locations; } + void setPageResLocations(QVector * _page_res_locations) { + if (_page_res_locations) { + delete page_res_locations; + page_res_locations = _page_res_locations; + } else + throw InvalidValueException("Invalid Value in PageResLocations in Page: null pointer"); + } + ~Page() { for (int i = 0; i < page_res->length(); i++) delete page_res->at(i); diff --git a/ofdEditor/ofd/DataTypes/text/CT_Font.h b/ofdEditor/ofd/DataTypes/text/CT_Font.h index b186a24..237764f 100644 --- a/ofdEditor/ofd/DataTypes/text/CT_Font.h +++ b/ofdEditor/ofd/DataTypes/text/CT_Font.h @@ -27,24 +27,59 @@ public: QString getFontName() { return font_name; } + void setFontName(QString _font_name) { + if (_font_name.isNull()) + throw InvalidValueException("Invalid value in FontName in CT_Font: null"); + font_name = _font_name; + } + QString getFamilyName() { return family_name; } + + void setFamilyName(QString _family_name) { + family_name = _family_name; + } + QString getCharset() { return charset; } + + void setCharset(QString _charset) { + charset = _charset; + } + bool getItalic() { return italic; } + + void setItalic(bool _italic) { + italic = _italic; + } + bool getBold() { return bold; } + + void setBold(bool _bold) { + bold = _bold; + } + bool getSerif() { return serif; } + + void setSerif(bool _serif) { + serif = _serif; + } + bool getFixedWidth() { return fixed_width; } + + void setFixedWidth(bool _fixed_width) { + fixed_width = _fixed_width; + } }; #endif // CT_FONT_H diff --git a/ofdEditor/ofd/DataTypes/text/CT_Text.h b/ofdEditor/ofd/DataTypes/text/CT_Text.h index 3d14385..2849e1c 100644 --- a/ofdEditor/ofd/DataTypes/text/CT_Text.h +++ b/ofdEditor/ofd/DataTypes/text/CT_Text.h @@ -24,7 +24,7 @@ public: int weight; //文字对象的粗细值 bool italic; //是否是斜体 //CT_CGTransform to be implemented - TextCode * text_code; + QVector * text_code; CT_Text(){ stroke = false; fill = true; @@ -34,31 +34,111 @@ public: weight = 400; italic = false; size_used = false; - text_code = nullptr; + text_code = new QVector; } public: friend class OFDParser; ~CT_Text() { + for (int i = 0; i < text_code->size(); i++) + delete text_code->at(i); delete text_code; } - ST_RefID getFont() { return font; } - double getSize() { return size; } - bool sizeUsed() { return size_used; } - bool getStroke() { return stroke; } - bool getFill() { return fill; } - double getHScale() { return hscale; } - int getReadDirection() { return read_direction; } - int getCharDirection() { return char_direction; } + ST_RefID getFont() { + return font; + } + + void setFont(int _font, ID_Table * _id_table) { + if (_id_table->contains(_font)) { + ST_RefID ri(_font); + font = ri; + } else + throw InvalidIDException("CT_Text对象的Font属性引用了未注册的ID: " + QString::number(_font)); + } + + double getSize() { + return size; + } + + void setSize(double _size) { + size = _size; + } + + bool sizeUsed() { + return size_used; + } + + bool getStroke() { + return stroke; + } + + void setStroke(bool _stroke) { + stroke = _stroke; + } + + bool getFill() { + return fill; + } + + void setFill(bool _fill) { + fill = _fill; + } + + double getHScale() { + return hscale; + } + + void setHScale(double _hscale) { + hscale = _hscale; + } + + int getReadDirection() { + return read_direction; + } + + void setReadDirection(int _read_direction) { + read_direction = _read_direction; + } + + int getCharDirection() { + return char_direction; + } + + void setCharDirection(int _char_direction) { + char_direction = _char_direction; + } + int getWeight() { - if (weight == 1000) + return weight; + } + + void setWeight(int _weight) { + if (_weight == 1000) weight = 900; - if (weight % 100 != 0 || weight > 1000 || weight <= 0) + else if (_weight % 100 != 0 || _weight > 1000 || _weight <= 0) weight = 400; - return weight; } - bool getItalic() { return italic; } - TextCode * getTextCode() { return text_code; } + bool getItalic() { + return italic; + } + + void setItalic(bool _italic) { + italic = _italic; + } + QVector * getTextCode() { + return text_code; + } + + void setTextCode(QVector * _text_code) { + if (_text_code) { + for (int i = 0; i < text_code->size(); i++) + delete text_code->at(i); + delete text_code; + text_code = _text_code; + } + else + throw InvalidValueException("Invalid value in TextCode in Page: null pointer"); + } }; #endif // CT_TEXT_H diff --git a/ofdEditor/ofd/DataTypes/text/TextCode.h b/ofdEditor/ofd/DataTypes/text/TextCode.h index c84ae10..05abeeb 100644 --- a/ofdEditor/ofd/DataTypes/text/TextCode.h +++ b/ofdEditor/ofd/DataTypes/text/TextCode.h @@ -8,15 +8,50 @@ public: double x, y; //首字形的绘制点的横纵坐标 ST_Array delta_x, delta_y; //字形绘制点横纵方向偏移 QString text; //!!!!!文本内容 - TextCode() {} + public: friend class OFDParser; - double getX() { return x; } - double getY() { return y; } - ST_Array getDeltaX() { return delta_x; } - ST_Array getDeltaY() { return delta_y; } + TextCode() {} + double getX() { + return x; + } + + void setX(double _x) { + x = _x; + } + + double getY() { + return y; + } + + void setY(double _y) { + y = _y; + } + + ST_Array getDeltaX() { + return delta_x; + } + + void setDeltaX(QString _delta_x) { + ST_Array a("DeltaX", _delta_x); + delta_x = a; + } + + ST_Array getDeltaY() { + return delta_y; + } + + void setDeltaY(QString _delta_y) { + ST_Array a("DeltaY", _delta_y); + delta_y = a; + } + QString getText() { //获取文本内容 return text; } + + void setText(QString _text) { + text = _text; + } }; #endif // TEXTCODE_H diff --git a/ofdEditor/ofd/DataTypes/text/ct_font.h b/ofdEditor/ofd/DataTypes/text/ct_font.h index b186a24..237764f 100644 --- a/ofdEditor/ofd/DataTypes/text/ct_font.h +++ b/ofdEditor/ofd/DataTypes/text/ct_font.h @@ -27,24 +27,59 @@ public: QString getFontName() { return font_name; } + void setFontName(QString _font_name) { + if (_font_name.isNull()) + throw InvalidValueException("Invalid value in FontName in CT_Font: null"); + font_name = _font_name; + } + QString getFamilyName() { return family_name; } + + void setFamilyName(QString _family_name) { + family_name = _family_name; + } + QString getCharset() { return charset; } + + void setCharset(QString _charset) { + charset = _charset; + } + bool getItalic() { return italic; } + + void setItalic(bool _italic) { + italic = _italic; + } + bool getBold() { return bold; } + + void setBold(bool _bold) { + bold = _bold; + } + bool getSerif() { return serif; } + + void setSerif(bool _serif) { + serif = _serif; + } + bool getFixedWidth() { return fixed_width; } + + void setFixedWidth(bool _fixed_width) { + fixed_width = _fixed_width; + } }; #endif // CT_FONT_H diff --git a/ofdEditor/ofd/DataTypes/text/ct_text.h b/ofdEditor/ofd/DataTypes/text/ct_text.h index 3d14385..2849e1c 100644 --- a/ofdEditor/ofd/DataTypes/text/ct_text.h +++ b/ofdEditor/ofd/DataTypes/text/ct_text.h @@ -24,7 +24,7 @@ public: int weight; //文字对象的粗细值 bool italic; //是否是斜体 //CT_CGTransform to be implemented - TextCode * text_code; + QVector * text_code; CT_Text(){ stroke = false; fill = true; @@ -34,31 +34,111 @@ public: weight = 400; italic = false; size_used = false; - text_code = nullptr; + text_code = new QVector; } public: friend class OFDParser; ~CT_Text() { + for (int i = 0; i < text_code->size(); i++) + delete text_code->at(i); delete text_code; } - ST_RefID getFont() { return font; } - double getSize() { return size; } - bool sizeUsed() { return size_used; } - bool getStroke() { return stroke; } - bool getFill() { return fill; } - double getHScale() { return hscale; } - int getReadDirection() { return read_direction; } - int getCharDirection() { return char_direction; } + ST_RefID getFont() { + return font; + } + + void setFont(int _font, ID_Table * _id_table) { + if (_id_table->contains(_font)) { + ST_RefID ri(_font); + font = ri; + } else + throw InvalidIDException("CT_Text对象的Font属性引用了未注册的ID: " + QString::number(_font)); + } + + double getSize() { + return size; + } + + void setSize(double _size) { + size = _size; + } + + bool sizeUsed() { + return size_used; + } + + bool getStroke() { + return stroke; + } + + void setStroke(bool _stroke) { + stroke = _stroke; + } + + bool getFill() { + return fill; + } + + void setFill(bool _fill) { + fill = _fill; + } + + double getHScale() { + return hscale; + } + + void setHScale(double _hscale) { + hscale = _hscale; + } + + int getReadDirection() { + return read_direction; + } + + void setReadDirection(int _read_direction) { + read_direction = _read_direction; + } + + int getCharDirection() { + return char_direction; + } + + void setCharDirection(int _char_direction) { + char_direction = _char_direction; + } + int getWeight() { - if (weight == 1000) + return weight; + } + + void setWeight(int _weight) { + if (_weight == 1000) weight = 900; - if (weight % 100 != 0 || weight > 1000 || weight <= 0) + else if (_weight % 100 != 0 || _weight > 1000 || _weight <= 0) weight = 400; - return weight; } - bool getItalic() { return italic; } - TextCode * getTextCode() { return text_code; } + bool getItalic() { + return italic; + } + + void setItalic(bool _italic) { + italic = _italic; + } + QVector * getTextCode() { + return text_code; + } + + void setTextCode(QVector * _text_code) { + if (_text_code) { + for (int i = 0; i < text_code->size(); i++) + delete text_code->at(i); + delete text_code; + text_code = _text_code; + } + else + throw InvalidValueException("Invalid value in TextCode in Page: null pointer"); + } }; #endif // CT_TEXT_H diff --git a/ofdEditor/ofd/DataTypes/text/textcode.h b/ofdEditor/ofd/DataTypes/text/textcode.h index c84ae10..05abeeb 100644 --- a/ofdEditor/ofd/DataTypes/text/textcode.h +++ b/ofdEditor/ofd/DataTypes/text/textcode.h @@ -8,15 +8,50 @@ public: double x, y; //首字形的绘制点的横纵坐标 ST_Array delta_x, delta_y; //字形绘制点横纵方向偏移 QString text; //!!!!!文本内容 - TextCode() {} + public: friend class OFDParser; - double getX() { return x; } - double getY() { return y; } - ST_Array getDeltaX() { return delta_x; } - ST_Array getDeltaY() { return delta_y; } + TextCode() {} + double getX() { + return x; + } + + void setX(double _x) { + x = _x; + } + + double getY() { + return y; + } + + void setY(double _y) { + y = _y; + } + + ST_Array getDeltaX() { + return delta_x; + } + + void setDeltaX(QString _delta_x) { + ST_Array a("DeltaX", _delta_x); + delta_x = a; + } + + ST_Array getDeltaY() { + return delta_y; + } + + void setDeltaY(QString _delta_y) { + ST_Array a("DeltaY", _delta_y); + delta_y = a; + } + QString getText() { //获取文本内容 return text; } + + void setText(QString _text) { + text = _text; + } }; #endif // TEXTCODE_H diff --git a/ofdEditor/ofd/main.cpp b/ofdEditor/ofd/main.cpp index db1bf47..a617a59 100644 --- a/ofdEditor/ofd/main.cpp +++ b/ofdEditor/ofd/main.cpp @@ -2,17 +2,23 @@ #include #include #include -#include "DataTypes/basic_datatype.h" -#include "ofd_parser.h" -#include "ofd_writer.h" +#include "../ofd/DataTypes/basic_datatype.h" +#include "../ofd/ofd_parser.h" +#include "../ofd/ofd_writer.h" #include using namespace std; int main(int argc, char *argv[]) { - OFDParser t("F:/第六届中软杯/OFD Document/OFD.xml"); + try { + OFDParser t("F:/第六届中软杯/OFD Document 3/OFD.xml"); OFD * i = t.getData(); OFDWriter w(i, "F:/第六届中软杯/writing_test/AnotherTest/"); + //qDebug() << i->getDocuments()->at(0)->getIDTable()->size(); + } catch (Exception e) { + qDebug() << e.getMessage(); + } + // QString str1("F:/第六届中软杯/OFD Document/OFD.xml"); // QString str2("F:/第六届中软杯/OFD Document/"); // ST_Loc t1("1",str1), t2("1", str2); diff --git a/ofdEditor/ofd/ofd.pro b/ofdEditor/ofd/ofd.pro index 5816cb2..0350806 100644 --- a/ofdEditor/ofd/ofd.pro +++ b/ofdEditor/ofd/ofd.pro @@ -31,7 +31,8 @@ SOURCES += \ ofd_parser.cpp \ DataTypes/basic_datatypes.cpp \ ofd_writer.cpp \ - Loaders/ZipTool.cpp + Loaders/ZipTool.cpp \ + ofdexceptions.cpp HEADERS +=\ @@ -43,33 +44,34 @@ HEADERS +=\ DataTypes/Color/CT_ColorSpace.h \ # DataTypes/Color/CT_Pattern.h \ # DataTypes/Color/CT_RadialShd.h \ - DataTypes/document/ct_commondata.h \ - DataTypes/document/ct_docinfo.h \ - DataTypes/document/ct_outlineelem.h \ - DataTypes/document/ct_outlines.h \ - DataTypes/document/docbody.h \ - DataTypes/document/document.h \ - DataTypes/document/ofd.h \ + DataTypes/document/CT_CommonData.h \ + DataTypes/document/CT_DocInfo.h \ + DataTypes/document/CT_OutlineElem.h \ + DataTypes/document/CT_Outlines.h \ + DataTypes/document/DocBody.h \ + DataTypes/document/Document.h \ + DataTypes/document/OFD.h \ # DataTypes/image/CT_Clip.h \ DataTypes/image/CT_DrawParam.h \ DataTypes/image/CT_GraphicUnit.h \ DataTypes/image/CT_Image.h \ DataTypes/image/CT_Path.h \ - DataTypes/page/ct_layer.h \ + DataTypes/page/CT_Layer.h \ DataTypes/page/CT_PageArea.h \ - DataTypes/page/ct_pageblock.h \ - DataTypes/page/ct_pages.h \ - DataTypes/page/page.h \ + DataTypes/page/CT_PageBlock.h \ + DataTypes/page/CT_Pages.h \ + DataTypes/page/Page.h \ ofd_parser.h \ DataTypes/document/res.h\ # DataTypes/text/CT_CGTransform.h \ - DataTypes/text/ct_font.h \ - DataTypes/text/ct_text.h \ - DataTypes/text/textcode.h \ + DataTypes/text/CT_Font.h \ + DataTypes/text/CT_Text.h \ + DataTypes/text/TextCode.h \ ofd_global.h \ ofd_writer.h \ - DataTypes/document/customtags.h \ - Loaders/ZipTool.h + DataTypes/document/CustomTags.h \ + Loaders/ZipTool.h \ + ofdexceptions.h DESTDIR = ../bin # 生成文件在这 diff --git a/ofdEditor/ofd/ofd_parser.cpp b/ofdEditor/ofd/ofd_parser.cpp index d7d1535..1c2c386 100644 --- a/ofdEditor/ofd/ofd_parser.cpp +++ b/ofdEditor/ofd/ofd_parser.cpp @@ -1,53 +1,41 @@ #include "ofd_parser.h" #include -OFDParser::OFDParser(QString _path) : - current_path("OFD", _path) -{ - this->error_msg = "Analysis dom file failed"; - +OFDParser::OFDParser(QString _path) : current_path("OFD", _path) { document = new QDomDocument(); data = readOFD(); - qDebug()<<"OFD file read finished"; } void OFDParser::openFile() { QFile ofd_file(current_path.getPath()); if (!ofd_file.open(QFile::ReadOnly | QFile::Text)) { //检查文件是否存在&正常打开 - //出现异常!!!to be implemented - qDebug() << "xml文件打开出现错误。 " << endl; - abort(); + throw ParsingFileException("无法打开XML文件: " + current_path.getPath()); } - - qDebug() <<"xml File Open Successfully:" - <setContent(&ofd_file, //解析OFD文档并将树状内容存在document文件中 false, &error_msg, &error_line, &error_column)) { ofd_file.close(); - - qDebug() <<"xml File analysis Successfully:" - <firstChildElement("ofd:OFD"); OFD *ofd_data = nullptr; if (!new_ofd.isNull()) { ofd_data = new OFD(); - ofd_data->doc_type = new_ofd.attribute("DocType"); - ofd_data->version = new_ofd.attribute("Version"); + if (new_ofd.hasAttribute("DocType")) + ofd_data->doc_type = new_ofd.attribute("DocType"); + else + throw ParsingFormatException("OFD类型的数据中中缺少必要的DocType属性\n位于" + current_path.getRelativePath()); + if (new_ofd.hasAttribute("Version")) + ofd_data->version = new_ofd.attribute("Version"); + else + throw ParsingFormatException("OFD类型的数据中中缺少必要的Version属性\n位于" + current_path.getRelativePath()); ofd_data->root_path = current_path; QDomElement new_docbody = new_ofd.firstChildElement("ofd:DocBody"); @@ -91,24 +79,20 @@ OFD * OFDParser::readOFD() { } } } else { - //Error - abort(); + throw ParsingFormatException("DocBody类型的数据中中缺少必要的DocInfo成员\n位于" + current_path.getRelativePath()); } QDomElement new_docroot = new_docbody.firstChildElement("ofd:DocRoot"); if (!new_docroot.isNull()) { ST_Loc p("Document", new_docroot.text(), current_path); docbody_data->doc_root = p; } else { - //qDebug() << "非法的OFD文档格式。" << endl; - //Error - abort(); + throw ParsingFormatException("DocBody类型的数据中中缺少必要的DocInfo成员\n位于" + current_path.getRelativePath()); } new_docbody = new_ofd.nextSiblingElement("ofd:DocBody"); } } else { - qDebug() << "非法的OFD文档格式。 " << endl; - abort(); + throw ParsingFormatException("OFD类型的数据中中缺少必要的DocBody成员\n位于" + current_path.getRelativePath()); } if (ofd_data) { for (int i = 0; i < ofd_data->docbodys->length(); i++) { @@ -119,13 +103,14 @@ OFD * OFDParser::readOFD() { return ofd_data; } -Document * OFDParser::readDocument(){ +Document * OFDParser::readDocument() { openFile(); - qDebug() << "Entering readDocument module..." << endl; +// qDebug() << "Checkpoint 1"; QDomElement new_document = document->firstChildElement("ofd:Document"); Document *document_data; if (!new_document.isNull()) { document_data = new Document(); + id_table = document_data->id_table; QDomElement new_commondata = new_document.firstChildElement("ofd:CommonData"); if (!new_commondata.isNull()) { CT_CommonData * commondata_data = new CT_CommonData(); @@ -159,7 +144,7 @@ Document * OFDParser::readDocument(){ } } else { - //Error + throw ParsingFormatException("Document类型的数据中中缺少必要的CommonData成员\n位于Document.xml"); } QDomElement new_pages = new_document.firstChildElement("ofd:Pages"); @@ -171,15 +156,14 @@ Document * OFDParser::readDocument(){ while (!new_page.isNull()) { Page *p = new Page(); ST_ID i(new_page.attribute("ID").toLong()); - p->setID(i); + p->setID(i, id_table); ST_Loc path("Page", new_page.attribute("BaseLoc"), current_path); p->base_loc = path; pages_data->pages->push_back(p); new_page = new_page.nextSiblingElement("ofd:Page"); } } else { - //Error - abort(); + throw ParsingFormatException("Document类型的数据中中缺少必要的Pages成员\n位于Document.xml"); } document_data->pages = pages_data; @@ -205,22 +189,22 @@ Document * OFDParser::readDocument(){ } } else { - //Error - abort(); - } - //访问页面 - for (int i = 0; i < document_data->pages->pages->size(); i++) { - current_path = document_data->pages->pages->at(i)->base_loc; - readPage(document_data->pages->pages->at(i)); + throw ParsingFormatException("Document.xml文档中缺少必要的Document标签\n位于" + current_path.getRelativePath()); } //访问资源 for (int i = 0; i < document_data->common_data->public_res->size(); i++) { - //qDebug() << "Start to read PublicRes..." << endl; current_path = document_data->common_data->public_res->at(i); Res * res_data = new Res(); readResource(res_data); document_data->public_res->push_back(res_data); } + + //访问页面 + for (int i = 0; i < document_data->pages->pages->size(); i++) { + current_path = document_data->pages->pages->at(i)->base_loc; + readPage(document_data->pages->pages->at(i)); + } + //访问自定义标签 if (!document_data->custom_tags.isNull()) { current_path = document_data->custom_tags; @@ -230,25 +214,19 @@ Document * OFDParser::readDocument(){ } void OFDParser::readPage(Page * page_data) { - - qDebug() << "Entering readPage module..." << endl; openFile(); - QDomElement new_page = document->firstChildElement("ofd:Page"); - if (!new_page.isNull()) - { +// qDebug() << "Checkpoint 2"; + if (!new_page.isNull()) { QDomElement t; - if (!(t = new_page.firstChildElement("ofd:Area")).isNull()) - { - qDebug() << "Start to read PageArea..." << endl; + if (!(t = new_page.firstChildElement("ofd:Area")).isNull()) { CT_PageArea * area_data = new CT_PageArea(); readPageArea(area_data, t); page_data->area = area_data; } t = new_page.firstChildElement("ofd:PageRes"); - while (!t.isNull()) - { + while (!t.isNull()) { ST_Loc p("PageRes", t.text(), current_path); Res * new_res = new Res(); current_path = p; @@ -257,150 +235,133 @@ void OFDParser::readPage(Page * page_data) { t = t.nextSiblingElement("ofd:PageRes"); } - if (!(t = new_page.firstChildElement("ofd:Content")).isNull()) - { - qDebug() << "Start to read Content..." << endl; + if (!(t = new_page.firstChildElement("ofd:Content")).isNull()) { +// qDebug() << "Checkpoint 2.1"; QDomElement new_layer = t.firstChildElement("ofd:Layer"); while (!new_layer.isNull()) { CT_Layer * layer_data = new CT_Layer(); page_data->getContent()->push_back(layer_data); if (new_layer.hasAttribute("ID")) { ST_ID i(new_layer.attribute("ID").toInt()); - layer_data->setID(i); + layer_data->setID(i, id_table); } else { - //Error - abort(); + throw ParsingFormatException("CT_Layer类型数据中缺少必要的ID属性\n位于" + current_path.getRelativePath()); } if (new_layer.hasAttribute("DrawParam")) { ST_RefID ri(new_layer.attribute("DrawParam").toInt()); - layer_data->draw_param = ri; + if (id_table->contains(ri.getRefID())) + layer_data->draw_param = ri; + else { + throw ParsingIDException("Layer类型数据的DrawParam属性引用了未注册的ID 位于" + current_path.getRelativePath()); + } } +// qDebug() << "Checkpoint 2.2"; QDomElement t; //解析文字对象 bool is_first_textcode_x = true, is_first_textcode_y = true; double last_x = 0.0, last_y = 0.0; t = new_layer.firstChildElement("ofd:TextObject"); - while (!t.isNull()) - { - qDebug() << "Start to read TextObject" << endl; + while (!t.isNull()) { + //qDebug() << "Start to read TextObject..." << endl; CT_Text * text_data = new CT_Text(); layer_data->text_object->push_back(text_data); readGraphicUnit(text_data, t); //Read TextObject attributes - if (t.hasAttribute("Font")) - { + if (t.hasAttribute("Font")) { ST_RefID ri(t.attribute("Font").toInt()); - text_data->font = ri; - } - else - { - //Error - abort(); + if (id_table->contains(ri.getRefID())) + text_data->font = ri; + else { + throw ParsingIDException("CT_Text类型数据的Font属性引用了未注册的ID:" + QString::number(ri.getRefID()) + " 位于" + current_path.getRelativePath()); + } + } else { + throw ParsingFormatException("CT_Text类型数据中缺少必要的Font属性\n位于" + current_path.getRelativePath()); } - if (t.hasAttribute("Size")) - { + if (t.hasAttribute("Size")) { text_data->size = t.attribute("Size").toDouble(); text_data->size_used = true; + } else { + throw ParsingFormatException("CT_Text类型数据中缺少必要的Size属性\n位于" + current_path.getRelativePath()); } - else - { - //Error - qDebug() <<"t don't has attribute size"; - abort(); - } - +// qDebug() << "Checkpoint 2.3"; //many optional attributes to be implemented - QDomElement t2; - if (!(t2 = t.firstChildElement("ofd:TextCode")).isNull()) - { - qDebug() << "ofd:TextCode"; - + QDomElement t2 = t.firstChildElement("ofd:TextCode"); + if (t2.isNull()) { + throw ParsingFormatException("CT_Text类型数据中缺少必要的TextCode成员\n位于" + current_path.getRelativePath()); + } +// qDebug() << "Checkpoint 2.3.1"; + while(!t2.isNull()) { TextCode * text_code_data = new TextCode(); - text_data->text_code = text_code_data; - if (t2.hasAttribute("X")) - { +// qDebug() << "Checkpoint 2.3.1.0"; + text_data->text_code->push_back(text_code_data); +// qDebug() << "Checkpoint 2.3.1.1"; + if (t2.hasAttribute("X")) { last_x = text_code_data->x = t2.attribute("X").toDouble(); if (is_first_textcode_x) is_first_textcode_x = false; - } - else - { + } else { if (!is_first_textcode_x && !is_first_textcode_y) text_code_data->x = last_x; - else - { - //Error - qDebug() << "ofd:TextCode" - << "if (!is_first_textcode_x && !is_first_textcode_y)"; - abort(); + else { + throw ParsingFormatException("TextCode类型数据中缺少第一个X值\n位于" + current_path.getRelativePath()); } } - if (t2.hasAttribute("Y")) - { +// qDebug() << "Checkpoint 2.3.2"; + if (t2.hasAttribute("Y")) { last_y = text_code_data->y = t2.attribute("Y").toDouble(); if (is_first_textcode_y) is_first_textcode_y = false; - } else - { + } else { if (!is_first_textcode_x && !is_first_textcode_y) text_code_data->y = last_y; - else - { - //Error - qDebug() << "ofd:TextCode if (!is_first_textcode_x && !is_first_textcode_y)"; - abort(); + else { + throw ParsingFormatException("TextCode类型数据中缺少第一个Y值\n位于" + current_path.getRelativePath()); } } - if (t2.hasAttribute("DeltaX")) - { + if (t2.hasAttribute("DeltaX")) { ST_Array delta_x_data("DeltaX", t2.attribute("DeltaX")); text_code_data->delta_x = delta_x_data; } - - if (t2.hasAttribute("DeltaY")) - { + if (t2.hasAttribute("DeltaY")) { ST_Array delta_y_data("DeltaX", t2.attribute("DeltaY")); text_code_data->delta_y = delta_y_data; } text_code_data->text = t2.text(); - } - else - { - //Error - qDebug() << "if (!(t2 = t.firstChildElement(\"ofd:TextCode\")).isNull())"; - abort(); + + t2 = t2.nextSiblingElement("ofd:TextCode"); } t = t.nextSiblingElement("ofd:TextObject"); } - -// //解析矢量图对象 -// t = new_layer.firstChildElement("ofd:PathObject"); -// while (!t.isNull()) { -// CT_Path * path_data = new CT_Path(); -// layer_data->path_object->push_back(path_data); -// readGraphicUnit(path_data, t); -// if (t.hasAttribute("Stroke")) { -// path_data->stroke = t.attribute("Stroke") == "false" ? false : true; -// } -// if (t.hasAttribute("Fill")) { -// path_data->fill = t.attribute("Fill") == "false" ? false : true; -// } -// if (t.hasAttribute("Rule")) { -// if (t.attribute("Rule") == "NonZero") -// path_data->rule = "NonZero"; -// else if (t.attribute("rule") == "Even-Odd") -// path_data->rule = "Even-Odd"; -// else { -// //Error! -// abort(); -// } -// } -// if (!t.firstChildElement("ofd:AbbreviatedData").isNull()) { -// path_data->abbreviated_data = t.firstChildElement("ofd:AbbreviatedData").text(); -// } -// t = t.nextSiblingElement("ofd:PathObject"); -// } +// qDebug() << "Checkpoint 2.4"; + //解析矢量图对象 + t = new_layer.firstChildElement("ofd:PathObject"); + while (!t.isNull()) { + CT_Path * path_data = new CT_Path(); + layer_data->path_object->push_back(path_data); + readGraphicUnit(path_data, t); + if (t.hasAttribute("Stroke")) { + path_data->stroke = t.attribute("Stroke") == "false" ? false : true; + } + if (t.hasAttribute("Fill")) { + path_data->fill = t.attribute("Fill") == "false" ? false : true; + } + if (t.hasAttribute("Rule")) { + if (t.attribute("Rule") == "NonZero") + path_data->rule = "NonZero"; + else if (t.attribute("Rule") == "Even-Odd") + path_data->rule = "Even-Odd"; + else { + throw ParsingFormatException("CT_Path类型数据中的Rule属性值为非法值\n位于" + current_path.getRelativePath() + " 值为" + t.attribute("Rule")); + } + } + if (!t.firstChildElement("ofd:AbbreviatedData").isNull()) { + path_data->abbreviated_data = t.firstChildElement("ofd:AbbreviatedData").text(); + } else { + throw ParsingFormatException("CT_Path类型数据中缺少必要的AbbreviatedData成员\n位于" + current_path.getRelativePath()); + } + t = t.nextSiblingElement("ofd:PathObject"); + } //解析位图对象 t = new_layer.firstChildElement("ofd:ImageObject"); @@ -410,26 +371,33 @@ void OFDParser::readPage(Page * page_data) { readGraphicUnit(image_data, t); if (t.hasAttribute("ResourceID")) { ST_RefID ri(t.attribute("ResourceID").toInt()); - image_data->resource_id = ri; + if (id_table->contains(ri.getRefID())) + image_data->resource_id = ri; + else { + throw ParsingIDException("CT_Image类型数据的ResourceID属性引用了未注册的ID 位于" + current_path.getRelativePath()); + } } else { - //Error! - abort(); + throw ParsingFormatException("CT_Image类型数据中缺少必要的ResourceID属性\n位于" + current_path.getRelativePath()); } if (t.hasAttribute("Substitution")) { ST_RefID ri(t.attribute("Substitution").toInt()); - image_data->substitution = ri; + if (id_table->contains(ri.getRefID())) + image_data->substitution = ri; + else { + throw ParsingIDException("CT_Image类型数据的Substitution属性引用了未注册的ID 位于" + current_path.getRelativePath()); + } } t = t.nextSiblingElement("ofd:ImageObject"); } //Other GraphicUnit objects to be implemented - qDebug() << "End of reading content..." << endl; + //qDebug() << "End of reading content..." << endl; new_layer = new_layer.nextSiblingElement("ofd:Layer"); } } } else { - //Error - abort(); + throw ParsingFormatException("Content.xml文档中缺少必要的Page标签\n位于" + current_path.getRelativePath()); } +// qDebug() << "Checkpoint 3"; } void OFDParser::readPageArea(CT_PageArea * data, QDomElement & root_node) { @@ -441,11 +409,10 @@ void OFDParser::readPageArea(CT_PageArea * data, QDomElement & root_node) { data->physical_box = ST_Box(values[0].toDouble(), values[1].toDouble(), values[2].toDouble(), values[3].toDouble()); } else { - //Error - abort(); + throw ParsingFormatException("CT_PageArea类型数据的PhysicalBox成员的值的数目错误\n位于" + current_path.getRelativePath()); } } else { - //Error + throw ParsingFormatException("CT_PageArea类型的数据中中缺少必要的PhysicalBox成员\n位于" + current_path.getRelativePath()); } if (!(t = root_node.firstChildElement("ofd:ApplicationBox")).isNull()) { @@ -453,8 +420,7 @@ void OFDParser::readPageArea(CT_PageArea * data, QDomElement & root_node) { if (values.size() == 4) data->application_box = ST_Box(values[0].toDouble(), values[1].toDouble(), values[2].toDouble(), values[3].toDouble()); else { - //Error - abort(); + throw ParsingFormatException("CT_PageArea类型数据的ApplicationBox成员的值的数目错误\n位于" + current_path.getRelativePath()); } } @@ -462,10 +428,8 @@ void OFDParser::readPageArea(CT_PageArea * data, QDomElement & root_node) { QStringList values = t.text().split(" "); if (values.size() == 4) data->content_box = ST_Box(values[0].toDouble(), values[1].toDouble(), values[2].toDouble(), values[3].toDouble()); - else { - //Error - abort(); - } + else + throw ParsingFormatException("CT_PageArea类型数据的ContentBox成员的值的数目错误\n位于" + current_path.getRelativePath()); } if (!(t = root_node.firstChildElement("ofd:BleedBox")).isNull()) { @@ -473,8 +437,7 @@ void OFDParser::readPageArea(CT_PageArea * data, QDomElement & root_node) { if (values.size() == 4) data->bleed_box = ST_Box(values[0].toDouble(), values[1].toDouble(), values[2].toDouble(), values[3].toDouble()); else { - //Error - abort(); + throw ParsingFormatException("CT_PageArea类型数据的BleedBox成员的值的数目错误\n位于" + current_path.getRelativePath()); } } } @@ -483,10 +446,10 @@ void OFDParser::readGraphicUnit(CT_GraphicUnit *data, QDomElement &root_node) { //读取属性 if (root_node.hasAttribute("ID")) { ST_ID i(root_node.attribute("ID").toInt()); - data->setID(i); + data->setID(i, id_table); + } else { - //Error - abort(); + throw ParsingFormatException("CT_GraphicUnit类型数据中缺少必要的ID属性\n位于" + current_path.getRelativePath()); } if (root_node.hasAttribute("Boundary")) { @@ -495,12 +458,10 @@ void OFDParser::readGraphicUnit(CT_GraphicUnit *data, QDomElement &root_node) { data->boundary = ST_Box(values[0].toDouble(), values[1].toDouble(), values[2].toDouble(), values[3].toDouble()); } else { - //Error - abort(); + throw ParsingFormatException("CT_GraphicUnit类型数据的Boundary成员的值的数目错误\n位于" + current_path.getRelativePath()); } } else { - //Error - abort(); + throw ParsingFormatException("CT_GraphicUnit类型数据中缺少必要的ID属性\n位于" + current_path.getRelativePath()); } //读取成员 @@ -517,15 +478,13 @@ void OFDParser::readGraphicUnit(CT_GraphicUnit *data, QDomElement &root_node) { void OFDParser::readResource(Res * res_data) { openFile(); QDomElement new_res = document->firstChildElement("ofd:Res"); - qDebug() << "Entering readResource module..." << endl; if (!new_res.isNull()) { //读取属性 if (new_res.hasAttribute("BaseLoc")) { ST_Loc new_baseloc("BaseLoc", new_res.attribute("BaseLoc"), current_path); res_data->base_loc = new_baseloc; } else { - //Error - abort(); + throw ParsingFormatException("Res类型数据中缺少必要的BaseLoc属性\n位于" + current_path.getRelativePath()); } //读取成员 QDomElement t; @@ -560,10 +519,9 @@ void OFDParser::readResource(Res * res_data) { } //Other stuff to be implemented } else { - //Error - abort(); + throw ParsingFormatException("Resource.xml文档中缺少必要的Res标签\n位于" + current_path.getRelativePath()); } - qDebug() << "End of reading Resourse..." << endl; + //qDebug() << "End of reading Resourse..." << endl; } void OFDParser::readColor(CT_Color *data, QDomElement & root_node) { @@ -573,7 +531,12 @@ void OFDParser::readColor(CT_Color *data, QDomElement & root_node) { } if (root_node.hasAttribute("ColorSpace")) { ST_RefID colorspace_data(root_node.attribute("ColorSpace").toInt()); - data->color_space = colorspace_data; + if (id_table->contains(colorspace_data.getRefID())) + data->color_space = colorspace_data; + else { + throw ParsingIDException("CT_Color类型数据的ColorSpace属性引用了未注册的ID:" + QString::number(colorspace_data.getRefID()) + " 位于" + current_path.getRelativePath()); + } + } if (root_node.hasAttribute("Index")) { data->index = root_node.attribute("Index").toInt(); @@ -587,16 +550,14 @@ void OFDParser::readColor(CT_Color *data, QDomElement & root_node) { void OFDParser::readFont(CT_Font * data, QDomElement & root_node) { if (root_node.hasAttribute("ID")) { ST_ID i(root_node.attribute("ID").toInt()); - data->setID(i); + data->setID(i, id_table); } else { - //Error - abort(); + throw ParsingFormatException("CT_Font类型数据中缺少必要的ID属性\n位于" + current_path.getRelativePath()); } if (root_node.hasAttribute("FontName")) { data->font_name = root_node.attribute("FontName"); } else { - //Error - abort(); + throw ParsingFormatException("CT_Font类型数据中缺少必要的FontName属性\n位于" + current_path.getRelativePath()); } if (root_node.hasAttribute("FamilyName")) { data->family_name = root_node.attribute("FamilyName"); @@ -619,16 +580,14 @@ void OFDParser::readFont(CT_Font * data, QDomElement & root_node) { void OFDParser::readColorSpace(CT_ColorSpace * data, QDomElement & root_node) { if (root_node.hasAttribute("ID")) { ST_ID i(root_node.attribute("ID").toInt()); - data->setID(i); + data->setID(i, id_table); } else { - //Error - abort(); + throw ParsingFormatException("CT_ColorSpace类型数据中缺少必要的ID属性\n位于" + current_path.getRelativePath()); } if (root_node.hasAttribute("Type")) { data->type = root_node.attribute("Type"); } else { - //Error - abort(); + throw ParsingFormatException("CT_ColorSpace类型数据中缺少必要的Type属性\n位于" + current_path.getRelativePath()); } if (root_node.hasAttribute("BitsPerComponent")) { data->bits_per_component = root_node.attribute("BitsPerComponent").toInt(); @@ -642,14 +601,18 @@ void OFDParser::readColorSpace(CT_ColorSpace * data, QDomElement & root_node) { void OFDParser::readDrawParam(CT_DrawParam * data, QDomElement & root_node) { if (root_node.hasAttribute("ID")) { ST_ID i(root_node.attribute("ID").toInt()); - data->setID(i); + data->setID(i, id_table); } else { - //Error! - abort(); + throw ParsingFormatException("CT_DrawParam类型数据中缺少必要的ID属性\n位于" + current_path.getRelativePath()); } if (root_node.hasAttribute("Relative")) { ST_RefID i(root_node.attribute("Relative").toInt()); - data->relative = i; + if (id_table->contains(i.getRefID())) + data->relative = i; + else { + throw ParsingIDException("CT_DrawParam类型数据的Relative属性引用了未注册的ID 位于" + current_path.getRelativePath()); + } + } if (root_node.hasAttribute("LineWidth")) { data->line_width = root_node.attribute("LineWidth").toDouble(); @@ -659,8 +622,7 @@ void OFDParser::readDrawParam(CT_DrawParam * data, QDomElement & root_node) { if (j == "Miter" || j == "Round" || j == "Bevel") data->join = j; else { - //Error! - abort(); + throw ParsingFormatException("CT_DrawParam类型数据中的Join属性值为非法值\n位于" + current_path.getRelativePath()); } } if (root_node.hasAttribute("Cap")) { @@ -668,8 +630,7 @@ void OFDParser::readDrawParam(CT_DrawParam * data, QDomElement & root_node) { if (c == "Butt" || c == "Round" || c == "Square") data->cap = c; else { - //Error! - abort(); + throw ParsingFormatException("CT_DrawParam类型数据中的Cap属性值为非法值\n位于" + current_path.getRelativePath()); } } if (root_node.hasAttribute("DashOffset")) { diff --git a/ofdEditor/ofd/ofd_parser.h b/ofdEditor/ofd/ofd_parser.h index 80f1f7d..a5e6b6f 100644 --- a/ofdEditor/ofd/ofd_parser.h +++ b/ofdEditor/ofd/ofd_parser.h @@ -10,7 +10,7 @@ #include "DataTypes/page/Page.h" #include "DataTypes/basic_datatype.h" #include "DataTypes/Color/CT_Color.h" -#include "ofd_global.h" +#include "ofdexceptions.h" class OFD; @@ -19,6 +19,8 @@ class OFDSHARED_EXPORT OFDParser { //解析OFD.xml ST_Loc current_path; //当前文档的路径 QDomDocument *document; //保存了ofd文档信息的树形结构 QString error_msg; //当xml文档格式不当、解析错误时的错误信息 + ID_Table * id_table; + int error_line; int error_column; @@ -47,7 +49,7 @@ class OFDSHARED_EXPORT OFDParser { //解析OFD.xml void readResource(Res *); //读取Res文档信息 public: - OFDParser(QString _path); //!!!!!!!!!!!!!!!应设为private + OFDParser(QString _path); OFD * getData() { return data; } diff --git a/ofdEditor/ofd/ofd_writer.cpp b/ofdEditor/ofd/ofd_writer.cpp index a676880..109d516 100644 --- a/ofdEditor/ofd/ofd_writer.cpp +++ b/ofdEditor/ofd/ofd_writer.cpp @@ -10,8 +10,7 @@ void OFDWriter::createFile() { current_file = new QFile(current_path.getPath()); // qDebug() << current_path.getPath() << endl; if (!current_file->open(QFile::WriteOnly | QFile::Text)) { - qDebug() << "Error: Cannot write file."; - abort(); + throw WritingFileException("无法打开或创建XML文件: " + current_path.getPath()); } writer.setDevice(current_file); } @@ -35,8 +34,7 @@ void OFDWriter::writeOFD() { if (!cur_docinfo->getDocID().isNull()) { writer.writeTextElement("ofd:DocID", cur_docinfo->getDocID()); } else { - //Error! - abort(); + throw WritingFormatException("DocInfo类型数据缺少必要的成员DocID"); } if (!cur_docinfo->getTitle().isNull()) { writer.writeTextElement("ofd:Title", cur_docinfo->getTitle()); @@ -92,16 +90,10 @@ void OFDWriter::writeOFD() { //修改current_file ST_Loc cur_path = current_path; for (int i = 0; i < data->getDocBodies()->size(); i++) { -// qDebug() << "To write Document.xml..." << endl; -// qDebug() << "cur_path = " << cur_path << endl; ST_Loc p("Document", data->getDocBodies()->at(i)->getDocRoot().getRelativePath(), cur_path); current_path = p; -// qDebug() << "current_path = " << current_path << endl; - QDir dir(cur_path.getPath()); - - QString str; - dir.mkdir("Doc_" + str.setNum(i)); + makePath(current_path); writeDocument(data->getDocuments()->at(i)); } } @@ -122,16 +114,14 @@ void OFDWriter::writeDocument(Document * data) { writer.writeTextElement("ofd:MaxUnitID", QString::number(cur_common_data->getMaxUnitID().getID())); } else { - //Error! - abort(); + throw WritingFormatException("CT_CommonData类型数据缺少必要的成员MaxUnitID"); } if (cur_common_data->getPageArea()) { writer.writeStartElement("ofd:PageArea"); writePageArea(cur_common_data->getPageArea()); writer.writeEndElement(); //ofd:PageArea } else { - //Error! - abort(); + throw WritingFormatException("CT_CommonData类型数据缺少必要的成员PageArea"); } for (int i = 0; i < data->getCommonData()->getPublicRes()->size(); i++) { @@ -141,8 +131,7 @@ void OFDWriter::writeDocument(Document * data) { //TemplatePage & DefaultCS to be implemented writer.writeEndElement(); //ofd:CommonData } else { - //Error! - abort(); + throw WritingFormatException("Document类型数据缺少必要的成员CommonData"); } //写Pages if (data->getPages()) { @@ -157,8 +146,7 @@ void OFDWriter::writeDocument(Document * data) { } writer.writeEndElement(); //ofd:Pages } else { - //Error! - abort(); + throw WritingFormatException("Document类型数据缺少必要的成员Pages"); } //写CustomTags if (!data->getCustomTags().isNull()) { @@ -170,23 +158,16 @@ void OFDWriter::writeDocument(Document * data) { current_file->close(); ST_Loc cur_path = current_path; for (int i = 0; i < data->getPages()->getPages()->size(); i++) { -// qDebug() << "To write Page.xml..." << endl; -// qDebug() << "cur_path = " << cur_path << endl; - if (i == 0) { - QDir dir(cur_path.getPath().remove("Document.xml")); - dir.mkdir("Pages"); - } ST_Loc p("Page", data->getPages()->getPages()->at(i)-> getBaseLoc().getRelativePath(), cur_path); current_path = p; -// qDebug() << "current_path = " << current_path << endl; - QDir dir(cur_path.getPath().remove("Document.xml").append("Pages\\")); - dir.mkdir("Page_" + QString::number(i)); + makePath(current_path); writePage(data->getPages()->getPages()->at(i)); } for (int i = 0; i < data->getPublicRes()->size(); i++) { ST_Loc p("PublicRes", data->getPublicRes()->at(i)->getBaseLoc().getRelativePath(), cur_path); current_path = p; + makePath(current_path); writeRes(data->getPublicRes()->at(i)); } //write CustomTags to be implemented @@ -251,8 +232,7 @@ void OFDWriter::writeRes(Res * data) { if (!data->getBaseLoc().isNull()) { writer.writeAttribute("BaseLoc", data->getBaseLoc().getRelativePath()); } else { - //Error! - abort(); + throw WritingFormatException("Res类型数据缺少必要的属性BaseLoc"); } //写成员 if (data->getColorSpaces()->size()) { @@ -301,8 +281,7 @@ void OFDWriter::writePageArea(CT_PageArea * cur_page_area) { QString::number(b.getDeltaX())+ " " + QString::number(b.getDeltaY())); } else { - //Error! - abort(); + throw WritingFormatException("CT_PageArea类型数据缺少必要的成员PhysicalBox"); } if (!cur_page_area->getApplicationBox().isNull()) { ST_Box b = cur_page_area->getApplicationBox(); @@ -376,17 +355,16 @@ void OFDWriter::writeTextObject(CT_Text * cur_text) { writeGraphicUnitMemebers(cur_text); //CGTransform to be implemented if (cur_text->getTextCode()) { - TextCode * cur_textcode = cur_text->getTextCode(); - writer.writeStartElement("ofd:TextCode"); - QXmlStreamAttributes a = getAttributes(cur_textcode); -// qDebug() << "Checkpoint 6 reached."; - writer.writeAttributes(a); -// qDebug() << "Checkpoint 7 reached."; - writer.writeCharacters(cur_textcode->getText()); - writer.writeEndElement(); //ofd:TextCode + QVector * cur_textcode = cur_text->getTextCode(); + for (int i = 0; i < cur_textcode->size(); i++) { + writer.writeStartElement("ofd:TextCode"); + QXmlStreamAttributes a = getAttributes(cur_textcode->at(i)); + writer.writeAttributes(a); + writer.writeCharacters(cur_textcode->at(i)->getText()); + writer.writeEndElement(); //ofd:TextCode + } } else { - //Error! - abort(); + throw WritingFormatException("CT_Text类型数据缺少必要的成员TextObject"); } } @@ -401,8 +379,7 @@ void OFDWriter::writePathObject(CT_Path * cur_path) { cur_path->getAbbreviatedData()); // qDebug() << "????"; } else { - //Error! - abort(); + throw WritingFormatException("CT_Path类型数据缺少必要的成员AbbreviatedData"); } } @@ -444,8 +421,7 @@ void OFDWriter::writeBase(CT_Base * cur_base) { if (!cur_base->getID().isNull()) { writer.writeAttribute("ID", QString::number(cur_base->getID().getID())); } else { - //Error! - abort(); + throw WritingFormatException("CT_Base类型数据缺少必要的属性ID"); } } @@ -485,14 +461,12 @@ QXmlStreamAttributes getAttributes(OFD * data) { if (!data->getDocType().isNull()) { a.append("DocType", data->getDocType()); } else { - //Error - abort(); + throw WritingFormatException("OFD类型数据缺少必要的属性DocType"); } if (!data->getOfdVersion().isNull()) { a.append("Version", data->getOfdVersion()); } else { - //Error - abort(); + throw WritingFormatException("OFD类型数据缺少必要的属性Version"); } return a; } @@ -518,8 +492,7 @@ QXmlStreamAttributes getAttributes(CT_GraphicUnit * cur_graphic_unit) { QString::number(b.getDeltaX()) + " " + QString::number(b.getDeltaY())); } else { - //Error - abort(); + throw WritingFormatException("CT_GraphicUnit类型数据缺少必要的属性Boundary"); } if (!cur_graphic_unit->getName().isNull()) { @@ -568,15 +541,13 @@ QXmlStreamAttributes getAttributes(CT_Text * cur_text) { if (!cur_text->getFont().isNull()) { a.append("Font", QString::number(cur_text->getFont().getRefID())); } else { - //Error! - abort(); + throw WritingFormatException("CT_Text类型数据缺少必要的属性Font"); } if (cur_text->sizeUsed()) { a.append("Size", QString::number(cur_text->getSize())); } else { - //Error! - abort(); + throw WritingFormatException("CT_Text类型数据缺少必要的属性Size"); } //Stroke属性不为默认值false时才显示 if (cur_text->getStroke()) { @@ -637,8 +608,7 @@ QXmlStreamAttributes getAttributes(CT_Image * cur_image) { if (!cur_image->getResourceID().isNull()) { a.append("ResourceID", QString::number(cur_image->getResourceID().getRefID())); } else { - //Error! - abort(); + throw WritingFormatException("CT_Image类型数据缺少必要的属性ResourceID"); } if (!cur_image->getSubstitution().isNull()) { a.append("Substitution", QString::number(cur_image->getSubstitution().getRefID())); @@ -650,8 +620,7 @@ QXmlStreamAttributes getAttributes(CT_ColorSpace * cur_colorspace) { if (!cur_colorspace->getType().isNull()) { a.append("Type", cur_colorspace->getType()); } else { - //Error! - abort(); + throw WritingFormatException("CT_ColorSpace类型数据缺少必要的属性Type"); } if (cur_colorspace->getBitsPerComponent() != 8) { a.append("BitsPerComponent", QString::number(cur_colorspace->getBitsPerComponent())); @@ -695,8 +664,7 @@ QXmlStreamAttributes getAttributes(CT_Font * cur_font) { if (!cur_font->getFontName().isNull()) { a.append("FontName", cur_font->getFontName()); } else { - //Error! - abort(); + throw WritingFormatException("CT_Font类型数据缺少必要的属性FontName"); } if (!cur_font->getFamilyName().isNull()) { a.append("FamilyName", cur_font->getFamilyName()); @@ -718,3 +686,15 @@ QXmlStreamAttributes getAttributes(CT_Font * cur_font) { } return a; } + +void OFDWriter::makePath(ST_Loc path) { + QString path_str = path.getPath(); + int n = 0; + while (path_str[path_str.length() - n - 1] != '\\') + n++; + path_str.chop(n); + //qDebug() << path_str; + if (!QDir().mkpath(path_str)) { + throw WritingFileException("无法创建文件路径: " + path.getPath()); + } +} diff --git a/ofdEditor/ofd/ofd_writer.h b/ofdEditor/ofd/ofd_writer.h index 4fda0a2..667bec0 100644 --- a/ofdEditor/ofd/ofd_writer.h +++ b/ofdEditor/ofd/ofd_writer.h @@ -11,7 +11,7 @@ #include "DataTypes/page/Page.h" #include "DataTypes/basic_datatype.h" #include "DataTypes/Color/CT_Color.h" -#include "ofd_global.h" +#include "ofdexceptions.h" class OFDSHARED_EXPORT OFDWriter { @@ -20,7 +20,7 @@ private: ST_Loc current_path; //当前文档节点的路径 QFile * current_file; //当前输出的文件 QXmlStreamWriter writer; - + void makePath(ST_Loc path); void createFile(); void writeOFD(); void writeDocument(Document * data); diff --git a/ofdEditor/ofd/ofdexceptions.cpp b/ofdEditor/ofd/ofdexceptions.cpp new file mode 100644 index 0000000..842968f --- /dev/null +++ b/ofdEditor/ofd/ofdexceptions.cpp @@ -0,0 +1,84 @@ +#include "ofdexceptions.h" + +Exception::Exception(QString _msg) + : msg(_msg) {} + +ParsingException::ParsingException(QString _msg) + : Exception(_msg) {} + +ParsingFileException::ParsingFileException(QString _msg) + : ParsingException(_msg) {} + +ParsingFormatException::ParsingFormatException(QString _msg) + : ParsingException(_msg) {} + +QString Exception::getMessage() { + return msg; +} + +QString ParsingException::getMessage() { + return Exception::getMessage(); +} + +QString ParsingFileException::getMessage() { + return "OFD Parsing File Exception:\n" + ParsingException::getMessage(); +} + +QString ParsingFormatException::getMessage() { + return "OFD Parsing Format Exception:\n" + ParsingException::getMessage(); +} + +WritingException::WritingException(QString _msg) + : Exception(_msg) {} + +WritingFileException::WritingFileException(QString _msg) + : WritingException(_msg) {} + +WritingFormatException::WritingFormatException(QString _msg) + : WritingException(_msg) {} + +QString WritingException::getMessage() { + return Exception::getMessage(); +} + +QString WritingFileException::getMessage() { + return "OFD Writing File Exception: " + WritingException::getMessage(); +} + +QString WritingFormatException::getMessage() { + return "OFD Writing Format Exception: " + WritingException::getMessage(); +} + +ParsingIDException::ParsingIDException(QString _msg) + : ParsingException(_msg) {} + +QString ParsingIDException::getMessage() { + return "OFD Parsing ID Exception: " + ParsingException::getMessage(); +} + +EditingException::EditingException(QString _msg) + : Exception(_msg) {} + +QString EditingException::getMessage() { + return Exception::getMessage(); +} + +InvalidIDException::InvalidIDException(QString _msg) + : EditingException(_msg) {} + +QString InvalidIDException::getMessage() { + return "OFD Editing Exception : Invalid ID. \n " + EditingException::getMessage(); +} + +InvalidValueException::InvalidValueException(QString _msg) + : EditingException(_msg) {} + +QString InvalidValueException::getMessage() { + return "OFD Editing Exception : Invalid Value. \n " + EditingException::getMessage(); +} + +IllegalAccessException::IllegalAccessException(QString _msg) + : EditingException(_msg) {} +QString IllegalAccessException::getMessage() { + return "OFD Illegal Access Exception: Try To Access Uninitialized Value. \n" + EditingException::getMessage(); +} diff --git a/ofdEditor/ofd/ofdexceptions.h b/ofdEditor/ofd/ofdexceptions.h new file mode 100644 index 0000000..bae9710 --- /dev/null +++ b/ofdEditor/ofd/ofdexceptions.h @@ -0,0 +1,83 @@ +#ifndef OFDEXCEPTIONS_H +#define OFDEXCEPTIONS_H +#include +#include "ofd_global.h" + +class OFDSHARED_EXPORT Exception +{ + QString msg; +public: + Exception(QString _msg); + virtual QString getMessage(); +}; + +class OFDSHARED_EXPORT ParsingException : public Exception { +public: + ParsingException(QString _msg); + QString getMessage(); +}; + + +class OFDSHARED_EXPORT ParsingFileException : public ParsingException { + +public: + ParsingFileException(QString _msg); + QString getMessage(); +}; + +class OFDSHARED_EXPORT ParsingFormatException : public ParsingException { + +public: + ParsingFormatException(QString _msg); + QString getMessage(); +}; + +class OFDSHARED_EXPORT WritingException : public Exception { +public: + WritingException(QString _msg); + QString getMessage(); +}; + +class OFDSHARED_EXPORT WritingFormatException : public WritingException { +public: + WritingFormatException(QString _msg); + QString getMessage(); +}; + +class OFDSHARED_EXPORT WritingFileException : public WritingException { +public: + WritingFileException(QString _msg); + QString getMessage(); +}; + +class OFDSHARED_EXPORT ParsingIDException : public ParsingException { +public: + ParsingIDException(QString _msg); + QString getMessage(); +}; + +class OFDSHARED_EXPORT EditingException : public Exception { +public: + EditingException(QString _msg); + QString getMessage(); +}; + +class OFDSHARED_EXPORT InvalidIDException : public EditingException { +public: + InvalidIDException(QString _msg); + QString getMessage(); +}; + +class OFDSHARED_EXPORT InvalidValueException : public EditingException { +public: + InvalidValueException(QString _msg); + QString getMessage(); +}; + +class OFDSHARED_EXPORT IllegalAccessException : public EditingException { +public: + IllegalAccessException(QString _msg); + QString getMessage(); +}; + +#endif // OFDEXCEPTIONS_H diff --git a/ofdEditor/ofdEditor.pro b/ofdEditor/ofdEditor.pro index c2dec3c..7f103f5 100644 --- a/ofdEditor/ofdEditor.pro +++ b/ofdEditor/ofdEditor.pro @@ -12,9 +12,9 @@ TEMPLATE = subdirs # 工程类型,多工程 SUBDIRS += \ ofd \ model \ - start \ +# start \ #test_chaoqun\ -# test_pan \ + test_pan \ #test_yang CONFIG += ordered warn_on qt diff --git a/ofdEditor/test_pan/main.cpp b/ofdEditor/test_pan/main.cpp index e7c7511..0258359 100644 --- a/ofdEditor/test_pan/main.cpp +++ b/ofdEditor/test_pan/main.cpp @@ -1,29 +1,39 @@ #include "mainwindow.h" #include -#include #include -#include "DataTypes/basic_datatype.h" -#include "ofd_parser.h" -#include "ofd_writer.h" -#include +#include "../ofd/DataTypes/basic_datatype.h" +#include "../ofd/ofd_parser.h" +#include "../ofd/ofd_writer.h" + + +//#include +//#include +//#include +//#include "../test_chaoqun/PassageMainWindow.h" +//#include "../model/Doc/DocPassage.h" +//#include "../model/Doc/DocPage.h" +//#include "../model/Doc/DocTextBlock.h" +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include using namespace std; int main(int argc, char *argv[]) { - OFDParser t("F:/第六届中软杯/OFD Document/OFD.xml"); - OFD * i = t.getData(); - OFDWriter w(i, "F:/第六届中软杯/writing_test/"); -// QString str1("F:/第六届中软杯/OFD Document/OFD.xml"); -// QString str2("F:/第六届中软杯/OFD Document/"); -// ST_Loc t1("1",str1), t2("1", str2); -// qDebug() << t1.getRelativePath(t2); -// QString sb; -// qDebug() << sb.isNull(); -// qDebug() << i->getDocuments()->at(0)->getPublicRes()->at(0)->getBaseLoc().getPath(); -// qDebug() << i->getDocuments()->at(0)->getPages()->getPages()->at(1)->getBaseLoc(); -// qDebug() << i->getDocuments()->at(0)->getPages()->getPages()->at(1)->getContent()->at(0)->getTextObject()->size(); -// for (int k = 0; k < i->getDocuments()->at(0)->getPages()->getPages()->at(1)->getContent()->at(0)->getTextObject()->size(); k++) -// qDebug() << i->getDocuments()->at(0)->getPages()->getPages()->at(1)->getContent()->at(0)->getTextObject()->at(k)->getTextCode()->getText(); - return 0; + try { + OFDParser t("F:/第六届中软杯/OFD Document/OFD.xml"); + OFD * i = t.getData(); + qDebug() << "从Document_0中收集到的ID数量: " << i->getDocuments()->at(0)->getIDTable()->size(); + qDebug() << "Document.xml中的MaxUnitID属性值: " << i->getDocuments()->at(0)->getCommonData()->getMaxUnitID(); +// OFDWriter w(i, "F:/第六届中软杯/OFD Writing Test 2/"); + } catch (Exception e) { + qDebug() << e.getMessage(); + } } diff --git a/ofdEditor/test_pan/mainwindow.cpp b/ofdEditor/test_pan/mainwindow.cpp index 494750e..469836b 100644 --- a/ofdEditor/test_pan/mainwindow.cpp +++ b/ofdEditor/test_pan/mainwindow.cpp @@ -7,21 +7,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { -// file = new QFile("F:\\第六届中软杯\\OFD Document\\Doc_0\\Pages\\Page_0\\Content.xml"); -// if (!file->open(QFile::ReadOnly | QFile::Text)) { -// QMessageBox::critical(this, tr("Error"), -// tr("Cannot read file %1").arg("F:\\第六届中软杯\\OFD Document\\Doc_0\\Pages\\Page_0\\Content.xml")); -// } -// reader.setDevice(file); -// reader.readNext(); -// if (reader.isStartDocument()) { -// qDebug() << "XML Version : " << reader.documentVersion() -// << " XML Encoding : " << reader.documentEncoding() << endl; -// readPage(); -// } else { -// qDebug() << "An error has occured. " << endl; -// abort(); -// } + } MainWindow::~MainWindow() @@ -29,353 +15,3 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::readPage() { //读取页面 -// Q_ASSERT(reader.isStartDocument()); -// reader.setNamespaceProcessing(false); -// reader.readNext(); -// if (reader.isStartElement() && reader.name() == "Page" ) { -// while (!reader.isEndElement() || reader.name() != "Page") -// { -// reader.readNext(); -// if (reader.isStartElement() && reader.name() == "Area") -// readPageArea(); -// else if (reader.isStartElement() && reader.name() == "Content") -// readContent(); -// } -// } -// else { -// qDebug() << "The page file doesn't start with a tag." << endl; -// abort(); -// } -} - -void MainWindow::readPageArea() { //读取页面区域信息 - Q_ASSERT(reader.isStartElement() && reader.name() == "Area"); - while (!reader.isEndElement() || reader.name() != "Area") - { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "PhysicalBox") { - QString str = reader.readElementText(); - QStringList strl = str.split(" "); - qDebug() << strl.at(0).toDouble() << " "; - qDebug() << strl.at(1).toDouble() << " "; - qDebug() << strl.at(2).toDouble() << " "; - qDebug() << strl.at(3).toDouble() << "\n"; - } - } -} - -void MainWindow::readContent() { //读取页面内容 - Q_ASSERT(reader.isStartElement() && reader.name() == "Content"); - while (!reader.isEndElement() || reader.name() != "Content") - { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "Layer") { //层 - while (!reader.isEndElement() || reader.name() != "Layer") { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "TextObject") { //文字图元对象 - QXmlStreamAttributes textobject_attributes = reader.attributes(); //属性 - if (textobject_attributes.hasAttribute("ID")) - { - qDebug() << textobject_attributes.value("ID") << " "; - } - if (textobject_attributes.hasAttribute("Boundary")) - { - qDebug() << textobject_attributes.value("Boundary") << " "; - } - if (textobject_attributes.hasAttribute("Font")) - { - qDebug() << textobject_attributes.value("Font") << " "; - } - if (textobject_attributes.hasAttribute("Size")) - { - qDebug() << textobject_attributes.value("Size") << "\n"; - } - while (!reader.isEndElement() || reader.name() != "TextObject") { - reader.readNext(); - //FillColor待实现 - if (reader.isStartElement() && reader.name() == "TextCode") - { - QXmlStreamAttributes textcode_attributes = reader.attributes(); - if (textcode_attributes.hasAttribute("X")) - { - qDebug() << textcode_attributes.value("X") << " "; - } - if (textcode_attributes.hasAttribute("Y")) - { - qDebug() << textcode_attributes.value("Y") << " "; - } - if (textcode_attributes.hasAttribute("DeltaX")) - { - qDebug() << textcode_attributes.value("DeltaX") << " "; - } - if (textcode_attributes.hasAttribute("DeltaY")) - { - qDebug() << textcode_attributes.value("DeltaY") << " "; - } - QString str = reader.readElementText(); - qDebug() << str << "\n"; - } - } - - } - } - } - } -} - -void MainWindow::start() -{ - QFile ofd_file("F:\\第六届中软杯\\OFD Document\\OFD.xml"); - if (!ofd_file.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::critical(this, tr("Error"), - tr("Cannot read file %1").arg(ofd_file.fileName())); - } - reader.setDevice(&ofd_file); - reader.readNext(); - if (reader.isStartDocument()) { - qDebug() << "XML Version : " << reader.documentVersion() - << " XML Encoding : " << reader.documentEncoding() << endl; - readOFD(); - ofd_file.close(); - } else { - qDebug() << "An error has occured. " << endl; - abort(); - } -} - -void MainWindow::readOFD() -{ - vector doc_root_list; - Q_ASSERT(reader.isStartDocument()); - reader.setNamespaceProcessing(false); - while (!reader.isEndDocument()) { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "OFD") { - QXmlStreamAttributes ofd_attributes = reader.attributes(); - qDebug() << "DocType: " << ofd_attributes.value("DocType") << " "; - qDebug() << "Version: " << ofd_attributes.value("Version") << "\n"; - while (!reader.isEndElement() || reader.name() != "OFD") { - reader.readNext(); - //qDebug() << reader.name(); - if (reader.isStartElement() && reader.name() == "DocBody") { - while (!reader.isEndDocument() || reader.name() != "DocBody") { - reader.readNext(); - if (reader.name() == "DocInfo") { - while (!reader.isEndElement() || reader.name() != "DocInfo") { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "DocID") { - qDebug() << "DocID: " << reader.readElementText() << "\n"; - } else if (reader.isStartElement() && reader.name() == "CreationDate") { - qDebug() << "CreationDate: " << reader.readElementText() << "\n"; - } else if (reader.isStartElement() && reader.name() == "ModDate") { - qDebug() << "ModDate: " << reader.readElementText() << "\n"; - } else if (reader.isStartElement() && reader.name() == "Title") { - qDebug() << "Title: " << reader.readElementText() << "\n"; - } else if (reader.isStartElement() && reader.name() == "CustomDatas") { - qDebug() << "自定义数据元: "; - while (!reader.isEndElement() || reader.name() != "CustomDatas") { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "CustomData") { - QXmlStreamAttributes customtag_attributes = reader.attributes(); - qDebug() << customtag_attributes.value("Name") << ": " << reader.readElementText() << "\n"; - } - } - } - } - } - } - reader.readNextStartElement(); - if (reader.name() == "DocRoot") { - // qDebug() << reader.readElementText() << "\n"; - doc_root_list.push_back(reader.readElementText()); - } - } - } - vector::iterator iter; - for (iter = doc_root_list.begin(); iter != doc_root_list.end(); iter++) - { - QString dir = "F:\\第六届中软杯\\OFD Document\\" + *iter; - //qDebug() << dir << "\n"; - dir.replace("/", "\\"); - //qDebug() << dir << "\n"; - QFile document_file(dir); - if (!document_file.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::critical(this, tr("Error"), - tr("Cannot read file %1").arg(document_file.fileName())); - } - QIODevice * current_device = reader.device(); - reader.setDevice(&document_file); - reader.readNext(); - if (reader.isStartDocument()) { - qDebug() << "XML Version : " << reader.documentVersion() - << " XML Encoding : " << reader.documentEncoding() << endl; - readDocument(); - reader.setDevice(current_device); - document_file.close(); - } - } - } - - } -} - -void MainWindow::readDocument() -{ - Q_ASSERT(reader.isStartDocument()); - int debug_cnt = 0; - vector public_res_list; - vector page_list; - QString custom_tag_dir; - //qDebug() << "Entering readDocument module..." << "\n"; - reader.readNextStartElement(); - if (reader.name() == "Document") { - //qDebug() << "Entering Point 1..." << "\n"; - while (!reader.isEndElement() || reader.name() != "Document") { - reader.readNext(); - //qDebug() << reader.isStartElement() << reader.name() << "\n"; - if (reader.isStartElement() && reader.name() == "CommonData") { - while (!reader.isEndElement() || reader.name() != "CommonData") { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "MaxUnitID") { - qDebug() << "MaxUnitId: " << reader.readElementText(); - } else if (reader.isStartElement() && reader.name() == "PageArea") { - while (!reader.isEndElement() || reader.name() != "PageArea") { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "PhysicalBox") { - qDebug() << "PhysicalBox: " << "\n"; - QString str = reader.readElementText(); - QStringList strl = str.split(" "); - qDebug() << strl.at(0).toDouble() << " "; - qDebug() << strl.at(1).toDouble() << " "; - qDebug() << strl.at(2).toDouble() << " "; - qDebug() << strl.at(3).toDouble() << "\n"; - } - //其他区域 to be implemented - } - } else if (reader.isStartElement() && reader.name() == "PublicRes") { - public_res_list.push_back(reader.readElementText()); - } - } - } else if (reader.isStartElement() && reader.name() == "Pages") { - while (!reader.isEndElement() || reader.name() != "Pages") { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "Page") { - QXmlStreamAttributes pages_attributes = reader.attributes(); - page_list.push_back(pages_attributes.value("BaseLoc").toString()); - } - } - } else if (reader.isStartElement() && reader.name() == "Outlines") { - //To be implemented - } else if (reader.isStartElement() && reader.name() == "CustomTags") { - //qDebug() << reader.readElementText() << "\n"; - custom_tag_dir = "F:\\第六届中软杯\\OFD Document\\Doc_0\\" + reader.readElementText(); //!!!!!!! - } - } - } - custom_tag_dir.replace("/", "\\"); - QFile custom_tag_file(custom_tag_dir); - qDebug() << custom_tag_file.fileName() << "\n"; - if (!custom_tag_file.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::critical(this, tr("Error"), - tr("Cannot read file %1").arg(custom_tag_file.fileName())); - } - QIODevice * current_device = reader.device(); - reader.setDevice(&custom_tag_file); - reader.readNext(); - if (reader.isStartDocument()) { - qDebug() << "XML Version : " << reader.documentVersion() - << " XML Encoding : " << reader.documentEncoding() << "\n"; - readCustomTags(); - reader.setDevice(current_device); - custom_tag_file.close(); - } - vector::iterator iter; - for (iter = public_res_list.begin(); iter != public_res_list.end(); iter++) - { - QString dir = "F:\\第六届中软杯\\OFD Document\\Doc_0\\" + *iter; - dir.replace("/", "\\"); - QFile public_res_file(dir); - qDebug() << public_res_file.fileName() << "\n"; - if (!public_res_file.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::critical(this, tr("Error"), - tr("Cannot read file %1").arg(public_res_file.fileName())); - } - QIODevice * current_device = reader.device(); - reader.setDevice(&public_res_file); - reader.readNext(); - if (reader.isStartDocument()) { - qDebug() << "XML Version : " << reader.documentVersion() - << " XML Encoding : " << reader.documentEncoding() << endl; - readPublicRes(); - reader.setDevice(current_device); - public_res_file.close(); - } - } - - for (iter = page_list.begin(); iter != page_list.end(); iter++) - { - //qDebug() << *iter << "\n"; - QString dir = "F:\\第六届中软杯\\OFD Document\\Doc_0\\" + *iter; - dir.replace("/", "\\"); - QFile page_file(dir); - qDebug() << page_file.fileName() << "\n"; - if (!page_file.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::critical(this, tr("Error"), - tr("Cannot read file %1").arg(page_file.fileName())); - } - QIODevice * current_device = reader.device(); - reader.setDevice(&page_file); - reader.readNext(); - if (reader.isStartDocument()) { - qDebug() << "XML Version : " << reader.documentVersion() - << " XML Encoding : " << reader.documentEncoding() << endl; - readPage(); - reader.setDevice(current_device); - page_file.close(); - } - } -} - -void MainWindow::readCustomTags() -{ - //to be implemented -} - -void MainWindow::readPublicRes() -{ - Q_ASSERT(reader.isStartDocument()); - reader.readNextStartElement(); - if (reader.name() == "Res") { - QXmlStreamAttributes res_attributes = reader.attributes(); - qDebug() << "BaseLoc: " << res_attributes.value("BaseLoc") << endl; - while (!reader.isEndElement() || reader.name() != "Res") { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "Fonts") { - while (!reader.isEndElement() || reader.name() != "Fonts") { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "Font") { - QXmlStreamAttributes font_attributes = reader.attributes(); - if (font_attributes.hasAttribute("FontName")) - qDebug() << "FontName: " << font_attributes.value("FontName"); - if (font_attributes.hasAttribute("FamilyName")) - qDebug() << "FamilyName: " << font_attributes.value("FamilyName"); - //more attributes to be implemented - } - } - } else if (reader.isStartElement() && reader.name() == "ColorSpaces") { - while (!reader.isEndElement() || reader.name() != "ColorSpaces") { - reader.readNext(); - if (reader.isStartElement() && reader.name() == "ColorSpace") { - QXmlStreamAttributes colorspace_attributes = reader.attributes(); - if (colorspace_attributes.hasAttribute("FontName")) - qDebug() << "ID: " << colorspace_attributes.value("ID"); - if (colorspace_attributes.hasAttribute("FamilyName")) - qDebug() << "Type: " << colorspace_attributes.value("Type"); - //more attributes to be implemented - } - } - } //more resource types to be implemented - } - } -} diff --git a/ofdEditor/test_pan/ofd_parser.cpp b/ofdEditor/test_pan/ofd_parser.cpp index ea62432..e4aa31a 100644 --- a/ofdEditor/test_pan/ofd_parser.cpp +++ b/ofdEditor/test_pan/ofd_parser.cpp @@ -10,7 +10,7 @@ void OFDParser::openFile() { QFile ofd_file(current_path.getPath()); if (!ofd_file.open(QFile::ReadOnly | QFile::Text)) { //检查文件是否存在&正常打开 //出现异常!!!to be implemented - qDebug() << "xml文件打开出现错误。" << endl; +// qDebug() << "xml文件打开出现错误。" << endl; abort(); } if (document->setContent(&ofd_file, //解析OFD文档并将树状内容存在document文件中 @@ -21,7 +21,7 @@ void OFDParser::openFile() { ofd_file.close(); } else { //出现异常!!!to be implemented - qDebug() << "xml解析出现错误。" << endl; +// qDebug() << "xml解析出现错误。" << endl; abort(); } } @@ -94,7 +94,7 @@ OFD * OFDParser::readOFD() { } } else { - qDebug() << "非法的OFD文档格式。" << endl; +// qDebug() << "非法的OFD文档格式。" << endl; abort(); } if (ofd_data) { diff --git a/ofdEditor/test_pan/test_pan.pro b/ofdEditor/test_pan/test_pan.pro index 54f9226..b1265c1 100644 --- a/ofdEditor/test_pan/test_pan.pro +++ b/ofdEditor/test_pan/test_pan.pro @@ -27,45 +27,45 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += \ main.cpp \ mainwindow.cpp \ - ofd_parser.cpp \ - DataTypes/basic_datatypes.cpp \ - ofd_writer.cpp +# ofd_parser.cpp \ +# DataTypes/basic_datatypes.cpp \ +# ofd_writer.cpp HEADERS += \ mainwindow.h \ - DataTypes/basic_datatype.h \ +# DataTypes/basic_datatype.h \ # DataTypes/CT_Action.h \ # DataTypes/Color/CT_AxialShd.h \ - DataTypes/Color/CT_Color.h \ - DataTypes/Color/CT_ColorSpace.h \ +# DataTypes/Color/CT_Color.h \ +# DataTypes/Color/CT_ColorSpace.h \ # DataTypes/Color/CT_Pattern.h \ # DataTypes/Color/CT_RadialShd.h \ - DataTypes/document/CT_CommonData.h \ - DataTypes/document/CT_DocInfo.h \ - DataTypes/document/CT_OutlineElem.h \ - DataTypes/document/CT_Outlines.h \ - DataTypes/document/DocBody.h \ - DataTypes/document/Document.h \ - DataTypes/document/OFD.h \ +# DataTypes/document/CT_CommonData.h \ +# DataTypes/document/CT_DocInfo.h \ +# DataTypes/document/CT_OutlineElem.h \ +# DataTypes/document/CT_Outlines.h \ +# DataTypes/document/DocBody.h \ +# DataTypes/document/Document.h \ +# DataTypes/document/OFD.h \ # DataTypes/image/CT_Clip.h \ - DataTypes/image/CT_DrawParam.h \ - DataTypes/image/CT_GraphicUnit.h \ - DataTypes/image/CT_Image.h \ - DataTypes/image/CT_Path.h \ - DataTypes/page/CT_Layer.h \ - DataTypes/page/CT_PageArea.h \ - DataTypes/page/CT_PageBlock.h \ - DataTypes/page/CT_Pages.h \ - DataTypes/page/Page.h \ - ofd_parser.h \ - DataTypes/document/res.h\ +# DataTypes/image/CT_DrawParam.h \ +# DataTypes/image/CT_GraphicUnit.h \ +# DataTypes/image/CT_Image.h \ +# DataTypes/image/CT_Path.h \ +# DataTypes/page/CT_Layer.h \ +# DataTypes/page/CT_PageArea.h \ +# DataTypes/page/CT_PageBlock.h \ +# DataTypes/page/CT_Pages.h \ +# DataTypes/page/Page.h \ +# ofd_parser.h \ +# DataTypes/document/res.h\ # DataTypes/text/CT_CGTransform.h \ - DataTypes/text/CT_Font.h \ - DataTypes/text/CT_Text.h \ - DataTypes/text/TextCode.h \ +# DataTypes/text/CT_Font.h \ +# DataTypes/text/CT_Text.h \ +# DataTypes/text/TextCode.h \ ofd_global.h \ - ofd_writer.h \ - DataTypes/document/CustomTags.h +# ofd_writer.h \ +# DataTypes/document/CustomTags.h DESTDIR = ../bin # 生成文件在这 MOC_DIR = ./moc # Q_OBJECT 类转换后的文件 @@ -86,6 +86,6 @@ unix{ } win32{ - #LIBS += ../bin/model.lib \ - # ../bin/ofd.lib + LIBS += ../bin/model.lib \ + ../bin/ofd.lib } -- Gitee From 822836266715b1365d9ad01a7854deaaa812311a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E8=B6=85=E7=BE=A4?= Date: Sat, 27 May 2017 09:24:25 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=96=87=E5=AD=97=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=EF=BC=8C=E6=96=87=E6=9C=AC=E6=A1=86=E6=B7=B1=E5=BA=A6=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdEditor/model/Convert/OFD_DocConvertor.cpp | 76 +++++++++++++------ ofdEditor/model/Doc/DocBlock.cpp | 30 ++++++++ ofdEditor/model/Doc/DocBlock.h | 3 + ofdEditor/ofd/DataTypes/document/CT_DocInfo.h | 24 ++++++ ofdEditor/ofd/DataTypes/document/ct_docinfo.h | 24 ++++++ ofdEditor/ofdEditor.pro | 4 +- 6 files changed, 134 insertions(+), 27 deletions(-) diff --git a/ofdEditor/model/Convert/OFD_DocConvertor.cpp b/ofdEditor/model/Convert/OFD_DocConvertor.cpp index 2b45ab5..b354be2 100644 --- a/ofdEditor/model/Convert/OFD_DocConvertor.cpp +++ b/ofdEditor/model/Convert/OFD_DocConvertor.cpp @@ -34,18 +34,20 @@ DocPassage *OFD_DocConvertor::ofd_to_doc(OFD *ofd) passage = new DocPassage(); // version - passage->setVersion(ofd->version); - passage->setDocType(ofd->doc_type); + passage->setVersion(ofd->getOfdVersion()); + passage->setDocType(ofd->getDocType()); - DocBody * docBody = (*ofd->docbodys)[0]; // DocBody - passage->setDocInfo(*(docBody->doc_info)); + QVector * bodys = ofd->getDocBodies(); + DocBody * docBody = (*bodys)[0]; // DocBody + passage->setDocInfo(*(docBody->getDocInfo())); - Document * document = (*ofd->docs)[0]; // Document + Document * document = (*(ofd->getDocuments()))[0]; // Document - CT_CommonData * commonData = document->getCommonData(); // 获取common_data +// CT_CommonData * commonData = document->getCommonData(); // 获取common_data // CT_Pages pages = document->pages; // 获得文档中的页 - QVector * pages = document->pages->pages; // 获得页属性 + QVector * pages = document->getPages()->getPages(); // 获得页属性 + for(int i = 0; i length(); i++) { @@ -71,9 +73,12 @@ DocPage *OFD_DocConvertor::buildDocPage(Page *ct_page) if(ct_page->area != NULL) { // 如果定义了纸张尺寸 - ST_Box physical_box = ct_page->area->physical_box; - page = new DocPage(physical_box.getDeltaX(), - physical_box.getDeltaY(), + + CT_PageArea* area = ct_page->getArea(); // 获得空间 + + // 物理空间 + page = new DocPage(area->getPhysicalBox().getDeltaX(), + area->getPhysicalBox().getDeltaY(), 1.0); // 设置纸张大小 } else @@ -84,7 +89,7 @@ DocPage *OFD_DocConvertor::buildDocPage(Page *ct_page) page->setVisible(false); // 先隐藏显示 // 将每一层加入到页中 - QVector* layers = ct_page->content; // 获得文章中的层信息 + QVector* layers = ct_page->getContent(); // 获得文章中的层信息 for(int i = 0; i < layers->size(); i++) { CT_Layer* layer = (*layers)[i]; @@ -133,24 +138,42 @@ void OFD_DocConvertor::insertLayer(DocPage *page, CT_Layer *layer) * @return 返回值 * @date 2017/xx/xx */ -void OFD_DocConvertor::insertPageBlock(DocPage *page, CT_Layer *layer, CT_PageBlock *pageBlock) +void OFD_DocConvertor::insertPageBlock(DocPage *page, + CT_Layer *layer, + CT_PageBlock *pageBlock) { - CT_Layer::LayerType cttype = layer->type; // 首先获得层 + QString cttype = layer->getType(); // 首先获得层 + DocPage::Layer doctype; - switch (cttype) { - case CT_Layer::Foreground: +// switch (cttype) { +// case "Foreground": +// doctype = DocPage::Foreground; +// break; +// case "Body": +// doctype = DocPage::Body; +// break; +// case "Background": +// doctype = DocPage::Background; +// default: +// break; +// } + + // 获得关于层的概念 + if(cttype == "Foreground") + { doctype = DocPage::Foreground; - break; - case CT_Layer::Body: + } + else if(cttype == "Body") + { doctype = DocPage::Body; - break; - case CT_Layer::Background: + } + else if(cttype == "Background") + { doctype = DocPage::Background; - default: - break; } + // 处理 CT_Text QVector * texts = pageBlock->getTextObject(); for(int i = 0; ilength(); i++) @@ -179,9 +202,12 @@ void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Tex { // qDebug() << "execute insert CT_Text"; - TextCode* textCode = text->text_code; // 获得text_code; + QVector* textCodes = text->getTextCode(); + + TextCode* textCode = (*textCodes)[0]; // 获得text_code[0]; + // 先简单点 - QString content = textCode->text; // 文本内容 + QString content = textCode->getText(); // 文本内容 // qDebug() << "insert Content:" << content; @@ -189,7 +215,7 @@ void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Tex DocBlock *block = new DocBlock(); block->setWidget(textBlock); - ST_Box box = text->boundary; + ST_Box box = text->getBoundary(); block->resize(UnitTool::mmToPixel(box.getDeltaX()), UnitTool::mmToPixel(box.getDeltaY())); block->setPos(UnitTool::mmToPixel(box.getX()), @@ -215,7 +241,7 @@ void OFD_DocConvertor::insertCT_Text(DocPage *page, DocPage::Layer layer, CT_Tex QFont font = charFormat.font(); // 字体 // 字号 - font.setPixelSize(UnitTool::mmToPixel(text->size)); // 字号 + font.setPixelSize(UnitTool::mmToPixel(text->getSize())); // 字号 // 上下间距 blockFormat.setTopMargin(0); diff --git a/ofdEditor/model/Doc/DocBlock.cpp b/ofdEditor/model/Doc/DocBlock.cpp index 8de6f3b..d3b297f 100644 --- a/ofdEditor/model/Doc/DocBlock.cpp +++ b/ofdEditor/model/Doc/DocBlock.cpp @@ -84,6 +84,19 @@ void DocBlock::resize(const QSizeF &size) this->blockSize.setHeight(size.height()); } +/** + * @Author Chaoqun + * @brief 设置Z坐标的同时存下记录 + * @param 参数 + * @return 返回值 + * @date 2017/05/27 + */ +void DocBlock::setZValue(qreal z) +{ + QGraphicsProxyWidget::setZValue(z); + this->realZValue = z; // 设置本地记录 +} + /** * @Author Chaoqun @@ -105,18 +118,35 @@ void DocBlock::paint(QPainter *painter, } +/** + * @Author Chaoqun + * @brief 被聚焦后的操作 + * @param QFocusEvent *event + * @return void + * @date 2017/05/27 + */ void DocBlock::focusInEvent(QFocusEvent *event) { QGraphicsProxyWidget::focusInEvent(event); this->isFocused = true; + + QGraphicsProxyWidget::setZValue(2000); // 临时呼叫到最高层 this->update(); // 呼叫更新 } +/** + * @Author Chaoqun + * @brief 聚焦移出事件响应 + * @param QFocusEvent *event + * @return void + * @date 2017/05/27 + */ void DocBlock::focusOutEvent(QFocusEvent *event) { QGraphicsProxyWidget::focusOutEvent(event); this->isFocused = false; + QGraphicsProxyWidget::setZValue(this->realZValue); // 还原到真实的Z坐标 this->update(); } diff --git a/ofdEditor/model/Doc/DocBlock.h b/ofdEditor/model/Doc/DocBlock.h index 9521d01..0e70625 100644 --- a/ofdEditor/model/Doc/DocBlock.h +++ b/ofdEditor/model/Doc/DocBlock.h @@ -34,6 +34,8 @@ public: void resize(qreal w, qreal h); // 继承函数 void resize(const QSizeF &size); // 继承函数 + void setZValue(qreal z); // 继承该函数 + protected: void paint(QPainter *painter, @@ -60,6 +62,7 @@ private: bool isFocused; // 是否被聚焦 bool blockIsResizing; // 是否正在改变大小 bool isInResizeArea(const QPointF& pos); // 检查鼠标是否在重置大小区域 + qreal realZValue; //真是的z值 public: RectAdjustStatus currentStatus(const QPointF& pos); // 鼠标所在位置可以进行什么调整 diff --git a/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h b/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h index ba75f78..1c3b85d 100644 --- a/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h +++ b/ofdEditor/ofd/DataTypes/document/CT_DocInfo.h @@ -57,6 +57,30 @@ public: delete custom_datas; } +/** + * @Author Chaoqun + * @brief 深拷贝函数,暂时没有去管custom_data + * @param CT_DocInfo &info + * @return void + * @date 2017/05/27 + */ + void copy(CT_DocInfo &info) + { + this->doc_id = info.doc_id; + this->title = info.title; + this->author = info.author; + this->subject = info.subject; + this->abstract = info.abstract; + this->creation_date = info.creation_date; + this->mod_date = info.mod_date; + this->doc_usage = info.doc_usage; + this->cover = info.cover; + this->creator = info.creator; + this->creator_version = info.creator_version; + + // custom_datas暂时不考虑 + } + QString getDocID() { return doc_id; } diff --git a/ofdEditor/ofd/DataTypes/document/ct_docinfo.h b/ofdEditor/ofd/DataTypes/document/ct_docinfo.h index ba75f78..1c3b85d 100644 --- a/ofdEditor/ofd/DataTypes/document/ct_docinfo.h +++ b/ofdEditor/ofd/DataTypes/document/ct_docinfo.h @@ -57,6 +57,30 @@ public: delete custom_datas; } +/** + * @Author Chaoqun + * @brief 深拷贝函数,暂时没有去管custom_data + * @param CT_DocInfo &info + * @return void + * @date 2017/05/27 + */ + void copy(CT_DocInfo &info) + { + this->doc_id = info.doc_id; + this->title = info.title; + this->author = info.author; + this->subject = info.subject; + this->abstract = info.abstract; + this->creation_date = info.creation_date; + this->mod_date = info.mod_date; + this->doc_usage = info.doc_usage; + this->cover = info.cover; + this->creator = info.creator; + this->creator_version = info.creator_version; + + // custom_datas暂时不考虑 + } + QString getDocID() { return doc_id; } diff --git a/ofdEditor/ofdEditor.pro b/ofdEditor/ofdEditor.pro index 7f103f5..c2dec3c 100644 --- a/ofdEditor/ofdEditor.pro +++ b/ofdEditor/ofdEditor.pro @@ -12,9 +12,9 @@ TEMPLATE = subdirs # 工程类型,多工程 SUBDIRS += \ ofd \ model \ -# start \ + start \ #test_chaoqun\ - test_pan \ +# test_pan \ #test_yang CONFIG += ordered warn_on qt -- Gitee