Skip to content

Commit

Permalink
#106: Added element <toc-text> as child element of <toc-entry>.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRambags committed Sep 26, 2019
1 parent f932a61 commit 178f95c
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,14 @@ public void testBreakBeforeSheet() throws LayoutEngineException, IOException, Pa
testPEF("resource-files/dp2/break-before-sheet-input.obfl",
"resource-files/dp2/break-before-sheet-expected.pef", false);
}
@Test
public void testTocTextDeprecated() throws LayoutEngineException, IOException, PagedMediaWriterConfigurationException {
testPEF("resource-files/dp2/toc-text-input-deprecated.obfl",
"resource-files/dp2/toc-text-expected.pef", true);
}
@Test
public void testTocText() throws LayoutEngineException, IOException, PagedMediaWriterConfigurationException {
testPEF("resource-files/dp2/toc-text-input.obfl",
"resource-files/dp2/toc-text-expected.pef", true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<pef xmlns="http://www.daisy.org/ns/2008/pef" version="2008-1">
<head>
<meta>
<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">toc-text</dc:title>
<dc:description xmlns:dc="http://purl.org/dc/elements/1.1/">Tests toc-text.</dc:description>
<dc:format xmlns:dc="http://purl.org/dc/elements/1.1/">application/x-pef+xml</dc:format>
</meta>
</head>
<body>
<volume cols="15" rows="6" rowgap="0" duplex="false">
<section>
<page>
<row>⠼⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠼⠃</row>
<row>⠿⠿⠿⠿⠀⠼⠚⠀⠼⠁</row>
<row>⠿⠿</row>
<row>⠿⠿⠀⠀⠀⠀⠀⠼⠃</row>
<row>⠿⠿⠿⠿</row>
</page>
</section>
<section>
<page>
<row>⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀</row>
<row>⠿⠿</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
</page>
<page>
<row>⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀</row>
<row>⠿⠿</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
</page>
<page>
<row>⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀</row>
<row>⠿⠿⠿</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
<row>⠤⠤⠤⠤⠤⠀⠤⠤⠤⠤⠤</row>
</page>
</section>
</volume>
</body>
</pef>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<obfl xmlns="http://www.daisy.org/ns/2011/obfl" version="2011-1" xml:lang="und" hyphenate="false">
<meta>
<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">toc-text-input-deprecated</dc:title>
<dc:description xmlns:dc="http://purl.org/dc/elements/1.1/">Tests toc-entry elements without a toc-text child element (deprecated, #106).</dc:description>
</meta>
<layout-master name="main" duplex="false" page-width="15" page-height="6">
<default-template>
<header>
<field>
<marker-reference marker="marker" direction="forward" scope="sequence"/>
</field>
<field>
<marker-reference marker="marker" direction="backward" scope="sequence"/>
</field>
</header>
<footer/>
</default-template>
</layout-master>
<table-of-contents name="toc">
<toc-entry ref-id="ch_1">
⠿⠿⠿⠿ <evaluate expression="(- 1 1)"/>
<page-number ref-id="ch_1" number-format="default"/>
<marker class="marker" value="1"/>
</toc-entry>
<toc-entry ref-id="ch_2">
⠿⠿<br/>⠿⠿ <leader position="7"/><page-number ref-id="ch_2" number-format="default"/>
<marker class="marker" value="2"/>
<toc-entry ref-id="ch_2_2">
⠿⠿⠿⠿
</toc-entry>
</toc-entry>
</table-of-contents>
<volume-template sheets-in-volume-max="100">
<pre-content>
<toc-sequence toc="toc" master="main" range="volume"/>
</pre-content>
</volume-template>
<sequence master="main">
<block id="ch_1" translate="">⠿⠿ </block>
<block>⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
</block>
<block id="ch_2" translate="">⠿⠿ </block>
<block>⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
<block id="ch_2_2" translate="">⠿⠿⠿ </block>
<block>⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
</block>
</block>
</sequence>
</obfl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<obfl xmlns="http://www.daisy.org/ns/2011/obfl" version="2011-1" xml:lang="und" hyphenate="false">
<meta>
<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">toc-text</dc:title>
<dc:description xmlns:dc="http://purl.org/dc/elements/1.1/">Tests toc-text.</dc:description>
</meta>
<layout-master name="main" duplex="false" page-width="15" page-height="6">
<default-template>
<header>
<field>
<marker-reference marker="marker" direction="forward" scope="sequence"/>
</field>
<field>
<marker-reference marker="marker" direction="backward" scope="sequence"/>
</field>
</header>
<footer/>
</default-template>
</layout-master>
<table-of-contents name="toc">
<toc-entry ref-id="ch_1">
<toc-text>
⠿⠿⠿⠿ <evaluate expression="(- 1 1)"/>
<page-number ref-id="ch_1" number-format="default"/>
<marker class="marker" value="1"/>
</toc-text>
</toc-entry>
<toc-entry ref-id="ch_2">
<toc-text>
⠿⠿<br/>⠿⠿ <leader position="7"/><page-number ref-id="ch_2" number-format="default"/>
<marker class="marker" value="2"/>
</toc-text>
<toc-entry ref-id="ch_2_2">
<toc-text>
⠿⠿⠿⠿
</toc-text>
</toc-entry>
</toc-entry>
</table-of-contents>
<volume-template sheets-in-volume-max="100">
<pre-content>
<toc-sequence toc="toc" master="main" range="volume"/>
</pre-content>
</volume-template>
<sequence master="main">
<block id="ch_1" translate="">⠿⠿ </block>
<block>⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
</block>
<block id="ch_2" translate="">⠿⠿ </block>
<block>⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
<block id="ch_2_2" translate="">⠿⠿⠿ </block>
<block>⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤ ⠤⠤⠤⠤⠤
</block>
</block>
</sequence>
</obfl>
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,14 @@ private static int untilEventIsNotBackward(List<XMLEvent> events, final int i, Q
}

private boolean beginsMixedContent(XMLEvent event) {
return equalsStart(event, ObflQName.BLOCK, ObflQName.TOC_ENTRY, ObflQName.ITEM, ObflQName.BEFORE, ObflQName.AFTER, ObflQName.TD);
// TODO: ObflQName.TOC_ENTRY is deprecated (#106) - remove in a future version
return equalsStart(event, ObflQName.BLOCK, ObflQName.TOC_ENTRY, ObflQName.TOC_TEXT, ObflQName.TOC_TEXT_RESUMED, ObflQName.ITEM, ObflQName.BEFORE, ObflQName.AFTER, ObflQName.TD);

}

private boolean endsMixedContent(XMLEvent event) {
return equalsEnd(event, ObflQName.BLOCK, ObflQName.TOC_ENTRY, ObflQName.ITEM, ObflQName.BEFORE, ObflQName.AFTER, ObflQName.TD);
// TODO: ObflQName.TOC_ENTRY is deprecated (#106) - remove in a future version
return equalsEnd(event, ObflQName.BLOCK, ObflQName.TOC_ENTRY, ObflQName.TOC_TEXT, ObflQName.TOC_TEXT_RESUMED, ObflQName.ITEM, ObflQName.BEFORE, ObflQName.AFTER, ObflQName.TD);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/org/daisy/dotify/formatter/impl/obfl/ObflParserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1193,10 +1193,14 @@ private void parseTocEntry(XMLEvent event, XMLEventIterator input, TableOfConten
while (input.hasNext()) {
event=input.nextEvent();
if (event.isCharacters()) {
// TODO: deprecated (#106) - remove in a future version
toc.addChars(event.asCharacters().getData(), tp);
} else if (equalsStart(event, ObflQName.TOC_TEXT)) {
parseTocText(event, input, toc, tp);
} else if (equalsStart(event, ObflQName.TOC_ENTRY)) {
parseTocEntry(event, input, toc, tp);
} else if (processAsBlockContents(toc, event, input, tp)) {
// TODO: deprecated (#106) - remove this if clause in a future version
//done!
}
else if (equalsEnd(event, ObflQName.TOC_ENTRY)) {
Expand All @@ -1207,6 +1211,23 @@ else if (equalsEnd(event, ObflQName.TOC_ENTRY)) {
}
}
}

private void parseTocText(XMLEvent event, XMLEventIterator input, TableOfContents toc, TextProperties tp) throws XMLStreamException {
tp = getTextProperties(event, tp);
while (input.hasNext()) {
event=input.nextEvent();
if (event.isCharacters()) {
toc.addChars(event.asCharacters().getData(), tp);
} else if (processAsBlockContents(toc, event, input, tp)) {
//done!
}
else if (equalsEnd(event, ObflQName.TOC_TEXT)) {
break;
} else {
report(event);
}
}
}

private void parseCollectionItem(XMLEvent event, XMLEventIterator input, ContentCollection coll, TextProperties tp) throws XMLStreamException {
tp = getTextProperties(event, tp);
Expand Down
3 changes: 3 additions & 0 deletions src/org/daisy/dotify/formatter/impl/obfl/ObflQName.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ interface ObflQName {
static final QName SPAN = new QName(OBFL_NS, "span");
static final QName STYLE = new QName(OBFL_NS, "style");
static final QName TOC_ENTRY = new QName(OBFL_NS, "toc-entry");
static final QName TOC_TEXT = new QName(OBFL_NS, "toc-text");
static final QName TOC_TEXT_RESUMED = new QName(OBFL_NS, "toc-text");
static final QName LEADER = new QName(OBFL_NS, "leader");
static final QName MARKER = new QName(OBFL_NS, "marker");
static final QName ANCHOR = new QName(OBFL_NS, "anchor");
Expand Down Expand Up @@ -97,6 +99,7 @@ interface ObflQName {
static final QName ATTR_COST = new QName("cost");
static final QName ATTR_URI = new QName("uri");
static final QName ATTR_VALUE = new QName("value");
static final QName ATTR_USE_TOC_TEXT_RESUMED = new QName("use-toc-text-resumed");

static final QName TABLE = new QName(OBFL_NS, "table");
static final QName THEAD = new QName(OBFL_NS, "thead");
Expand Down

0 comments on commit 178f95c

Please sign in to comment.