SVG podría ser una buena opción para su paginación texto
texto SVG es en realidad el texto - a diferencia de la lona la cual muestra solo una imagen de texto.
El texto SVG es legible, seleccionable, buscable.
El texto SVG no se envuelve automáticamente de forma nativa, pero esto se remedia fácilmente mediante javascript.
Los tamaños de página flexibles son posibles porque el formateo de la página se realiza en javascript.
La paginación no depende del formateo dependiente del navegador.
Las descargas de texto son pequeñas y eficientes. Solo se debe descargar el texto de la página actual.
Aquí están los detalles de cómo SVG paginación se puede hacer y una demostración:
http://jsfiddle.net/m1erickson/Lf4Vt/

Parte 1: eficientemente traiga sobre una página valor de las palabras desde una base de datos en el servidor
Almacena el texto completo en una base de datos con 1 palabra por fila.
Cada fila (palabra) se indexa secuencialmente por el orden de la palabra (palabra # 1 tiene índice == 1, palabra # 2 tiene índice == 2, etc.).
Por ejemplo, esto se vendería todo el texto en el buen orden de las palabras:
// select the entire text of Romeo and Juliet
// “order by wordIndex” causes the words to be in proper order
Select word from RomeoAndJuliet order by wordIndex
Si asume ninguna página tiene contiene alrededor de 250 palabras al formato, a continuación, esta consulta la base de datos va a buscar a los primeros 250 palabras de texto para página n. ° 1
// select the first 250 words for page#1
Select top 250 word from RomeoAndJuliet order by wordIndex
¡Ahora la parte buena!
Digamos que la página n. ° 1 usó 212 palabras después del formateo. Luego, cuando esté listo para procesar la página n. ° 2, podrá buscar otras 250 palabras a partir de la palabra n. ° 213. Esto da como resultado búsquedas de datos rápidas y eficientes.
// select 250 more words for page#2
// “where wordIndex>212” causes the fetched words
// to begin with the 213th word in the text
Select top 250 word from RomeoAndJuliet order by wordIndex where wordIndex>212
Parte 2: Formato de las palabras captan en líneas de texto que se ajusten a la página especificada ancho
Cada línea de texto debe contener suficientes palabras para llenar la página especificada con, pero no más.
Comience la línea n. ° 1 con una sola palabra y luego agregue las palabras 1 a la vez hasta que el texto encaje en el ancho de página especificado.
Después de que se instala la primera línea, nos movemos hacia abajo por una línea de altura y comenzamos la línea n. ° 2.
Ajustar las palabras en la línea requiere medir cada palabra adicional agregada en una línea. Cuando la siguiente palabra excedería el ancho de línea, esa palabra adicional se moverá a la siguiente línea.
Una palabra puede medirse utilizando el método Html Canvases context.measureText
.
Este código tomará un conjunto de palabras (como las 250 palabras extraídas de la base de datos) y formateará la mayor cantidad de palabras posible para llenar el tamaño de la página.
maxWidth
es el ancho máximo de píxeles de una línea de texto.
maxLines
es la cantidad máxima de líneas que cabrán en una página.
function textToLines(words,maxWidth,maxLines,x,y){
var lines=[];
while(words.length>0 && lines.length<=maxLines){
var line=getOneLineOfText(words,maxWidth);
words=words.splice(line.index+1);
lines.push(line);
wordCount+=line.index+1;
}
return(lines);
}
function getOneLineOfText(words,maxWidth){
var line="";
var space="";
for(var i=0;i<words.length;i++){
var testWidth=ctx.measureText(line+" "+words[i]).width;
if(testWidth>maxWidth){return({index:i-1,text:line});}
line+=space+words[i];
space=" ";
}
return({index:words.length-1,text:line});
}
Parte 3: Muestra las líneas de texto usando SVG
el elemento de texto SVG es un verdadero elemento html que puede ser leído, y buscó seleccionado.
Cada línea de texto individual en el elemento de texto SVG se visualiza con un elemento SVG Tspan.
Este código toma las líneas de texto formateadas en la Parte # 2 y muestra las líneas como una página de texto usando SVG.
function drawSvg(lines,x){
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var sText = document.createElementNS('http://www.w3.org/2000/svg', 'text');
sText.setAttributeNS(null, 'font-family', 'verdana');
sText.setAttributeNS(null, 'font-size', "14px");
sText.setAttributeNS(null, 'fill', '#000000');
for(var i=0;i<lines.length;i++){
var sTSpan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
sTSpan.setAttributeNS(null, 'x', x);
sTSpan.setAttributeNS(null, 'dy', lineHeight+"px");
sTSpan.appendChild(document.createTextNode(lines[i].text));
sText.appendChild(sTSpan);
}
svg.appendChild(sText);
$page.append(svg);
}
Aquí es código completo en caso de que la demo de enlace se rompe:
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
body{ background-color: ivory; }
.page{border:1px solid red;}
</style>
<script>
$(function(){
var canvas=document.createElement("canvas");
var ctx=canvas.getContext("2d");
ctx.font="14px verdana";
var pageWidth=250;
var pageHeight=150;
var pagePaddingLeft=10;
var pagePaddingRight=10;
var approxWordsPerPage=500;
var lineHeight=18;
var maxLinesPerPage=parseInt(pageHeight/lineHeight)-1;
var x=pagePaddingLeft;
var y=lineHeight;
var maxWidth=pageWidth-pagePaddingLeft-pagePaddingRight;
var text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
// # words that have been displayed
//(used when ordering a new page of words)
var wordCount=0;
// size the div to the desired page size
$pages=$(".page");
$pages.width(pageWidth)
$pages.height(pageHeight);
// Test: Page#1
// get a reference to the page div
var $page=$("#page");
// use html canvas to word-wrap this page
var lines=textToLines(getNextWords(wordCount),maxWidth,maxLinesPerPage,x,y);
// create svg elements for each line of text on the page
drawSvg(lines,x);
// Test: Page#2 (just testing...normally there's only 1 full-screen page)
var $page=$("#page2");
var lines=textToLines(getNextWords(wordCount),maxWidth,maxLinesPerPage,x,y);
drawSvg(lines,x);
// Test: Page#3 (just testing...normally there's only 1 full-screen page)
var $page=$("#page3");
var lines=textToLines(getNextWords(wordCount),maxWidth,maxLinesPerPage,x,y);
drawSvg(lines,x);
// fetch the next page of words from the server database
// (since we've specified the starting point in the entire text
// we only have to download 1 page of text as needed
function getNextWords(nextWordIndex){
// Eg: select top 500 word from romeoAndJuliet
// where wordIndex>=nextwordIndex
// order by wordIndex
//
// But here for testing, we just hardcode the entire text
var testingText="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
var testingWords=testingText.split(" ");
var words=testingWords.splice(nextWordIndex,approxWordsPerPage);
//
return(words);
}
function textToLines(words,maxWidth,maxLines,x,y){
var lines=[];
while(words.length>0 && lines.length<=maxLines){
var line=getLineOfText(words,maxWidth);
words=words.splice(line.index+1);
lines.push(line);
wordCount+=line.index+1;
}
return(lines);
}
function getLineOfText(words,maxWidth){
var line="";
var space="";
for(var i=0;i<words.length;i++){
var testWidth=ctx.measureText(line+" "+words[i]).width;
if(testWidth>maxWidth){return({index:i-1,text:line});}
line+=space+words[i];
space=" ";
}
return({index:words.length-1,text:line});
}
function drawSvg(lines,x){
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var sText = document.createElementNS('http://www.w3.org/2000/svg', 'text');
sText.setAttributeNS(null, 'font-family', 'verdana');
sText.setAttributeNS(null, 'font-size', "14px");
sText.setAttributeNS(null, 'fill', '#000000');
for(var i=0;i<lines.length;i++){
var sTSpan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
sTSpan.setAttributeNS(null, 'x', x);
sTSpan.setAttributeNS(null, 'dy', lineHeight+"px");
sTSpan.appendChild(document.createTextNode(lines[i].text));
sText.appendChild(sTSpan);
}
svg.appendChild(sText);
$page.append(svg);
}
}); // end $(function(){});
</script>
</head>
<body>
<h4>Text split into "pages"<br>(Selectable & Searchable)</h4>
<div id="page" class="page"></div>
<h4>Page 2</h4>
<div id="page2" class="page"></div>
<h4>Page 3</h4>
<div id="page3" class="page"></div>
</body>
</html>
¿Estás intentando paginar el texto, pero en el navegador? ¿O estamos hablando de un e-reader dedicado aquí? – Eric
Vamos a mantenerlo en el texto paginado en el navegador (aunque técnicamente estoy trabajando en un proyecto de teléfono). –
Sobre la recompensa: ya no está trabajando en este proyecto, pero tal vez ya es posible, así que me sentí como si comenzara una recompensa. –