Skip to content

Commit

Permalink
📦 Release 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Apr 1, 2018
1 parent dccd856 commit 17834fc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 43 deletions.
2 changes: 1 addition & 1 deletion hocrjs/dist/hocr.fullscreen.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions hocrjs/dist/hocr.user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ==UserScript==
// @name hocr-viewer
// @namespace http://github.com/kba/hocrjs
// @updateURL https://unpkg.com/[email protected]-2/dist/hocr.user.js
// @version 0.4.0-2
// @updateURL https://unpkg.com/[email protected]/dist/hocr.user.js
// @version 0.4.0
// @description Add hocr-viewer controls to a apage
// @author kba
// @include http://*/*
Expand All @@ -24,7 +24,7 @@
'use strict'
function injectHocrViewer() {
const script = document.createElement('script')
script.src = "https://unpkg.com/[email protected]-2/dist/hocr.fullscreen.js?cachebuster=" + Math.random() * 10000000000000000
script.src = "https://unpkg.com/[email protected]/dist/hocr.fullscreen.js?cachebuster=" + Math.random() * 10000000000000000
script.type = 'text/javascript'
document.querySelector('body').appendChild(script)
}
Expand Down
4 changes: 2 additions & 2 deletions hocrjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hocrjs",
"version": "0.4.0-2",
"version": "0.4.0",
"description": "Vue component for viewing hOCR files, also usable standalone",
"main": "dist/hocr.fullscreen.js",
"bin": {
Expand Down Expand Up @@ -48,6 +48,6 @@
},
"dependencies": {
"hocr-dom": "0.1.4",
"vue-hocr": "^0.4.0-2"
"vue-hocr": "^0.4.0"
}
}
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"hocrjs",
"vue-hocr"
],
"version": "0.4.0-2"
"version": "0.4.0"
}
59 changes: 24 additions & 35 deletions vue-hocr/dist/vue-hocr.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ exports.default = {
var _HocrDOM$getHocrPrope = _hocrDom.HocrDOM.getHocrProperties(_hocrDom.HocrDOM.queryHocr(page)),
bbox = _HocrDOM$getHocrPrope.bbox;

var pageHeight = bbox[3] - bbox[1];
var pageHeight = bbox[3] - bbox[1] + 1;
return {
transform: 'scale(' + this.currentZoom + ')',
'transform-origin': 'top left',
Expand Down Expand Up @@ -1985,8 +1985,8 @@ var Layout = function () {
el.style.position = 'fixed';
el.style.left = bbox[0] + "px";
el.style.top = bbox[1] + "px";
el.style.width = bbox[2] - bbox[0] + "px";
el.style.height = bbox[3] - bbox[1] + "px";
el.style.width = bbox[2] - bbox[0] + 1 + "px";
el.style.height = bbox[3] - bbox[1] + 1 + "px";
});
}
}]);
Expand Down Expand Up @@ -2023,10 +2023,9 @@ var ScaleFont = function () {
_classCallCheck(this, ScaleFont);

this.fontFamily = fontFamily;
this.maxFontSize = 128;
this.minFontSize = 2;
this.wrapClass = 'hocr-viewer-wrap';
this.cache = {};
this.wrap = {};
}

_createClass(ScaleFont, [{
Expand All @@ -2037,46 +2036,36 @@ var ScaleFont = function () {
console.time('toggleScaleFont');

// wrapper element containing wrappers for font-size expansion
var wrap = document.createElement('span');
wrap.classList.add(this.wrapClass);
document.body.appendChild(wrap);
this.wrap = document.createElement('span');
this.wrap.classList.add(this.wrapClass);
document.body.appendChild(this.wrap);
_hocrDom.HocrDOM.queryHocrAll(dom, { terminal: true }).forEach(function (el) {
return _this.scaleFont(el, wrap);
return _this.scaleFont(el);
});
wrap.remove();
this.wrap.remove();

console.timeEnd('toggleScaleFont');
}
}, {
key: 'scaleFont',
value: function scaleFont(el, wrap) {
value: function scaleFont(el) {
var text = el.textContent.trim();
if (text.length === 0) return;
if (!(text in this.cache)) {
// wrap.setAttribute('class', el.getAttribute('class'))
// wrap.style.width = '100%'
wrap.style.fontFamily = el.style.fontFamily;
wrap.innerHTML = text;
var height = parseInt(el.style.height.replace('px', ''));
var width = parseInt(el.style.width.replace('px', ''));
var fontSize = Math.min(width, height);
if (fontSize <= this.minFontSize) {
this.cache[text] = this.minFontSize;
} else {
// console.log({fontSize, width: width, height:height, min, el})
wrap.style.fontSize = fontSize + 'px';
if (fontSize > this.minFontSize && wrap.offsetHeight > height) {
fontSize -= wrap.offsetHeight - height;
wrap.style.fontSize = fontSize + 'px';
}
while (fontSize > this.minFontSize && wrap.offsetWidth > width) {
wrap.style.fontSize = --fontSize + 'px';
}
// if (iterations > 1) console.debug(iterations, text, wrap.offsetHeight, height, wrap.offsetWidth, width)
this.cache[text] = fontSize - 1;
}
this.wrap.style.fontFamily = el.style.fontFamily;
this.wrap.innerHTML = text;
var height = parseInt(el.style.height.replace('px', ''));
var width = parseInt(el.style.width.replace('px', ''));
var fontSize = height;
if (fontSize > this.minFontSize) {
this.wrap.style.fontSize = fontSize + 'px';
var fontSizeH = fontSize * height / this.wrap.offsetHeight;
var fontSizeW = fontSize * width / this.wrap.offsetWidth;
fontSize = fontSizeH < fontSizeW ? fontSizeH : fontSizeW;
}
if (fontSize < this.minFontSize) {
fontSize = this.minFontSize;
}
el.style.fontSize = this.cache[text] + 'px';
el.style.fontSize = fontSize + 'px';
}
}]);

Expand Down
2 changes: 1 addition & 1 deletion vue-hocr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-hocr",
"version": "0.4.0-2",
"version": "0.4.0",
"description": "Vue component for viewing hOCR files",
"main": "dist/vue-hocr.js",
"repository": {
Expand Down

0 comments on commit 17834fc

Please sign in to comment.