Update QTextDocument to work with new chapter headers
This commit is contained in:
@@ -156,20 +156,28 @@ class ToQTextDocument(Tokenizer):
|
||||
mPx = fPx * self._dpi/96.0
|
||||
|
||||
self._mHead = {
|
||||
BlockTyp.TITLE: (fPx * self._marginTitle[0], fPx * self._marginTitle[1]),
|
||||
BlockTyp.HEAD1: (fPx * self._marginHead1[0], fPx * self._marginHead1[1]),
|
||||
BlockTyp.HEAD2: (fPx * self._marginHead2[0], fPx * self._marginHead2[1]),
|
||||
BlockTyp.HEAD3: (fPx * self._marginHead3[0], fPx * self._marginHead3[1]),
|
||||
BlockTyp.HEAD4: (fPx * self._marginHead4[0], fPx * self._marginHead4[1]),
|
||||
BlockTyp.TITLE: (fPx * self._marginTitle[0], fPx * self._marginTitle[1]),
|
||||
BlockTyp.PART: (fPx * self._marginTitle[0], fPx * self._marginTitle[1]),
|
||||
BlockTyp.HEAD1: (fPx * self._marginHead1[0], fPx * self._marginHead1[1]),
|
||||
BlockTyp.CHAPTER: (fPx * self._marginHead1[0], fPx * self._marginHead1[1]),
|
||||
BlockTyp.HEAD2: (fPx * self._marginHead2[0], fPx * self._marginHead2[1]),
|
||||
BlockTyp.SCENE: (fPx * self._marginHead2[0], fPx * self._marginHead2[1]),
|
||||
BlockTyp.HEAD3: (fPx * self._marginHead3[0], fPx * self._marginHead3[1]),
|
||||
BlockTyp.SECTION: (fPx * self._marginHead3[0], fPx * self._marginHead3[1]),
|
||||
BlockTyp.HEAD4: (fPx * self._marginHead4[0], fPx * self._marginHead4[1]),
|
||||
}
|
||||
|
||||
hScale = self._scaleHeads
|
||||
self._sHead = {
|
||||
BlockTyp.TITLE: (nwStyles.H_SIZES.get(0, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.HEAD1: (nwStyles.H_SIZES.get(1, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.HEAD2: (nwStyles.H_SIZES.get(2, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.HEAD3: (nwStyles.H_SIZES.get(3, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.HEAD4: (nwStyles.H_SIZES.get(4, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.TITLE: (nwStyles.H_SIZES.get(0, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.PART: (nwStyles.H_SIZES.get(0, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.HEAD1: (nwStyles.H_SIZES.get(1, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.CHAPTER: (nwStyles.H_SIZES.get(1, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.HEAD2: (nwStyles.H_SIZES.get(2, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.SCENE: (nwStyles.H_SIZES.get(2, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.HEAD3: (nwStyles.H_SIZES.get(3, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.SECTION: (nwStyles.H_SIZES.get(3, 1.0) * fPt) if hScale else fPt,
|
||||
BlockTyp.HEAD4: (nwStyles.H_SIZES.get(4, 1.0) * fPt) if hScale else fPt,
|
||||
}
|
||||
|
||||
self._mText = (fPx * self._marginText[0], fPx * self._marginText[1])
|
||||
|
||||
@@ -79,44 +79,44 @@ def testFmtToQTextDocument_ConvertHeaders(mockGUI):
|
||||
block = doc.document.findBlockByNumber(1)
|
||||
assert block.text() == "Partition"
|
||||
bFmt = block.blockFormat()
|
||||
assert bFmt.topMargin() == doc._mHead[BlockTyp.HEAD1][0]
|
||||
assert bFmt.bottomMargin() == doc._mHead[BlockTyp.HEAD1][1]
|
||||
assert bFmt.topMargin() == doc._mHead[BlockTyp.PART][0]
|
||||
assert bFmt.bottomMargin() == doc._mHead[BlockTyp.PART][1]
|
||||
cFmt = charFmtInBlock(block, 1)
|
||||
assert cFmt.fontWeight() == QFont.Weight.Bold
|
||||
assert cFmt.fontPointSize() == doc._sHead[BlockTyp.HEAD1]
|
||||
assert cFmt.fontPointSize() == doc._sHead[BlockTyp.PART]
|
||||
assert cFmt.foreground().color() == THEME.head
|
||||
|
||||
# Chapter
|
||||
block = doc.document.findBlockByNumber(2)
|
||||
assert block.text() == "Chapter"
|
||||
bFmt = block.blockFormat()
|
||||
assert bFmt.topMargin() == doc._mHead[BlockTyp.HEAD2][0]
|
||||
assert bFmt.bottomMargin() == doc._mHead[BlockTyp.HEAD2][1]
|
||||
assert bFmt.topMargin() == doc._mHead[BlockTyp.CHAPTER][0]
|
||||
assert bFmt.bottomMargin() == doc._mHead[BlockTyp.CHAPTER][1]
|
||||
cFmt = charFmtInBlock(block, 1)
|
||||
assert cFmt.fontWeight() == QFont.Weight.Bold
|
||||
assert cFmt.fontPointSize() == doc._sHead[BlockTyp.HEAD2]
|
||||
assert cFmt.fontPointSize() == doc._sHead[BlockTyp.CHAPTER]
|
||||
assert cFmt.foreground().color() == THEME.head
|
||||
|
||||
# Scene
|
||||
block = doc.document.findBlockByNumber(3)
|
||||
assert block.text() == "Scene"
|
||||
bFmt = block.blockFormat()
|
||||
assert bFmt.topMargin() == doc._mHead[BlockTyp.HEAD3][0]
|
||||
assert bFmt.bottomMargin() == doc._mHead[BlockTyp.HEAD3][1]
|
||||
assert bFmt.topMargin() == doc._mHead[BlockTyp.SCENE][0]
|
||||
assert bFmt.bottomMargin() == doc._mHead[BlockTyp.SCENE][1]
|
||||
cFmt = charFmtInBlock(block, 1)
|
||||
assert cFmt.fontWeight() == QFont.Weight.Bold
|
||||
assert cFmt.fontPointSize() == doc._sHead[BlockTyp.HEAD3]
|
||||
assert cFmt.fontPointSize() == doc._sHead[BlockTyp.SCENE]
|
||||
assert cFmt.foreground().color() == THEME.head
|
||||
|
||||
# Section
|
||||
block = doc.document.findBlockByNumber(4)
|
||||
assert block.text() == "Section"
|
||||
bFmt = block.blockFormat()
|
||||
assert bFmt.topMargin() == doc._mHead[BlockTyp.HEAD4][0]
|
||||
assert bFmt.bottomMargin() == doc._mHead[BlockTyp.HEAD4][1]
|
||||
assert bFmt.topMargin() == doc._mHead[BlockTyp.SECTION][0]
|
||||
assert bFmt.bottomMargin() == doc._mHead[BlockTyp.SECTION][1]
|
||||
cFmt = charFmtInBlock(block, 1)
|
||||
assert cFmt.fontWeight() == QFont.Weight.Bold
|
||||
assert cFmt.fontPointSize() == doc._sHead[BlockTyp.HEAD4]
|
||||
assert cFmt.fontPointSize() == doc._sHead[BlockTyp.SECTION]
|
||||
assert cFmt.foreground().color() == THEME.head
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user