txt.py, infoview fixes

This commit is contained in:
j 2014-05-20 00:49:47 +02:00
parent 0dbc92d027
commit 16989e9990
3 changed files with 51 additions and 38 deletions

View file

@ -99,12 +99,13 @@ oml.ui.infoView = function(identifyData) {
+ Ox._(Ox.toTitleCase(key)) + ':&nbsp;</span> ';
}
function formatValue(value, key) {
return (Ox.isArray(value) ? value : [value]).map(function(value) {
function formatValue(value, key, join) {
value = Ox.encodeHTMLEntities(value);
return value ? (Ox.isArray(value) ? value : [value]).map(function(value) {
return key ?
'<a href="/' + key + '==' + value + '">' + value + '</a>'
: value;
}).join(', ');
}).join(join || ', ') : '';
}
function identify(data) {
@ -352,8 +353,8 @@ oml.ui.infoView = function(identifyData) {
fontWeight: 'bold'
})
.html(
data.title
|| '<span class="OxLight">'
data.title ? Ox.encodeHTMLEntities(data.title)
: '<span class="OxLight">'
+ Ox._('No Title')
+ '</span>'
)
@ -375,10 +376,10 @@ oml.ui.infoView = function(identifyData) {
.css({
marginTop: '8px'
})
.text(
(data.place || []).join(' ; ')
.html(
(formatValue(data.place, 'place', ' ; '))
+ (data.place && (data.publisher || data.date) ? ' : ' : '')
+ (data.publisher || '')
+ (formatValue(data.publisher, 'publisher'))
+ (data.publisher && data.date ? ', ' : '')
+ (data.date || '')
)
@ -390,10 +391,10 @@ oml.ui.infoView = function(identifyData) {
.css({
marginTop: '8px'
})
.text(
(data.edition || '')
.html(
(Ox.encodeHTMLEntities(data.edition || ''))
+ (data.edition && data.language ? '; ' : '')
+ (data.language || '')
+ (formatValue(data.language, 'language'))
)
.appendTo($info);
}
@ -404,7 +405,9 @@ oml.ui.infoView = function(identifyData) {
marginTop: '8px',
textAlign: 'justify'
})
.html(Ox.encodeHTMLEntities(data.classification))
.html(
Ox.formatValue(data.classification, 'classification')
)
.appendTo($info);
}
@ -414,7 +417,9 @@ oml.ui.infoView = function(identifyData) {
marginTop: '8px',
textAlign: 'justify'
})
.html(Ox.encodeHTMLEntities(data.description))
.html(
Ox.encodeHTMLEntities(data.description)
)
.appendTo($info);
}

View file

@ -5,7 +5,8 @@ txtjs.open = function(url) {
Ox.get(url, function(text) {
var $body = Ox.$('body')
.css({
backgroundColor: 'rgb(255, 255, 255)'
backgroundColor: 'rgb(255, 255, 255)',
overflowX: 'hidden'
}),
$text = Ox.$('<div>')
.css({
@ -29,28 +30,32 @@ txtjs.open = function(url) {
.css({
fontSize: '2px',
lineHeight: '3px',
cursor: 'pointer',
WebkitUserSelect: 'none'
})
.on({
click: function(e) {
mousedown: function(e) {
var offset = 'offsetY' in e ? e.offsetY : e.layerY;
document.body.scrollTop = offset / factor;
Ox.print('!', offset)
//Ox.print('!', offset)
}
})
.appendTo($scroll),
scale;
textHeight, scrollTextHeight, factor;
text = Ox.encodeHTMLEntities(text)
.replace(/\r\n/g, '\n')
.replace(/[\r\n]/g, '<br>');
$text.html(text);
$scrollText.html(text);
var textHeight = $text[0].clientHeight,
scrollTextHeight = $scrollText[0].clientHeight,
window.onresize = function() {
textHeight = $text[0].clientHeight - window.innerHeight,
scrollTextHeight = $scrollText[0].clientHeight - (window.innerHeight - 32),
factor = scrollTextHeight / textHeight;
};
window.onscroll = function() {
$scroll[0].scrollTop = window.pageYOffset * factor;
};
window.onresize();
});
});
};

View file

@ -30,28 +30,31 @@ def render(infile, outfile):
for line in f:
line = line.decode('utf-8').strip()
for line_ in line.decode('utf-8').strip().split('\r'):
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),
lines = wrapText(
line_,
font_file,
font_size,
(0)
image_size[0] - 2 * margin,
# we don't want the last line that ends with an ellipsis
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:
break