Commit c1aa878d authored by gijs's avatar gijs

More tools and scripts. For simple typographic fixes, layout book2

parent 67914819
;(function () {
if ((!document.getNamedFlows) && document.webkitGetNamedFlows) {
document.getNamedFlows = document.webkitGetNamedFlows;
}
if (!document.getNamedFlow) {
document.getNamedFlow = function (name) {
return document.getNamedFlows(name).namedItem(name);
}
}
var textFlow = document.getNamedFlow('main');
/**
* Returns first region the given node is shown within
*
* workaround for getRegionsForContent() as that function only seems to work
* on block-elements
*/
function getRegionByNode(flow, node) {
var ranges, regions = flow.getRegionsByContent(node);
if (regions.length > 0) {
return regions[0];
} else {
regions = flow.getRegions();
for (var i=0; i < regions.length; i++) {
ranges = regions[i].webkitGetRegionFlowRanges();
for (var r=0; r < ranges.length; r++) {
if (ranges[r].isPointInRange(node, 0)) {
return regions[i];
}
}
}
console.log('Could not find region for node', node);
}
}
/**
* Find page for given node, travels up the DOM tree to find
* first wrapping paper element. Does not work for Nodes in a flow.
*/
function getPageByNode (node) {
if (node) {
if (node.classList.contains('paper')) {
return node;
} else {
if (node.parentElement) {
return getPageByNode(node.parentElement);
} else {
return false;
}
}
return false;
}
}
/**
* Get page by node in region
*/
function getPageByRegionNode (flow, node) {
var region = getRegionByNode(flow, node);
if (region) {
return getPageByNode(getRegionByNode(flow, node));
} else {
return null;
}
}
/**
* Return page number for given page
*/
function getPageNum (page) {
return parseInt(page.id.replace(/\D/g, ''));
}
window.fixOrphans = function () {
var threshold = 80,
step = -.025,
max = -0.125;
spans = document.querySelectorAll('.last-line');
for (var i=0; i < spans.length; i++) {
var rects = spans[i].getClientRects(),
lineCount = rects.length; // Remember how many lines we had at the start
if (rects[rects.length-1].width <= threshold) {
var spacing = 0;
while(rects.length >= lineCount && spacing >= max) {
spacing += step;
spans[i].style.letterSpacing = spacing + 'mm';
rects = spans[i].getClientRects()
}
if (rects.length == lineCount) {
spans[i].style.letterSpacing = 0;
}
}
}
}
window.fixWidows = function () {
var threshold = 30,
p = document.querySelectorAll('p');
for (var i=0; i < p.length; i++) {
var rects = p[i].getClientRects();
if (rects.length > 1 && rects[0].height < threshold) {
p[i].classList.add('break-before');
}
}
}
window.reattachHeaders = function () {
var textFlow = document.getNamedFlow('main'),
headers = document.querySelectorAll('h4');
for (var i=0; i< headers.length; i++) {
var h = headers[i],
p = h.nextElementSibling;
if (getPageNum(getPageByRegionNode(textFlow, h)) != getPageNum(getPageByRegionNode(textFlow, p))) {
h.classList.add('break-before');
} else {
var threshold = 75,
rects = p.getClientRects();
if (rects.length > 1 && rects[0].height <= threshold) {
h.classList.add('break-before');
}
}
}
}
window.typographicFixes = function () {
fixOrphans();
reattachHeaders();
fixWidows();
}
})();
\ No newline at end of file
;(function () {
'use strict';
window.buildIndex = function (callback) {
var dummyIndexJSON = "{\"problematisation\":[1,4,6,2,3,10,5,7],\"integrality\":[1,3,5,6,7,10],\"enunciation\":[1,2,10,3,4,8,9,6],\"formulation\":[1,3,4,6,10,2,7,9],\"discursive object\":[1,2,5],\"détournements\":[1],\"lekton\":[2,4,5],\"singularity\":[4,9,2,11,5],\"statement\":[5,10,3,7,9,13],\"history\":[9,1,2,4,5,3,7,11,13,6,14,12],\"urbanism\":[9,1,2,3,5,6,8,10,11,12,4,13,16],\"event\":[10,1,2,3,4,5,8],\"fault line\":[10,4,5],\"birth\":[2,4,5,6,8,11,12,1,3],\"street\":[3,4,12,5,8,6,9,10,11,13,1,2,7,16],\"police\":[3,5,2,10,12],\"palimpsest in action\":[4],\"disappearance\":[4,11,12,9],\"accidental intertwining\":[1],\"ideal city\":[1,2,4,9],\"evil\":[2,3,12,16,9,11,8],\"chance\":[2,4,11,9,10],\"archaeological method\":[3],\"conspiracy\":[3,1,2,4,12,5,6],\"aesthetics\":[3,1,7,9,6,8,10,11],\"ethics\":[4,1,2,7,8,12,3,5,6,9,10],\"provenance\":[5,6,11],\"immanent\":[10,7],\"public domain\":[11,13],\"public space\":[11,12],\"polis\":[12,7,1,3,4,9],\"machine\":[1,2,11,13,4,9],\"concatenation\":[1],\"savoir\":[2,3,5,11,4,9,10,8,12,13,6,1,7],\"medical topography\":[4],\"exercise\":[5,3,11,12,2],\"ventilation\":[6,8,9,11,12],\"problematisations\":[7,10],\"rupture\":[7,4,5,8],\"concatenations\":[1],\"historical subject\":[2],\"vector\":[7,13,3],\"aesthetic\":[8,2,10,12,11],\"focal point\":[10,11,12,1,2,5],\"political territory\":[12,13],\"\":[13],\" as institution\":[13],\"street as institution\":[13],\"arsenal\":[2],\"mathēsis\":[1,5,9,16,4,7],\"wisconst\":[1,5,6,9,16,4,7,8],\"resemblance\":[2,5,13,14,15,7],\"‘as if’\":[2,5],\"ars combinatoria\":[5,6],\"civil life\":[5,12,16,1,9,3,4,6,7,8],\"expert\":[5,6,7,9],\"constancy\":[5,6,4,7,8,9,10,11,12,1,2,3],\"dissimulation\":[8,9],\"vital ascesis\":[12,1],\"subject of initiative\":[3],\"dispositif\":[3,11],\"myth\":[4],\"gemüt\":[5,8],\"technologies of the self\":[5,6,8,2],\"structural dissidence\":[11],\"inertia\":[12],\"indifference\":[10],\"vita politica\":[1,4],\"passivum\":[10],\"ghemoed\":[8],\"hypermodern dilettante\":[9]}",
indexJSON = window.localStorage.getItem('the-riddle-index'),
index = (indexJSON) ? JSON.parse(indexJSON) : JSON.parse(dummyIndexJSON),
indexContainer = document.querySelector('#index'),
keys = Object.keys(index);
keys.sort();
for (var k = 0; k < keys.length; k++) {
var key = keys[k],
pages = index[key];
pages.sort(function (a, b) {
if (a < b) {
return -1;
} else {
if (a > b) {
return 1;
}
return 0;
}
});
console.log(pages);
var entry = document.createElement('section'),
entryLabel = document.createElement('span'),
entryLabelText = document.createTextNode(key);
entry.classList.add('index-entry');
entryLabel.classList.add('index-entry-label');
entryLabel.appendChild(entryLabelText);
entry.appendChild(entryLabel);
for (var i=0; i < pages.length; i++) {
var pageNum = document.createElement('span'),
pageNumText = document.createTextNode(pages[i]);
pageNum.classList.add('index-pagenum');
pageNum.appendChild(pageNumText);
entry.appendChild(pageNum);
}
indexContainer.appendChild(entry);
}
callback();
};
})();
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
<html>
<head>
<style type="text/css">
#viewport {
position: fixed;
width: 100%;
height: -webkit-calc(100% - 25px);
height: calc(100% - 25px);
border: none;
}
</style>
</head>
<body>
<iframe id="viewport"></iframe>
<script>
(function () {
'use strict';
var chapters = [
"/chapters/book1/I.1.1 + Exc 1 def.html",
"/chapters/book1/I.1.2 def.html",
"/chapters/book1/I.1.3 + Exc 2 en 3 def.html",
"/chapters/book1/I.1.4 + 4a def.html",
"/chapters/book1/I.1.5 The Emergence of the Engineer and His Unexcelled Theoretical Background+ Exc 5a def.html",
"/chapters/book1/I.1.6 Politics of the Street def.html",
"/chapters/book1/I.1.7 The Street Machine.html",
"/chapters/book1/I.1.8 Boosting the City or the Principle of Conditioned Ground def.html",
"/chapters/book1/I.1.9 The Power of Expressiveness and Wil to Direct + Exc 7def.html",
"/chapters/book1/I.2.1 On the Ordering of Cities.html",
"/chapters/book1/I.2.2 + Exc 7.html",
"/chapters/book1/I.2.3 + Exc 8.html",
"/chapters/book1/I.2.4 + Exc 9.html",
"/chapters/book1/I.2.5 + Exc 10.html",
"/chapters/book1/I.2.6 + Exc 11.html",
"/chapters/book1/I.2.7 Wealth and Representation.html",
"/chapters/book2/II.1 The Image of the City and the Process of Planning.html",
"/chapters/book2/II.2 City Frontiers and Their Disappearance.html",
"/chapters/book2/II.3 Passion for the Hiatus and the Liquidisation of Architecture.html",
"/chapters/book2/II.4 Information Cloud and the Rise of the Omnipolis.html",
"/chapters/book2/II.5 Solidification of History.html",
"/chapters/book2/II.6 Compulsion to Sit.html",
"/chapters/book3/3-all.html"
];
var c = 0, intervalId,
viewport = document.getElementById('viewport');
function checkChapterReady () {
if (viewport.contentDocument.layoutcomplete) {
window.clearInterval(intervalId);
loadNextChapter();
}
}
function loadNextChapter () {
if (c < chapters.length) {
viewport.src = chapters[c];
c++;
} else {
window.location.href = 'http://html2print/chapters/book0/index.html';
console.log('ready');
}
}
viewport.addEventListener("load", function () {
intervalId = window.setInterval(checkChapterReady, 500);
});
loadNextChapter();
})();
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment