Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#106: Added element <toc-text> as child element of <toc-entry>. #112

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ publishing {
id = 'kalaspuffar'
name = 'Daniel Persson'
}
developer {
id = 'paulrambags'
name = 'Paul Rambags'
}
}
}
}
Expand Down
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", false);
}
@Test
public void testTocText() throws LayoutEngineException, IOException, PagedMediaWriterConfigurationException {
testPEF("resource-files/dp2/toc-text-input.obfl",
"resource-files/dp2/toc-text-expected.pef", false);
}
}
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 with mixed content.</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 with mixed content.</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
41 changes: 39 additions & 2 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,12 @@ private void parseTocEntry(XMLEvent event, XMLEventIterator input, TableOfConten
while (input.hasNext()) {
event=input.nextEvent();
if (event.isCharacters()) {
toc.addChars(event.asCharacters().getData(), tp);
tocEntryAddChars(toc, event, 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)) {
} else if (tocEntryProcessAsBlockContents(toc, event, input, tp)) {
//done!
}
else if (equalsEnd(event, ObflQName.TOC_ENTRY)) {
Expand All @@ -1207,6 +1209,41 @@ else if (equalsEnd(event, ObflQName.TOC_ENTRY)) {
}
}
}

/**
* Adds characters from a toc-entry to the toc
* @deprecated the characters should be placed inside the toc-text element, see #106
*/
@Deprecated
private void tocEntryAddChars(TableOfContents toc, XMLEvent event, TextProperties tp) {
toc.addChars(event.asCharacters().getData(), tp);
}

/**
* Adds block contents from a toc-entry to the toc
* @deprecated the block contents should be placed inside the toc-text element, see #106
*/
@Deprecated
private boolean tocEntryProcessAsBlockContents(TableOfContents toc, XMLEvent event, XMLEventIterator input, TextProperties tp) throws XMLStreamException {
return processAsBlockContents(toc, event, input, tp);
}

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
2 changes: 2 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-resumed");
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