txt.py, infoview fixes
This commit is contained in:
parent
0dbc92d027
commit
16989e9990
3 changed files with 51 additions and 38 deletions
|
@ -99,12 +99,13 @@ oml.ui.infoView = function(identifyData) {
|
||||||
+ Ox._(Ox.toTitleCase(key)) + ': </span> ';
|
+ Ox._(Ox.toTitleCase(key)) + ': </span> ';
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatValue(value, key) {
|
function formatValue(value, key, join) {
|
||||||
return (Ox.isArray(value) ? value : [value]).map(function(value) {
|
value = Ox.encodeHTMLEntities(value);
|
||||||
|
return value ? (Ox.isArray(value) ? value : [value]).map(function(value) {
|
||||||
return key ?
|
return key ?
|
||||||
'<a href="/' + key + '==' + value + '">' + value + '</a>'
|
'<a href="/' + key + '==' + value + '">' + value + '</a>'
|
||||||
: value;
|
: value;
|
||||||
}).join(', ');
|
}).join(join || ', ') : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function identify(data) {
|
function identify(data) {
|
||||||
|
@ -352,8 +353,8 @@ oml.ui.infoView = function(identifyData) {
|
||||||
fontWeight: 'bold'
|
fontWeight: 'bold'
|
||||||
})
|
})
|
||||||
.html(
|
.html(
|
||||||
data.title
|
data.title ? Ox.encodeHTMLEntities(data.title)
|
||||||
|| '<span class="OxLight">'
|
: '<span class="OxLight">'
|
||||||
+ Ox._('No Title')
|
+ Ox._('No Title')
|
||||||
+ '</span>'
|
+ '</span>'
|
||||||
)
|
)
|
||||||
|
@ -375,10 +376,10 @@ oml.ui.infoView = function(identifyData) {
|
||||||
.css({
|
.css({
|
||||||
marginTop: '8px'
|
marginTop: '8px'
|
||||||
})
|
})
|
||||||
.text(
|
.html(
|
||||||
(data.place || []).join(' ; ')
|
(formatValue(data.place, 'place', ' ; '))
|
||||||
+ (data.place && (data.publisher || data.date) ? ' : ' : '')
|
+ (data.place && (data.publisher || data.date) ? ' : ' : '')
|
||||||
+ (data.publisher || '')
|
+ (formatValue(data.publisher, 'publisher'))
|
||||||
+ (data.publisher && data.date ? ', ' : '')
|
+ (data.publisher && data.date ? ', ' : '')
|
||||||
+ (data.date || '')
|
+ (data.date || '')
|
||||||
)
|
)
|
||||||
|
@ -390,10 +391,10 @@ oml.ui.infoView = function(identifyData) {
|
||||||
.css({
|
.css({
|
||||||
marginTop: '8px'
|
marginTop: '8px'
|
||||||
})
|
})
|
||||||
.text(
|
.html(
|
||||||
(data.edition || '')
|
(Ox.encodeHTMLEntities(data.edition || ''))
|
||||||
+ (data.edition && data.language ? '; ' : '')
|
+ (data.edition && data.language ? '; ' : '')
|
||||||
+ (data.language || '')
|
+ (formatValue(data.language, 'language'))
|
||||||
)
|
)
|
||||||
.appendTo($info);
|
.appendTo($info);
|
||||||
}
|
}
|
||||||
|
@ -404,7 +405,9 @@ oml.ui.infoView = function(identifyData) {
|
||||||
marginTop: '8px',
|
marginTop: '8px',
|
||||||
textAlign: 'justify'
|
textAlign: 'justify'
|
||||||
})
|
})
|
||||||
.html(Ox.encodeHTMLEntities(data.classification))
|
.html(
|
||||||
|
Ox.formatValue(data.classification, 'classification')
|
||||||
|
)
|
||||||
.appendTo($info);
|
.appendTo($info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,7 +417,9 @@ oml.ui.infoView = function(identifyData) {
|
||||||
marginTop: '8px',
|
marginTop: '8px',
|
||||||
textAlign: 'justify'
|
textAlign: 'justify'
|
||||||
})
|
})
|
||||||
.html(Ox.encodeHTMLEntities(data.description))
|
.html(
|
||||||
|
Ox.encodeHTMLEntities(data.description)
|
||||||
|
)
|
||||||
.appendTo($info);
|
.appendTo($info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ txtjs.open = function(url) {
|
||||||
Ox.get(url, function(text) {
|
Ox.get(url, function(text) {
|
||||||
var $body = Ox.$('body')
|
var $body = Ox.$('body')
|
||||||
.css({
|
.css({
|
||||||
backgroundColor: 'rgb(255, 255, 255)'
|
backgroundColor: 'rgb(255, 255, 255)',
|
||||||
|
overflowX: 'hidden'
|
||||||
}),
|
}),
|
||||||
$text = Ox.$('<div>')
|
$text = Ox.$('<div>')
|
||||||
.css({
|
.css({
|
||||||
|
@ -29,28 +30,32 @@ txtjs.open = function(url) {
|
||||||
.css({
|
.css({
|
||||||
fontSize: '2px',
|
fontSize: '2px',
|
||||||
lineHeight: '3px',
|
lineHeight: '3px',
|
||||||
|
cursor: 'pointer',
|
||||||
WebkitUserSelect: 'none'
|
WebkitUserSelect: 'none'
|
||||||
})
|
})
|
||||||
.on({
|
.on({
|
||||||
click: function(e) {
|
mousedown: function(e) {
|
||||||
var offset = 'offsetY' in e ? e.offsetY : e.layerY;
|
var offset = 'offsetY' in e ? e.offsetY : e.layerY;
|
||||||
document.body.scrollTop = offset / factor;
|
document.body.scrollTop = offset / factor;
|
||||||
Ox.print('!', offset)
|
//Ox.print('!', offset)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.appendTo($scroll),
|
.appendTo($scroll),
|
||||||
scale;
|
textHeight, scrollTextHeight, factor;
|
||||||
text = Ox.encodeHTMLEntities(text)
|
text = Ox.encodeHTMLEntities(text)
|
||||||
.replace(/\r\n/g, '\n')
|
.replace(/\r\n/g, '\n')
|
||||||
.replace(/[\r\n]/g, '<br>');
|
.replace(/[\r\n]/g, '<br>');
|
||||||
$text.html(text);
|
$text.html(text);
|
||||||
$scrollText.html(text);
|
$scrollText.html(text);
|
||||||
var textHeight = $text[0].clientHeight,
|
window.onresize = function() {
|
||||||
scrollTextHeight = $scrollText[0].clientHeight,
|
textHeight = $text[0].clientHeight - window.innerHeight,
|
||||||
|
scrollTextHeight = $scrollText[0].clientHeight - (window.innerHeight - 32),
|
||||||
factor = scrollTextHeight / textHeight;
|
factor = scrollTextHeight / textHeight;
|
||||||
|
};
|
||||||
window.onscroll = function() {
|
window.onscroll = function() {
|
||||||
$scroll[0].scrollTop = window.pageYOffset * factor;
|
$scroll[0].scrollTop = window.pageYOffset * factor;
|
||||||
};
|
};
|
||||||
|
window.onresize();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,28 +30,31 @@ def render(infile, outfile):
|
||||||
|
|
||||||
for line in f:
|
for line in f:
|
||||||
|
|
||||||
line = line.decode('utf-8').strip()
|
for line_ in line.decode('utf-8').strip().split('\r'):
|
||||||
|
|
||||||
lines = wrapText(
|
lines = wrapText(
|
||||||
line,
|
|
||||||
image_size[0] - 2 * margin,
|
|
||||||
# we don't want the last line that ends with an ellipsis
|
|
||||||
max_lines + 1,
|
|
||||||
'txt.ttf',
|
|
||||||
font_size
|
|
||||||
)
|
|
||||||
|
|
||||||
for line_ in lines:
|
|
||||||
drawText(
|
|
||||||
image,
|
|
||||||
(margin, offset),
|
|
||||||
line_,
|
line_,
|
||||||
font_file,
|
image_size[0] - 2 * margin,
|
||||||
font_size,
|
# we don't want the last line that ends with an ellipsis
|
||||||
(0)
|
max_lines + 1,
|
||||||
|
'txt.ttf',
|
||||||
|
font_size
|
||||||
)
|
)
|
||||||
offset += line_height
|
|
||||||
max_lines -= 1
|
for line__ in lines:
|
||||||
|
drawText(
|
||||||
|
image,
|
||||||
|
(margin, offset),
|
||||||
|
line__,
|
||||||
|
font_file,
|
||||||
|
font_size,
|
||||||
|
(0)
|
||||||
|
)
|
||||||
|
offset += line_height
|
||||||
|
max_lines -= 1
|
||||||
|
|
||||||
|
if max_lines == 0:
|
||||||
|
break
|
||||||
|
|
||||||
if max_lines == 0:
|
if max_lines == 0:
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue