Skip to content

Instantly share code, notes, and snippets.

@brendandahl
Created October 15, 2012 16:22
Show Gist options
  • Save brendandahl/3893385 to your computer and use it in GitHub Desktop.
Save brendandahl/3893385 to your computer and use it in GitHub Desktop.
sbw support
diff --git a/src/core.js b/src/core.js
index 8e07078..3fa7d6f 100644
--- a/src/core.js
+++ b/src/core.js
@@ -110,7 +110,9 @@ var Page = (function PageClosure() {
return shadow(this, 'mediaBox', obj);
},
get view() {
+ var userUnit = this.inheritPageProp('UserUnit');
var mediaBox = this.mediaBox;
+ debugger;
var cropBox = this.inheritPageProp('CropBox');
if (!isArray(cropBox) || cropBox.length !== 4)
return shadow(this, 'view', mediaBox);
diff --git a/src/fonts.js b/src/fonts.js
index fd5c72d..7a790c3 100644
--- a/src/fonts.js
+++ b/src/fonts.js
@@ -2998,7 +2998,42 @@ var Font = (function FontClosure() {
'name': stringToArray(createNameTable(fontName)),
// PostScript informations
- 'post': stringToArray(createPostTable(properties))
+ 'post': stringToArray(createPostTable(properties))//,
+
+ // Vertical header
+ // 'vhea': (function fontFieldsVhea() {
+ // return stringToArray(
+ // '\x00\x01\x10\x00' + // Version number
+ // '\x00\x00' + //safeString16(1024) + // safeString16(properties.ascent) + // vertTypoAscender
+ // '\x00\x00' + //safeString16(-1024) + //safeString16(properties.descent) + // vertTypoDescender
+ // '\x00\x00' + // vertTypoLineGap
+ // '\xFF\xFF' + // advanceHeightMax
+ // '\x00\x00' + // minTopSideBearing
+ // '\x00\x00' + // minBottomSideBearing
+ // '\x00\x00' + // yMaxExtent
+ // '\x00\x00' + //safeString16(0) + //safeString16(properties.capHeight) + // caretSlopeRise
+ // '\x00\x00' + //safeString16(1) + //safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + // caretSlopeRun
+ // '\x00\x00' + // caretOffset
+ // '\x00\x00' + // -reserved-
+ // '\x00\x00' + // -reserved-
+ // '\x00\x00' + // -reserved-
+ // '\x00\x00' + // -reserved-
+ // '\x00\x00' + // metricDataFormat
+ // string16(charstrings.length + 1)); // numOfLongVerMetrics
+ // })(),
+
+ // // Vertical metrics
+ // 'vmtx': (function fontFieldsVmtx() {
+ // var vmtx = '\x00\x00\x00\x00'; // Fake .notdef
+ // for (var i = 0, ii = charstrings.length; i < ii; i++) {
+ // var charstring = charstrings[i];
+ // var height = 'height' in charstring ? charstring.height : 0;
+ // console.log(height);
+ // vmtx += string16(height) + string16(0);
+ // }
+ // return stringToArray(vmtx);
+ // })()
+
};
for (var field in fields)
@@ -3008,7 +3043,7 @@ var Font = (function FontClosure() {
var table = fields[field];
otf.file += arrayToString(table);
}
-
+debugger;
return stringToArray(otf.file);
},
@@ -3423,8 +3458,10 @@ var Type1Parser = function type1Parser() {
function decodeCharString(array) {
var charstring = [];
var lsb = 0;
+ var sbx = 0, sby = 0;
var width = 0;
var flexState = 0;
+ var height = 0;
var value = '';
var count = array.length;
@@ -3462,6 +3499,21 @@ var Type1Parser = function type1Parser() {
// pop or setcurrentpoint commands can be ignored
// since we are not doing callothersubr
continue;
+ } else if (escape == 7) { // sbw
+ debugger;
+ if (charstring.length != 4) {
+ error('Unsupported sbw format: ' + charstring);
+ }
+
+ lsb = charstring[0]; // sbx
+ sby = charstring[1];
+ console.log("[" + lsb + "], [" + sby + "]");
+ width = charstring[2]; // wx
+ height = charstring[3]; // wy
+ charstring.splice(0, 2);
+
+ charstring.push('rmoveto');
+ continue;
} else if (!kHintingEnabled && (escape == 1 || escape == 2)) {
charstring.push('drop', 'drop', 'drop', 'drop', 'drop', 'drop');
continue;
@@ -3557,7 +3609,7 @@ var Type1Parser = function type1Parser() {
charstring.push(value);
}
- return { charstring: charstring, width: width, lsb: lsb };
+ return { charstring: charstring, width: width, lsb: lsb, height: height };
}
/*
@@ -3652,7 +3704,8 @@ var Type1Parser = function type1Parser() {
glyph: glyph,
data: str.charstring,
lsb: str.lsb,
- width: str.width
+ width: str.width,
+ height: str.height
});
} else {
program.subrs.push(str.charstring);
@@ -3967,7 +4020,12 @@ Type1Font.prototype = {
unicode: unicode,
gid: i,
charstring: item.data,
- width: item.width,
+ get width() {
+// debugger;
+ return item.width;
+
+ },
+ height: item.height,
lsb: item.lsb
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment