]> git.parisson.com Git - pdf.js.git/commitdiff
Properly support custom CSS properties
authorAdil Allawi <adil@diwan.com>
Mon, 13 Feb 2012 14:27:59 +0000 (14:27 +0000)
committerAdil Allawi <adil@diwan.com>
Mon, 13 Feb 2012 14:56:37 +0000 (14:56 +0000)
Fix comment in bidi

src/bidi.js
src/util.js
web/viewer.js

index 63ca2dde2e19e32041c682dc50cef501b9792686..09f8dd7c6054635c89aae6040c058708105d6815 100644 (file)
@@ -359,7 +359,7 @@ function bidi(text, startLevel) {
    directionality of that character is R.\r
    */\r
 \r
-  //dont mirror as this is already in the pdf\r
+  //dont mirror as characters are already mirrored in the pdf\r
 \r
   // Finally, return string\r
 \r
index f00fcd1ce117a67f5c7ca8a9ece510cd33898f89..3af6125e349e66a368de58b0cf19b95a5685c874 100644 (file)
@@ -118,6 +118,57 @@ var Util = (function UtilClosure() {
   return Util;
 })();
 
+// optimised CSS custom property getter/setter
+var CustomStyle = (function CustomStyleClosure() {
+
+  // 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 = { };
+
+  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 PDFStringTranslateTable = [
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
index bbb192a9aaf24bbfe6f98b1c35430f80f81c4a80..ff857a9436105a8ff8d67eccb8a58caaf3b3a681 100644 (file)
@@ -1044,8 +1044,10 @@ var TextLayerBuilder = function textLayerBuilder(textLayerDiv) {
           // Adjust div width to match canvas text
           // Due to the .offsetWidth calls, this is slow
           // This needs to come after appending to the DOM
-          textDiv.style.MozTransform = 'scale(' + textDiv.dataset.canvasWidth/textDiv.offsetWidth + ',1)';
-          textDiv.style.MozTransformOrigin = '0% 0%';
+          CustomStyle.setProp('transform' , textDiv, 'scale('
+            + textDiv.dataset.canvasWidth/textDiv.offsetWidth
+            + ',1)');
+          CustomStyle.setProp('transformOrigin' , textDiv, '0% 0%');
         }
       } // textLength > 0
     }