Add a createPostTable function and remove the useless join('') calls
This commit is contained in:
parent
7b454d403b
commit
59e178946a
64
fonts.js
64
fonts.js
@ -298,8 +298,7 @@ var Font = (function () {
|
||||
};
|
||||
|
||||
function createOS2Table() {
|
||||
var OS2 = stringToArray(
|
||||
"\x00\x03" + // version
|
||||
return "\x00\x03" + // version
|
||||
"\x02\x24" + // xAvgCharWidth
|
||||
"\x01\xF4" + // usWeightClass
|
||||
"\x00\x05" + // usWidthClass
|
||||
@ -335,19 +334,23 @@ var Font = (function () {
|
||||
"\x00\x00" + // sCapHeight
|
||||
"\x00\x01" + // usDefaultChar
|
||||
"\x00\xCD" + // usBreakChar
|
||||
"\x00\x02" // usMaxContext
|
||||
);
|
||||
return OS2;
|
||||
"\x00\x02"; // usMaxContext
|
||||
};
|
||||
|
||||
function createPostTable() {
|
||||
TODO("Fill with real values from the font dict");
|
||||
|
||||
return "\x00\x03\x00\x00" + // Version number
|
||||
"\x00\x00\x01\x00" + // italicAngle
|
||||
"\x00\x00" + // underlinePosition
|
||||
"\x00\x00" + // underlineThickness
|
||||
"\x00\x00\x00\x00" + // isFixedPitch
|
||||
"\x00\x00\x00\x00" + // minMemType42
|
||||
"\x00\x00\x00\x00" + // maxMemType42
|
||||
"\x00\x00\x00\x00" + // minMemType1
|
||||
"\x00\x00\x00\x00"; // maxMemType1
|
||||
};
|
||||
|
||||
/**
|
||||
* A bunch of the OpenType code is duplicate between this class and the
|
||||
* TrueType code, this is intentional and will merge in a future version
|
||||
* where all the code relative to OpenType will probably have its own
|
||||
* class and will take decision without the Fonts consent.
|
||||
* But at the moment it allows to develop around the TrueType rewriting
|
||||
* on the fly without messing up with the 'regular' Type1 to OTF conversion.
|
||||
*/
|
||||
constructor.prototype = {
|
||||
name: null,
|
||||
font: null,
|
||||
@ -512,10 +515,9 @@ var Font = (function () {
|
||||
createOpenTypeHeader("\x00\x01\x00\x00", ttf, offsets, numTables);
|
||||
|
||||
// Insert the missing table
|
||||
var OS2 = createOS2Table();
|
||||
tables.push({
|
||||
tag: "OS/2",
|
||||
data: OS2
|
||||
data: stringToArray(createOS2Table)
|
||||
});
|
||||
|
||||
// Replace the old CMAP table with a shiny new one
|
||||
@ -523,20 +525,9 @@ var Font = (function () {
|
||||
|
||||
// Rewrite the 'post' table if needed
|
||||
if (!post) {
|
||||
post =
|
||||
"\x00\x03\x00\x00" + // Version number
|
||||
"\x00\x00\x01\x00" + // italicAngle
|
||||
"\x00\x00" + // underlinePosition
|
||||
"\x00\x00" + // underlineThickness
|
||||
"\x00\x00\x00\x00" + // isFixedPitch
|
||||
"\x00\x00\x00\x00" + // minMemType42
|
||||
"\x00\x00\x00\x00" + // maxMemType42
|
||||
"\x00\x00\x00\x00" + // minMemType1
|
||||
"\x00\x00\x00\x00"; // maxMemType1
|
||||
|
||||
tables.unshift({
|
||||
tables.push({
|
||||
tag: "post",
|
||||
data: stringToArray(post)
|
||||
data: stringToArray(createPostTable())
|
||||
});
|
||||
}
|
||||
|
||||
@ -628,7 +619,7 @@ var Font = (function () {
|
||||
font.data, // PostScript Font Program
|
||||
OS2, // OS/2 and Windows Specific metrics
|
||||
cmap, // Character to glyphs mapping
|
||||
head, // Font eader
|
||||
head, // Font header
|
||||
hhea, // Horizontal header
|
||||
hmtx, // Horizontal metrics
|
||||
maxp, // Maximum profile
|
||||
@ -728,17 +719,7 @@ var Font = (function () {
|
||||
createTableEntry(otf, offsets, "name", name);
|
||||
|
||||
/** POST */
|
||||
// TODO: get those informations from the FontInfo structure
|
||||
post = "\x00\x03\x00\x00" + // Version number
|
||||
"\x00\x00\x01\x00" + // italicAngle
|
||||
"\x00\x00" + // underlinePosition
|
||||
"\x00\x00" + // underlineThickness
|
||||
"\x00\x00\x00\x00" + // isFixedPitch
|
||||
"\x00\x00\x00\x00" + // minMemType42
|
||||
"\x00\x00\x00\x00" + // maxMemType42
|
||||
"\x00\x00\x00\x00" + // minMemType1
|
||||
"\x00\x00\x00\x00"; // maxMemType1
|
||||
post = stringToArray(post);
|
||||
post = stringToArray(createPostTable());
|
||||
createTableEntry(otf, offsets, "post", post);
|
||||
|
||||
// Once all the table entries header are written, dump the data!
|
||||
@ -1480,7 +1461,6 @@ CFF.prototype = {
|
||||
}
|
||||
|
||||
var charstringsIndex = this.createCFFIndexHeader([[0x40, 0x0E]].concat(glyphs), true);
|
||||
charstringsIndex = charstringsIndex.join(" ").split(" "); // XXX why?
|
||||
|
||||
//Top Dict Index
|
||||
var topDictIndex = [
|
||||
@ -1514,7 +1494,6 @@ CFF.prototype = {
|
||||
var privateOffset = charstringsOffset + charstringsIndex.length;
|
||||
topDictIndex = topDictIndex.concat(this.encodeNumber(privateOffset));
|
||||
topDictIndex.push(18); // Private
|
||||
topDictIndex = topDictIndex.join(" ").split(" ");
|
||||
|
||||
var indexes = [
|
||||
topDictIndex, stringsIndex,
|
||||
@ -1544,7 +1523,6 @@ CFF.prototype = {
|
||||
139, 12, 14,
|
||||
28, 0, 55, 19
|
||||
]);
|
||||
privateData = privateData.join(" ").split(" ");
|
||||
cff.set(privateData, currentOffset);
|
||||
currentOffset += privateData.length;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user