bscheibel 4 роки тому
батько
коміт
4c0cc5169c

+ 117 - 103
app/config.json

@@ -1,107 +1,121 @@
 {
    "Ra":{
-      "ISO4287":[
-         "Symbole",
-         "Tabelle",
-         "Definition"
-      ]
+      "ISO4287":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
    },
    "Rpk":{
-      "ISO4287":[
-         "Symbole",
-         "Tabelle",
-         "Definition"
-      ]
-   },
-  "Rz":{
-    "ISO14405-1" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "CT":{
-    "ISO14405-1" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "GX":{
-    "ISO14405-1" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "GG":{
-    "ISO14405-1" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "H\\d{1,2}":{
-    "ISO286-1" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "h\\d{1,2}":{
-    "ISO286-1" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "M\\d{1,2}":{
-    "ISO6410" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "\u27C2":{
-    "ISO1101" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "\u25CE":{
-    "ISO1101" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "\u232D":{
-    "ISO1101" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "\u2225":{
-    "ISO1101" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "\u232F":{
-    "ISO1101" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "\u2316":{
-    "ISO1101" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-    "\u2313":{
-    "ISO1101" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  },
-  "\u23E5":{
-    "ISO1101" : [
-      "Symbole",
-      "Tabelle",
-      "Definition"]
-  }
-}
-
+      "ISO4287":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "Rz":{
+      "ISO14405-1":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "CT":{
+      "ISO14405-1":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "GX":{
+      "ISO14405-1":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "GG":{
+      "ISO14405-1":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "H\\d{1,2}":{
+      "ISO286-1":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "h\\d{1,2}":{
+      "ISO286-1":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "M\\d{1,2}":{
+      "ISO6410":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "\u27C2":{
+      "ISO1101":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "\u25CE":{
+      "ISO1101":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "\u232D":{
+      "ISO1101":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "\u2225":{
+      "ISO1101":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "\u232F":{
+      "ISO1101":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "\u2316":{
+      "ISO1101":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "\u2313":{
+      "ISO1101":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   },
+   "\u23E5":{
+      "ISO1101":{
+         "Symbole":1,
+         "Tabelle":2,
+         "Definition":3
+      }
+   }
+}

+ 20 - 0
app/static/css/text_layer_builder.css

@@ -73,3 +73,23 @@
 .textLayer .endOfContent.active {
   top: 0px;
 }
+
+#text-layer {
+   position: absolute;
+    left: 0;
+    top: 0;
+    right: 0;
+    bottom: 0;
+    overflow: hidden;
+    opacity: 0.2;
+    line-height: 1.0;
+}
+
+#text-layer > div {
+    color: transparent;
+    position: absolute;
+    white-space: pre;
+    cursor: text;
+    transform-origin: 0% 0%;
+}
+

+ 30 - 8
app/static/js/js_libs/ui.js

@@ -51,22 +51,44 @@ function ui_add_tab(tabbed,title,id,closeable,additionalclasses) {
   }
 }
 
-function create_new_tab(title, id) {
-    console.log(title,id);
+function create_new_tab(title, id,terms) {
+    //console.log(title,id);
+    var terms = atob(terms);
     var theDiv = document.getElementById(id);
-    var content = document.createTextNode(id);
-    var content = document.createTextNode(id);
+    //var content = document.createTextNode("Test");
+    //var content = document.createTextNode(terms);
     var newElement = document.createElement('div');
-    newElement.setAttribute('id', id);
+    var textElement = document.createElement('div');
+    var array_terms = JSON.parse(terms);
+    var len = Object.keys(array_terms).length;
+    console.log(len);
+    textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','start')> Start of ISO File. </a><br>";
+    for (var key in array_terms) {
+        console.log(key);
+        //theDiv.appendChild(document.createTextNode(terms[key]));
+        textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','"+array_terms[key]+"')>"+key+" </a><br>";
+    }
+    newElement.setAttribute('id', "iso_"+id);
+    //console.log(terms);
     newElement.innerHTML = "<iframe width=100% height=1000px src= '/static/isos/" + id  + ".PDF')'> </iframe>";
-    theDiv.appendChild(content);
+    theDiv.appendChild(textElement);
     theDiv.appendChild(newElement);
     return true;
 }
 
-function ui_add_tab_active(tabbed,title,id,closeable,additionalclasses) {
+function change_isos_tab(id, term){
+    var theDiv = document.getElementById("iso_"+id);
+    if (term = "start"){
+        term = 1;
+    }
+    theDiv.innerHTML = "<iframe width=100% height=1000px src= '/static/isos/" + id  + ".PDF#page="+ term+"')'> </iframe>";
+    return true;
+}
+
+function ui_add_tab_active(tabbed,title,id,closeable,additionalclasses, terms) {
   var state = ui_add_tab(tabbed,title,id,closeable,additionalclasses);
-  if (state) { create_new_tab(title, id); }
+  console.log("test");
+  if (state) { create_new_tab(title, id, terms); }
   if (state) { ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']')); }
   return state;
 }

Різницю між файлами не показано, бо вона завелика
+ 41433 - 90
app/static/js/pdf.js


+ 177 - 406
app/static/js/text_layer_builder.js

@@ -1,431 +1,202 @@
-/* Copyright 2012 Mozilla Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
+/**
+ * Code extracted from pdf.js' viewer.js file. This contains code that is relevant to building the text overlays. I
+ * have removed dependencies on viewer.js and viewer.html.
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ *   -- Vivin Suresh Paliath (http://vivin.net)
  */
 
-import { getGlobalEventBus } from './ui_utils';
-import { renderTextLayer } from 'pdfjs-lib';
+var CustomStyle = (function CustomStyleClosure() {
 
-const EXPAND_DIVS_TIMEOUT = 300; // ms
+    // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
+    //              animate-css-transforms-firefox-webkit.html
+    // in some versions of IE9 it is critical that ms appear in this list
+    // before Moz
+    var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
+    var _cache = { };
 
-/**
- * @typedef {Object} TextLayerBuilderOptions
- * @property {HTMLDivElement} textLayerDiv - The text layer container.
- * @property {EventBus} eventBus - The application event bus.
- * @property {number} pageIndex - The page index.
- * @property {PageViewport} viewport - The viewport of the text layer.
- * @property {PDFFindController} findController
- * @property {boolean} enhanceTextSelection - Option to turn on improved
- *   text selection.
- */
+    function CustomStyle() {
+    }
+
+    CustomStyle.getProp = function get(propName, element) {
+        // check cache only when no element is given
+        if (arguments.length == 1 && typeof _cache[propName] == 'string') {
+            return _cache[propName];
+        }
+
+        element = element || document.documentElement;
+        var style = element.style, prefixed, uPropName;
+
+        // test standard property first
+        if (typeof style[propName] == 'string') {
+            return (_cache[propName] = propName);
+        }
+
+        // capitalize
+        uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
+
+        // test vendor specific properties
+        for (var i = 0, l = prefixes.length; i < l; i++) {
+            prefixed = prefixes[i] + uPropName;
+            if (typeof style[prefixed] == 'string') {
+                return (_cache[propName] = prefixed);
+            }
+        }
+
+        //if all fails then set to undefined
+        return (_cache[propName] = 'undefined');
+    };
+
+    CustomStyle.setProp = function set(propName, element, str) {
+        var prop = this.getProp(propName);
+        if (prop != 'undefined')
+            element.style[prop] = str;
+    };
+
+    return CustomStyle;
+})();
+
+var TextLayerBuilder = function textLayerBuilder(textLayerDiv, pageIdx) {
+    var textLayerFrag = document.createDocumentFragment();
 
-/**
- * The text layer builder provides text selection functionality for the PDF.
- * It does this by creating overlay divs over the PDF's text. These divs
- * contain text that matches the PDF text they are overlaying. This object
- * also provides a way to highlight text that is being searched for.
- */
-class TextLayerBuilder {
-  constructor({ textLayerDiv, eventBus, pageIndex, viewport,
-                findController = null, enhanceTextSelection = false, }) {
     this.textLayerDiv = textLayerDiv;
-    this.eventBus = eventBus || getGlobalEventBus();
-    this.textContent = null;
-    this.textContentItemsStr = [];
-    this.textContentStream = null;
-    this.renderingDone = false;
-    this.pageIdx = pageIndex;
-    this.pageNumber = this.pageIdx + 1;
+    this.layoutDone = false;
+    this.divContentDone = false;
+    this.pageIdx = pageIdx;
     this.matches = [];
-    this.viewport = viewport;
-    this.textDivs = [];
-    this.findController = findController;
-    this.textLayerRenderTask = null;
-    this.enhanceTextSelection = enhanceTextSelection;
-
-    this._onUpdateTextLayerMatches = null;
-    this._bindMouse();
-  }
-
-  /**
-   * @private
-   */
-  _finishRendering() {
-    this.renderingDone = true;
-
-    if (!this.enhanceTextSelection) {
-      let endOfContent = document.createElement('div');
-      endOfContent.className = 'endOfContent';
-      this.textLayerDiv.appendChild(endOfContent);
-    }
 
-    this.eventBus.dispatch('textlayerrendered', {
-      source: this,
-      pageNumber: this.pageNumber,
-      numTextDivs: this.textDivs.length,
-    });
-  }
-
-  /**
-   * Renders the text layer.
-   *
-   * @param {number} timeout - (optional) wait for a specified amount of
-   *                           milliseconds before rendering
-   */
-  render(timeout = 0) {
-    if (!(this.textContent || this.textContentStream) || this.renderingDone) {
-      return;
-    }
-    this.cancel();
-
-    this.textDivs = [];
-    let textLayerFrag = document.createDocumentFragment();
-    this.textLayerRenderTask = renderTextLayer({
-      textContent: this.textContent,
-      textContentStream: this.textContentStream,
-      container: textLayerFrag,
-      viewport: this.viewport,
-      textDivs: this.textDivs,
-      textContentItemsStr: this.textContentItemsStr,
-      timeout,
-      enhanceTextSelection: this.enhanceTextSelection,
-    });
-    this.textLayerRenderTask.promise.then(() => {
-      this.textLayerDiv.appendChild(textLayerFrag);
-      this._finishRendering();
-      this._updateMatches();
-    }, function (reason) {
-      // Cancelled or failed to render text layer; skipping errors.
-    });
-
-    if (!this._onUpdateTextLayerMatches) {
-      this._onUpdateTextLayerMatches = (evt) => {
-        if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
-          this._updateMatches();
-        }
-      };
-      this.eventBus.on('updatetextlayermatches',
-                       this._onUpdateTextLayerMatches);
-    }
-  }
-
-  /**
-   * Cancel rendering of the text layer.
-   */
-  cancel() {
-    if (this.textLayerRenderTask) {
-      this.textLayerRenderTask.cancel();
-      this.textLayerRenderTask = null;
-    }
-    if (this._onUpdateTextLayerMatches) {
-      this.eventBus.off('updatetextlayermatches',
-                        this._onUpdateTextLayerMatches);
-      this._onUpdateTextLayerMatches = null;
-    }
-  }
-
-  setTextContentStream(readableStream) {
-    this.cancel();
-    this.textContentStream = readableStream;
-  }
-
-  setTextContent(textContent) {
-    this.cancel();
-    this.textContent = textContent;
-  }
-
-  _convertMatches(matches, matchesLength) {
-    // Early exit if there is nothing to convert.
-    if (!matches) {
-      return [];
-    }
-    const { findController, textContentItemsStr, } = this;
-
-    let i = 0, iIndex = 0;
-    const end = textContentItemsStr.length - 1;
-    const queryLen = findController.state.query.length;
-    const result = [];
-
-    for (let m = 0, mm = matches.length; m < mm; m++) {
-      // Calculate the start position.
-      let matchIdx = matches[m];
-
-      // Loop over the divIdxs.
-      while (i !== end &&
-             matchIdx >= (iIndex + textContentItemsStr[i].length)) {
-        iIndex += textContentItemsStr[i].length;
-        i++;
-      }
-
-      if (i === textContentItemsStr.length) {
-        console.error('Could not find a matching mapping');
-      }
-
-      let match = {
-        begin: {
-          divIdx: i,
-          offset: matchIdx - iIndex,
-        },
-      };
-
-      // Calculate the end position.
-      if (matchesLength) { // Multiterm search.
-        matchIdx += matchesLength[m];
-      } else { // Phrase search.
-        matchIdx += queryLen;
-      }
-
-      // Somewhat the same array as above, but use > instead of >= to get
-      // the end position right.
-      while (i !== end &&
-             matchIdx > (iIndex + textContentItemsStr[i].length)) {
-        iIndex += textContentItemsStr[i].length;
-        i++;
-      }
-
-      match.end = {
-        divIdx: i,
-        offset: matchIdx - iIndex,
-      };
-      result.push(match);
-    }
-    return result;
-  }
+    this.beginLayout = function textLayerBuilderBeginLayout() {
+        this.textDivs = [];
+        this.renderingDone = false;
+    };
 
-  _renderMatches(matches) {
-    // Early exit if there is nothing to render.
-    if (matches.length === 0) {
-      return;
-    }
-    const { findController, pageIdx, textContentItemsStr, textDivs, } = this;
-
-    const isSelectedPage = (pageIdx === findController.selected.pageIdx);
-    const selectedMatchIdx = findController.selected.matchIdx;
-    const highlightAll = findController.state.highlightAll;
-    let prevEnd = null;
-    let infinity = {
-      divIdx: -1,
-      offset: undefined,
+    this.endLayout = function textLayerBuilderEndLayout() {
+        this.layoutDone = true;
+        this.insertDivContent();
     };
 
-    function beginText(begin, className) {
-      let divIdx = begin.divIdx;
-      textDivs[divIdx].textContent = '';
-      appendTextToDiv(divIdx, 0, begin.offset, className);
-    }
+    this.renderLayer = function textLayerBuilderRenderLayer() {
+        var textDivs = this.textDivs;
+        var bidiTexts = this.textContent.bidiTexts;
+        var textLayerDiv = this.textLayerDiv;
+        var canvas = document.createElement('canvas');
+        var ctx = canvas.getContext('2d');
+
+        // No point in rendering so many divs as it'd make the browser unusable
+        // even after the divs are rendered
+        var MAX_TEXT_DIVS_TO_RENDER = 100000;
+        if (textDivs.length > MAX_TEXT_DIVS_TO_RENDER)
+            return;
+
+        for (var i = 0, ii = textDivs.length; i < ii; i++) {
+            var textDiv = textDivs[i];
+            if ('isWhitespace' in textDiv.dataset) {
+                continue;
+            }
+            textLayerFrag.appendChild(textDiv);
 
-    function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
-      let div = textDivs[divIdx];
-      let content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
-      let node = document.createTextNode(content);
-      if (className) {
-        let span = document.createElement('span');
-        span.className = className;
-        span.appendChild(node);
-        div.appendChild(span);
-        return;
-      }
-      div.appendChild(node);
-    }
+            ctx.font = textDiv.style.fontSize + ' ' + textDiv.style.fontFamily;
+            var width = ctx.measureText(textDiv.textContent).width;
 
-    let i0 = selectedMatchIdx, i1 = i0 + 1;
-    if (highlightAll) {
-      i0 = 0;
-      i1 = matches.length;
-    } else if (!isSelectedPage) {
-      // Not highlighting all and this isn't the selected page, so do nothing.
-      return;
-    }
+            if (width > 0) {
+                var textScale = textDiv.dataset.canvasWidth / width;
 
-    for (let i = i0; i < i1; i++) {
-      let match = matches[i];
-      let begin = match.begin;
-      let end = match.end;
-      const isSelected = (isSelectedPage && i === selectedMatchIdx);
-      const highlightSuffix = (isSelected ? ' selected' : '');
-
-      if (isSelected) { // Attempt to scroll the selected match into view.
-        findController.scrollMatchIntoView({
-          element: textDivs[begin.divIdx],
-          pageIndex: pageIdx,
-          matchIndex: selectedMatchIdx,
-        });
-      }
-
-      // Match inside new div.
-      if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
-        // If there was a previous div, then add the text at the end.
-        if (prevEnd !== null) {
-          appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
-        }
-        // Clear the divs and set the content until the starting point.
-        beginText(begin);
-      } else {
-        appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
-      }
-
-      if (begin.divIdx === end.divIdx) {
-        appendTextToDiv(begin.divIdx, begin.offset, end.offset,
-                        'highlight' + highlightSuffix);
-      } else {
-        appendTextToDiv(begin.divIdx, begin.offset, infinity.offset,
-                        'highlight begin' + highlightSuffix);
-        for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
-          textDivs[n0].className = 'highlight middle' + highlightSuffix;
+                var transform = 'scale(' + textScale + ', 1)';
+                if (bidiTexts[i].dir === 'ttb') {
+                    transform = 'rotate(90deg) ' + transform;
+                }
+                CustomStyle.setProp('transform', textDiv, transform);
+                CustomStyle.setProp('transformOrigin', textDiv, '0% 0%');
+
+                textLayerDiv.appendChild(textDiv);
+            }
         }
-        beginText(end, 'highlight end' + highlightSuffix);
-      }
-      prevEnd = end;
-    }
 
-    if (prevEnd) {
-      appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
-    }
-  }
+        this.renderingDone = true;
 
-  _updateMatches() {
-    // Only show matches when all rendering is done.
-    if (!this.renderingDone) {
-      return;
-    }
-    const {
-      findController, matches, pageIdx, textContentItemsStr, textDivs,
-    } = this;
-    let clearedUntilDivIdx = -1;
-
-    // Clear all current matches.
-    for (let i = 0, ii = matches.length; i < ii; i++) {
-      let match = matches[i];
-      let begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
-      for (let n = begin, end = match.end.divIdx; n <= end; n++) {
-        let div = textDivs[n];
-        div.textContent = textContentItemsStr[n];
-        div.className = '';
-      }
-      clearedUntilDivIdx = match.end.divIdx + 1;
-    }
+        textLayerDiv.appendChild(textLayerFrag);
+    };
 
-    if (!findController || !findController.highlightMatches) {
-      return;
-    }
-    // Convert the matches on the `findController` into the match format
-    // used for the textLayer.
-    const pageMatches = findController.pageMatches[pageIdx] || null;
-    const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
-
-    this.matches = this._convertMatches(pageMatches, pageMatchesLength);
-    this._renderMatches(this.matches);
-  }
-
-  /**
-   * Improves text selection by adding an additional div where the mouse was
-   * clicked. This reduces flickering of the content if the mouse is slowly
-   * dragged up or down.
-   *
-   * @private
-   */
-  _bindMouse() {
-    let div = this.textLayerDiv;
-    let expandDivsTimer = null;
-
-    div.addEventListener('mousedown', (evt) => {
-      if (this.enhanceTextSelection && this.textLayerRenderTask) {
-        this.textLayerRenderTask.expandTextDivs(true);
-        if ((typeof PDFJSDev === 'undefined' ||
-             !PDFJSDev.test('FIREFOX || MOZCENTRAL')) &&
-            expandDivsTimer) {
-          clearTimeout(expandDivsTimer);
-          expandDivsTimer = null;
-        }
-        return;
-      }
-
-      let end = div.querySelector('.endOfContent');
-      if (!end) {
-        return;
-      }
-      if (typeof PDFJSDev === 'undefined' ||
-          !PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
-        // On non-Firefox browsers, the selection will feel better if the height
-        // of the `endOfContent` div is adjusted to start at mouse click
-        // location. This avoids flickering when the selection moves up.
-        // However it does not work when selection is started on empty space.
-        let adjustTop = evt.target !== div;
-        if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
-          adjustTop = adjustTop && window.getComputedStyle(end).
-            getPropertyValue('-moz-user-select') !== 'none';
-        }
-        if (adjustTop) {
-          let divBounds = div.getBoundingClientRect();
-          let r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
-          end.style.top = (r * 100).toFixed(2) + '%';
+    this.setupRenderLayoutTimer = function textLayerSetupRenderLayoutTimer() {
+        // Schedule renderLayout() if user has been scrolling, otherwise
+        // run it right away
+        var RENDER_DELAY = 200; // in ms
+        var self = this;
+        //0 was originally PDFView.lastScroll
+        if (Date.now() - 0 > RENDER_DELAY) {
+            // Render right away
+            this.renderLayer();
+        } else {
+            // Schedule
+            if (this.renderTimer)
+                clearTimeout(this.renderTimer);
+            this.renderTimer = setTimeout(function () {
+                self.setupRenderLayoutTimer();
+            }, RENDER_DELAY);
         }
-      }
-      end.classList.add('active');
-    });
-
-    div.addEventListener('mouseup', () => {
-      if (this.enhanceTextSelection && this.textLayerRenderTask) {
-        if (typeof PDFJSDev === 'undefined' ||
-            !PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
-          expandDivsTimer = setTimeout(() => {
-            if (this.textLayerRenderTask) {
-              this.textLayerRenderTask.expandTextDivs(false);
+    };
+
+    this.appendText = function textLayerBuilderAppendText(geom) {
+        var textDiv = document.createElement('div');
+
+        // vScale and hScale already contain the scaling to pixel units
+        var fontHeight = geom.fontSize * Math.abs(geom.vScale);
+        textDiv.dataset.canvasWidth = geom.canvasWidth * geom.hScale;
+        textDiv.dataset.fontName = geom.fontName;
+
+        textDiv.style.fontSize = fontHeight + 'px';
+        textDiv.style.fontFamily = geom.fontFamily;
+        textDiv.style.left = geom.x + 'px';
+        textDiv.style.top = (geom.y - fontHeight) + 'px';
+
+        // The content of the div is set in the `setTextContent` function.
+
+        this.textDivs.push(textDiv);
+    };
+
+    this.insertDivContent = function textLayerUpdateTextContent() {
+        // Only set the content of the divs once layout has finished, the content
+        // for the divs is available and content is not yet set on the divs.
+        if (!this.layoutDone || this.divContentDone || !this.textContent)
+            return;
+
+        this.divContentDone = true;
+
+        var textDivs = this.textDivs;
+        var bidiTexts = this.textContent.bidiTexts;
+
+        for (var i = 0; i < bidiTexts.length; i++) {
+            var bidiText = bidiTexts[i];
+            var textDiv = textDivs[i];
+            if (!/\S/.test(bidiText.str)) {
+                textDiv.dataset.isWhitespace = true;
+                continue;
             }
-            expandDivsTimer = null;
-          }, EXPAND_DIVS_TIMEOUT);
-        } else {
-          this.textLayerRenderTask.expandTextDivs(false);
+
+            textDiv.textContent = bidiText.str;
+            // bidiText.dir may be 'ttb' for vertical texts.
+            textDiv.dir = bidiText.dir === 'rtl' ? 'rtl' : 'ltr';
         }
-        return;
-      }
-
-      let end = div.querySelector('.endOfContent');
-      if (!end) {
-        return;
-      }
-      if (typeof PDFJSDev === 'undefined' ||
-          !PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
-        end.style.top = '';
-      }
-      end.classList.remove('active');
-    });
-  }
-}
+
+        this.setupRenderLayoutTimer();
+    };
+
+    this.setTextContent = function textLayerBuilderSetTextContent(textContent) {
+        this.textContent = textContent;
+        this.insertDivContent();
+    };
+};
 
 /**
- * @implements IPDFTextLayerFactory
+ * Returns scale factor for the canvas. It makes sense for the HiDPI displays.
+ * @return {Object} The object with horizontal (sx) and vertical (sy)
+ scales. The scaled property is set to false if scaling is
+ not required, true otherwise.
  */
-class DefaultTextLayerFactory {
-  /**
-   * @param {HTMLDivElement} textLayerDiv
-   * @param {number} pageIndex
-   * @param {PageViewport} viewport
-   * @param {boolean} enhanceTextSelection
-   * @returns {TextLayerBuilder}
-   */
-  createTextLayerBuilder(textLayerDiv, pageIndex, viewport,
-                         enhanceTextSelection = false) {
-    return new TextLayerBuilder({
-      textLayerDiv,
-      pageIndex,
-      viewport,
-      enhanceTextSelection,
-    });
-  }
-}
-
-export {
-  TextLayerBuilder,
-  DefaultTextLayerFactory,
-};
+function getOutputScale() {
+    var pixelRatio = 'devicePixelRatio' in window ? window.devicePixelRatio : 1;
+    return {
+        sx: pixelRatio,
+        sy: pixelRatio,
+        scaled: pixelRatio != 1
+    };
+}

+ 53 - 0
app/static/js/textlayer_pdfjs.js

@@ -0,0 +1,53 @@
+/* Copyright 2014 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+if (!pdfjsLib.getDocument || !pdfjsViewer.PDFPageView) {
+  alert('Please build the pdfjs-dist library using\n' +
+        '  `gulp dist-install`');
+}
+
+
+var DEFAULT_URL = {{og_filename}};
+var PAGE_TO_VIEW = 1;
+var SCALE = 1.0;
+
+var container = document.getElementById('pageContainer');
+
+// Loading document.
+var loadingTask = pdfjsLib.getDocument({
+  url: DEFAULT_URL,
+  cMapUrl: CMAP_URL,
+  cMapPacked: CMAP_PACKED,
+});
+loadingTask.promise.then(function(pdfDocument) {
+  // Document loaded, retrieving the page.
+  return pdfDocument.getPage(PAGE_TO_VIEW).then(function (pdfPage) {
+    // Creating the page view with default parameters.
+    var pdfPageView = new pdfjsViewer.PDFPageView({
+      container: container,
+      id: PAGE_TO_VIEW,
+      scale: SCALE,
+      defaultViewport: pdfPage.getViewport({ scale: SCALE, }),
+      // We can enable text/annotations layers, if needed
+      textLayerFactory: new pdfjsViewer.DefaultTextLayerFactory(),
+      annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory(),
+    });
+    // Associates the actual page with the view, and drawing it
+    pdfPageView.setPdfPage(pdfPage);
+    return pdfPageView.draw();
+  });
+});

Різницю між файлами не показано, бо вона завелика
+ 71 - 1856
app/static/js/viewer.css


+ 1 - 2
app/templates/index.html

@@ -1,5 +1,4 @@
-<!--
-  This file is part of centurio.work/edi.
+<!--This file is part of centurio.work/edi.
 
   centurio.work/edi is free software: you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the Free

+ 114 - 0
app/templates/pdf_textlayer.html

@@ -0,0 +1,114 @@
+<!DOCTYPE html><meta charset="utf-8"/>
+
+<!--<script type="javascript" src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.3.200/pdf.js"></script> das funktioniert!!!!!
+<script type="javascript" src="https://unpkg.com/pdfjs-dist@latest/build/pdf.js" ></script>
+<script type="javascript" src="{{ url_for('static', filename='js/pdf.js') }}"></script>
+<script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
+<script src="https://mozilla.github.io/pdf.js/build/pdf.js"></script>
+-->
+
+<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@1.9/build/pdf.min.js"></script>
+<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@1.9/web/pdf_viewer.js"></script>
+<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@1.9/build/pdf.js"></script>
+<script type="javascript" src="{{ url_for('static', filename='js/text_layer_builder.js') }}"></script>
+<script type="javascript" src="{{ url_for('static', filename='js/ui_utils.js') }}"></script>
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
+<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pdfjs-dist@2.2.228/web/pdf_viewer.css">
+<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"/>
+<link rel="stylesheet" href="{{ url_for('static', filename='css/text_layer_builder.css') }}" />
+
+
+
+<body>
+<div id="container" > {{og_filename}}</div>
+<div id="text-layer"></div>
+<script>
+
+
+var og_filename = "{{og_filename}}";
+var url = "{{ url_for('send_file', filename=og_filename) }}";
+console.log(og_filename);
+
+var pdfjsLib = window['pdfjs-dist/build/pdf'];
+
+pdfjsLib.getDocument(url)
+  .promise.then(function(pdf) {
+
+    // Get div#container and cache it for later use
+    var container = document.getElementById("container");
+
+    // Loop from 1 to total_number_of_pages in PDF document
+    for (var i = 1; i <= pdf.numPages; i++) {
+
+        // Get desired page
+        pdf.getPage(i).then(function(page) {
+
+          var scale = 1.5;
+          var viewport = page.getViewport({scale: scale});
+          var div = document.createElement("div");
+
+          // Set id attribute with page-#{pdf_page_number} format
+          div.setAttribute("id", "page-" + (page.pageIndex + 1));
+
+          // This will keep positions of child elements as per our needs
+          div.setAttribute("style", "position: relative");
+
+          // Append div within div#container
+          container.appendChild(div);
+
+          // Create a new Canvas element
+          var canvas = document.createElement("canvas");
+
+          // Append Canvas within div#page-#{pdf_page_number}
+          div.appendChild(canvas);
+
+          var context = canvas.getContext('2d');
+          canvas.height = viewport.height;
+          canvas.width = viewport.width;
+
+          var renderContext = {
+            canvasContext: context,
+            viewport: viewport
+          };
+
+          // Render PDF page
+         page.render(renderContext).promise.then(function() {
+    // Returns a promise, on resolving it will return text contents of the page
+    return page.getTextContent();
+}).then(function(textContent) {
+     // PDF canvas
+    var pdf_canvas = $("#canvas");
+
+    // Canvas offset
+    var canvas_offset = pdf_canvas.offset();
+
+    // Canvas height
+    var canvas_height =  canvas.height;
+
+    // Canvas width
+    var canvas_width = canvas.width;
+
+    // Assign CSS to the text-layer element
+    $("#text-layer").css({ left: canvas_offset.left + 'px', top: canvas_offset.top + 'px', height: canvas_height + 'px', width: canvas_width + 'px' });
+
+    // Pass the data to the method for rendering of text over the pdf canvas.
+    PDFJS.renderTextLayer({
+        textContent: textContent,
+        container: $("#text-layer").get(0),
+        viewport: viewport,
+        textDivs: []
+    });
+});
+
+
+        });
+
+    }
+
+});
+
+
+
+</script>
+</body>
+</html>

+ 23 - 13
app/templates/show_pdf.html

@@ -1,24 +1,30 @@
 <!DOCTYPE html><meta charset="utf-8"/>
-<link rel="stylesheet" href="{{ url_for('static', filename='css/text_layer_builder.css') }}" />
-<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
-<script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
-<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"/>
 
-<script type="javascript" src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.3.200/pdf.js"></script>
-<!-- das funktioniert!!!!!
+<!--<script type="javascript" src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.3.200/pdf.js"></script> das funktioniert!!!!!
 <script type="javascript" src="https://unpkg.com/pdfjs-dist@latest/build/pdf.js" ></script>
 <script type="javascript" src="{{ url_for('static', filename='js/pdf.js') }}"></script>
-
+<script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
 <script src="https://mozilla.github.io/pdf.js/build/pdf.js"></script>
 -->
 
-
+<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@1.9/build/pdf.min.js"></script>
+<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@1.9/web/pdf_viewer.js"></script>
+<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@1.9/build/pdf.js"></script>
 <script type="javascript" src="{{ url_for('static', filename='js/text_layer_builder.js') }}"></script>
 <script type="javascript" src="{{ url_for('static', filename='js/ui_utils.js') }}"></script>
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
+<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pdfjs-dist@1.9/web/pdf_viewer.css">
+<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"/>
+<link rel="stylesheet" href="{{ url_for('static', filename='css/text_layer_builder.css') }}" />
+
+
+
 <body>
-<div id="container"> {{og_filename}}</div>
+<div id="container" > {{og_filename}}</div>
+<div id="text-layer"></div>
 <script>
 
+
 var og_filename = "{{og_filename}}";
 var url = "{{ url_for('send_file', filename=og_filename) }}";
 console.log(og_filename);
@@ -66,14 +72,14 @@ pdfjsLib.getDocument(url)
           };
 
           // Render PDF page
-         page.render(renderContext)
-  .promise.then(function() {
+         page.render(renderContext).promise.then(function() {
     // Get text-fragments
     return page.getTextContent();
-    console.log(textContent);
   })
+
   .then(function(textContent) {
     // Create div which will hold text-fragments
+    console.log(textContent);
     var textLayerDiv = document.createElement("div");
 
     // Set it's class to textLayer which have required CSS styles
@@ -96,9 +102,13 @@ pdfjsLib.getDocument(url)
     textLayer.render();
   });
         });
-    }
+
+      }
+
 });
 
+
+
 </script>
 </body>
 </html>

+ 40 - 0
app/templates/test_pdfjs_textlayer.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<!--
+Copyright 2014 Mozilla Foundation
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+    http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<html dir="ltr" mozdisallowselectionprint>
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+  <meta name="google" content="notranslate">
+  <title>PDF.js page viewer using built components</title>
+
+  <style>
+    body {
+      background-color: #808080;
+      margin: 0;
+      padding: 0;
+    }
+  </style>
+
+  <link rel="stylesheet" href="{{ url_for('static', filename='css/viewer.css') }}" />
+
+<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@2.2.2/web/pdf_viewer.js"></script>
+<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@2.2.2/build/pdf.js"></script>
+</head>
+
+<body tabindex="1">
+  <div id="pageContainer" class="pdfViewer singlePageView"></div>
+
+  <script src="pageviewer.js"></script>
+</body>
+</html>

+ 1 - 1
app/templates/viewer.html

@@ -1 +1 @@
-<a href="/web/viewer.html?file={{ url_for('send_file', filename=og_filename) }}">Open yourpdf.pdf with PDF.js</a>
+<a href="/web/viewer.html?file=app">Open yourpdf.pdf with PDF.js</a>

+ 21 - 9
app/views.py

@@ -6,6 +6,7 @@ import redis
 import random
 import PyPDF2
 import json
+import base64
 import os
 import json
 import re
@@ -109,7 +110,7 @@ def upload_file():
 
 @app.route('/show/<filename>&<uuid>')
 def uploaded_file(filename, uuid):
-    """file_out = "out.jpg"
+    file_out = "out.jpg"
     #file_out = filename
     #if request.method == 'POST':
     #    uuid = 433
@@ -150,7 +151,8 @@ def uploaded_file(filename, uuid):
                 html_code += "<td><h4>" + dim + "</h4></td>"
             for d in dims[dim]:
                 relevant_isos = []
-                search_terms = []
+                search_terms = {}
+                terms = ''
                 #if "Ra" in d or "Rz" in d or "Rpk" in d:
                 #    relevant_isos.append("ISO4287.PDF")
                 #if u"\u27C2" in d or u"\u25CE" in d or u"\u232D" in d or u"\u2225" in d or u"\u232F" in d or u"\u2316" in d or u"\u2313" in d or u"\u23E5" in d:
@@ -166,9 +168,18 @@ def uploaded_file(filename, uuid):
                         iso = config_file[conf]
                         for key in iso:
                             relevant_isos.append(key)
-                            search_terms = iso[key]
+                            for blub in iso[key]:
+                                search_terms[blub] = iso[key][blub]
+
+                        #terms = '{"Symbole":1,"Tabelle":2,"Definition":3}'
+                        if len(search_terms) < 1:
+                            search_terms["Beginn"] = 1
+                        terms = json.dumps(search_terms)
+                        #print(terms)
+                        terms = base64.b64encode(terms.encode())
+                        #terms = "blub"
+
 
-                terms = ",".join(str(e) for e in search_terms)
 
                 try:
                     number = re.search(reg, d)
@@ -193,18 +204,19 @@ def uploaded_file(filename, uuid):
                              "<td style='text-align:center'>" + d + "</td>" + \
                              "<td max='3' style='text-align:center'> <input type='number' step='" + str(steps) + "' data-coords='" + coords + " 'data-details='" + det_coords  +"'' name='" + d + "' value='" + number + "'> </td>"
 
-
+                relevant_isos = list(set(relevant_isos))
                 for x in relevant_isos:
                     #html_code += "<td style='text-align:left'> <a href=" + url_for('static', filename="isos/"+x) + " >"+ x.partition(".")[0]  +"</a>  </td>"
-                    html_code += "<td style='text-align:left' data-terms='" + terms + "'> <a onclick=ui_add_tab_active('#main','" + x.partition(".")[0] + "','" + x.partition(".")[0] +"',true,'isotab')>" + x.partition(".")[0] + "</a>  </td>"
+                    html_code += "<td style='text-align:left' data-terms='" + terms + "'> <a onclick=ui_add_tab_active('#main','" + x.partition(".")[0] + "','" + x.partition(".")[0] +"',true,'isotab','"+terms+"')>" + x.partition(".")[0] + "</a>  </td>"
                 #print(html_code)
                 html_code += "</tr>"
                 html_links = ""
                 for link in links:
-                    html_links += "<a onclick =ui_add_tab_active('#main','" + link + "','" + link +"',true,'isotab')> Open " + link + "</a> <br>"
+                    html_links += "<a onclick =ui_add_tab_active('#main','" + link + "','" + link +"',true,'isotab','"+terms+"')> Open " + link + "</a> <br>"
                     #html_links += "<tr> <td> <a onclick =ui_add_tab_active('#main','iso1','iso1',true,'isotab')> Open " + link + " in Tab </a> </td> </tr>"""
-        #return render_template('show_pdf.html', filename=file_out, isos=isos, dims=dims, text=html_code,html_general=html_general, number=number_blocks, og_filename=filename, w=w, h=h, html_links=html_links, isos_names=isos_names)
-    return render_template('show_pdf.html', og_filename=filename)
+        #print("teeest")
+        return render_template('index.html', filename=file_out, isos=isos, dims=dims, text=html_code,html_general=html_general, number=number_blocks, og_filename=filename, w=w, h=h, html_links=html_links, isos_names=isos_names)
+    #return render_template('test_pdfjs_textlayer.html', og_filename=filename)
 
     #else:
     #    filename = filename