Skip to content

Commit cdd7df8

Browse files
committed
Improve DOCX document importer
1 parent 082709c commit cdd7df8

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/3rd_party/fileformats/docx_reader.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@ void DocxReader::readParagraph()
446446

447447
void DocxReader::readParagraphProperties(Style& style, bool allowstyles)
448448
{
449-
int left_indent = 0, right_indent = 0, indent = 0, top_indent = 0, bottom_indent = 0;
449+
int left_indent = 0, right_indent = 0, text_indent = 0, indent = 0, top_indent = 0,
450+
bottom_indent = 0;
450451
while (m_xml.readNextStartElement()) {
451452
const QXmlStreamAttributes& attributes = m_xml.attributes();
452453
const auto value = attributes.value("w:val");
@@ -477,6 +478,10 @@ void DocxReader::readParagraphProperties(Style& style, bool allowstyles)
477478
right_indent = pixelsFromTwips(attributes.value("w:right").toString().toInt());
478479
style.block_format.setRightMargin(right_indent);
479480
}
481+
if (attributes.hasAttribute("w:firstLine")) {
482+
text_indent = pixelsFromTwips(attributes.value("w:firstLine").toString().toInt());
483+
style.block_format.setTextIndent(text_indent);
484+
}
480485
if (attributes.hasAttribute("w:hanging")) {
481486
auto t = attributes.value("w:hanging").toString();
482487
indent = pixelsFromTwips(attributes.value("w:hanging").toString().toInt());

src/corelib/business_layer/import/abstract_document_importer.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ TextParagraphType AbstractDocumentImporter::typeForTextCursor(const QTextCursor&
476476
//
477477
const QString blockText = _cursor.block().text();
478478
const QString blockTextUppercase = TextHelper::smartToUpper(blockText);
479-
const QString BlockTextWithoutParentheses
479+
const QString blockTextWithoutParentheses
480480
= _cursor.block().text().remove(kTextInParenthesisChecker);
481481

482482
//
@@ -495,8 +495,8 @@ TextParagraphType AbstractDocumentImporter::typeForTextCursor(const QTextCursor&
495495
|| blockText == TextHelper::smartToUpper(blockText);
496496
// ... блоки находящиеся в центре
497497
bool isCentered = !blockFormat.alignment().testFlag(Qt::AlignRight)
498-
&& (((blockFormat.leftMargin() + blockFormat.indent()) > 0
499-
&& (blockFormat.leftMargin() + blockFormat.indent())
498+
&& (((blockFormat.leftMargin() + blockFormat.indent() + blockFormat.textIndent()) > 0
499+
&& (blockFormat.leftMargin() + blockFormat.indent() + blockFormat.textIndent())
500500
> kLeftMarginDelta + _minLeftMargin)
501501
|| (blockFormat.alignment().testFlag(Qt::AlignHCenter))
502502
|| blockText.startsWith(kOldSchoolCenteringPrefix));
@@ -507,9 +507,10 @@ TextParagraphType AbstractDocumentImporter::typeForTextCursor(const QTextCursor&
507507
{
508508
//
509509
// Самым первым пробуем определить заголовок сцены
510-
// 1. содержит ключевые сокращения места действия
510+
// 1. содержит ключевые сокращения места действия или начинается с номера сцены
511511
//
512-
if (blockTextUppercase.contains(kPlaceContainsChecker)) {
512+
if (blockTextUppercase.contains(kPlaceContainsChecker)
513+
|| blockTextUppercase.contains(kStartFromNumberChecker)) {
513514
blockType = TextParagraphType::SceneHeading;
514515
}
515516

@@ -537,8 +538,8 @@ TextParagraphType AbstractDocumentImporter::typeForTextCursor(const QTextCursor&
537538
// 1. В верхнем регистре
538539
//
539540
else if ((textIsUppercase
540-
|| BlockTextWithoutParentheses
541-
== TextHelper::smartToUpper(BlockTextWithoutParentheses))
541+
|| blockTextWithoutParentheses
542+
== TextHelper::smartToUpper(blockTextWithoutParentheses))
542543
&& _lastBlockType != TextParagraphType::Character) {
543544
blockType = TextParagraphType::Character;
544545
}

0 commit comments

Comments
 (0)