1
1
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
2
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
3
+ /*
4
+ * Copyright 2013 Mozilla Foundation
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
3
18
4
- var base64alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ;
19
+ 'use strict' ;
20
+
21
+ var base64alphabet =
22
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' ;
5
23
6
24
function decodeFontData (base64 ) {
7
25
var result = [];
8
26
9
27
var bits = 0 , bitsLength = 0 ;
10
28
for (var i = 0 , ii = base64 .length ; i < ii ; i ++) {
11
29
var ch = base64 [i ];
12
- if (ch <= " " ) continue ;
30
+ if (ch <= ' ' ) {
31
+ continue ;
32
+ }
13
33
var index = base64alphabet .indexOf (ch );
14
- if (index < 0 ) throw "Invalid character" ;
15
- if (index >= 64 ) break ;
34
+ if (index < 0 ) {
35
+ throw new Error ('Invalid character' );
36
+ }
37
+ if (index >= 64 ) {
38
+ break ;
39
+ }
16
40
bits = (bits << 6 ) | index ;
17
41
bitsLength += 6 ;
18
42
if (bitsLength >= 8 ) {
19
- bitsLength -= 8
43
+ bitsLength -= 8 ;
20
44
var code = (bits >> bitsLength ) & 0xFF ;
21
45
result .push (code );
22
46
}
@@ -45,8 +69,8 @@ function ttx(data, callback) {
45
69
xhr .open ('POST' , '/ttx' );
46
70
47
71
var encodedData = encodeFontData (data );
48
- xhr .setRequestHeader (" Content-type" , " text/plain" );
49
- xhr .setRequestHeader (" Content-length" , encodedData .length );
72
+ xhr .setRequestHeader (' Content-type' , ' text/plain' );
73
+ xhr .setRequestHeader (' Content-length' , encodedData .length );
50
74
51
75
xhr .onreadystatechange = function getPdfOnreadystatechange (e ) {
52
76
if (xhr .readyState === 4 ) {
@@ -62,6 +86,7 @@ function ttx(data, callback) {
62
86
63
87
function verifyTtxOutput (output ) {
64
88
var m = /^<error >(.*?)<\/error >/.exec (output );
65
- if (m )
89
+ if (m ) {
66
90
throw m [1 ];
91
+ }
67
92
}
0 commit comments