Skip to content

Commit

Permalink
Improve DOCX document importer
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkanovikov committed Dec 11, 2024
1 parent 082709c commit cdd7df8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/3rd_party/fileformats/docx_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ void DocxReader::readParagraph()

void DocxReader::readParagraphProperties(Style& style, bool allowstyles)
{
int left_indent = 0, right_indent = 0, indent = 0, top_indent = 0, bottom_indent = 0;
int left_indent = 0, right_indent = 0, text_indent = 0, indent = 0, top_indent = 0,
bottom_indent = 0;
while (m_xml.readNextStartElement()) {
const QXmlStreamAttributes& attributes = m_xml.attributes();
const auto value = attributes.value("w:val");
Expand Down Expand Up @@ -477,6 +478,10 @@ void DocxReader::readParagraphProperties(Style& style, bool allowstyles)
right_indent = pixelsFromTwips(attributes.value("w:right").toString().toInt());
style.block_format.setRightMargin(right_indent);
}
if (attributes.hasAttribute("w:firstLine")) {
text_indent = pixelsFromTwips(attributes.value("w:firstLine").toString().toInt());
style.block_format.setTextIndent(text_indent);
}
if (attributes.hasAttribute("w:hanging")) {
auto t = attributes.value("w:hanging").toString();
indent = pixelsFromTwips(attributes.value("w:hanging").toString().toInt());
Expand Down
15 changes: 8 additions & 7 deletions src/corelib/business_layer/import/abstract_document_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ TextParagraphType AbstractDocumentImporter::typeForTextCursor(const QTextCursor&
//
const QString blockText = _cursor.block().text();
const QString blockTextUppercase = TextHelper::smartToUpper(blockText);
const QString BlockTextWithoutParentheses
const QString blockTextWithoutParentheses
= _cursor.block().text().remove(kTextInParenthesisChecker);

//
Expand All @@ -495,8 +495,8 @@ TextParagraphType AbstractDocumentImporter::typeForTextCursor(const QTextCursor&
|| blockText == TextHelper::smartToUpper(blockText);
// ... блоки находящиеся в центре
bool isCentered = !blockFormat.alignment().testFlag(Qt::AlignRight)
&& (((blockFormat.leftMargin() + blockFormat.indent()) > 0
&& (blockFormat.leftMargin() + blockFormat.indent())
&& (((blockFormat.leftMargin() + blockFormat.indent() + blockFormat.textIndent()) > 0
&& (blockFormat.leftMargin() + blockFormat.indent() + blockFormat.textIndent())
> kLeftMarginDelta + _minLeftMargin)
|| (blockFormat.alignment().testFlag(Qt::AlignHCenter))
|| blockText.startsWith(kOldSchoolCenteringPrefix));
Expand All @@ -507,9 +507,10 @@ TextParagraphType AbstractDocumentImporter::typeForTextCursor(const QTextCursor&
{
//
// Самым первым пробуем определить заголовок сцены
// 1. содержит ключевые сокращения места действия
// 1. содержит ключевые сокращения места действия или начинается с номера сцены
//
if (blockTextUppercase.contains(kPlaceContainsChecker)) {
if (blockTextUppercase.contains(kPlaceContainsChecker)
|| blockTextUppercase.contains(kStartFromNumberChecker)) {
blockType = TextParagraphType::SceneHeading;
}

Expand Down Expand Up @@ -537,8 +538,8 @@ TextParagraphType AbstractDocumentImporter::typeForTextCursor(const QTextCursor&
// 1. В верхнем регистре
//
else if ((textIsUppercase
|| BlockTextWithoutParentheses
== TextHelper::smartToUpper(BlockTextWithoutParentheses))
|| blockTextWithoutParentheses
== TextHelper::smartToUpper(blockTextWithoutParentheses))
&& _lastBlockType != TextParagraphType::Character) {
blockType = TextParagraphType::Character;
}
Expand Down

0 comments on commit cdd7df8

Please sign in to comment.