diff --git a/fonts/firasans-medium/FiraSans-Medium.ttf b/fonts/firasans-medium/FiraSans-Medium.ttf deleted file mode 100644 index e6a6637b0..000000000 Binary files a/fonts/firasans-medium/FiraSans-Medium.ttf and /dev/null differ diff --git a/fonts/firasans-medium/LICENSE b/fonts/firasans-medium/LICENSE deleted file mode 100644 index e4d7557ab..000000000 --- a/fonts/firasans-medium/LICENSE +++ /dev/null @@ -1,99 +0,0 @@ -Copyright (c) 2014, Mozilla Foundation https://mozilla.org/ -with Reserved Font Name Fira Sans. - -Copyright (c) 2014, Mozilla Foundation https://mozilla.org/ -with Reserved Font Name Fira Mono. - -Copyright (c) 2014, Telefonica S.A. - -This Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: -http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/package.json b/package.json index 74d2c82c9..68e9647f0 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ ], "devDependencies": { "faucet": "0.0.1", + "mkdirp": "^0.5.1", "pbf": "^1.3.1", "tape": "^4.0.0" }, diff --git a/src/glyphs.cpp b/src/glyphs.cpp index 4a8577af5..4f679dd5c 100644 --- a/src/glyphs.cpp +++ b/src/glyphs.cpp @@ -34,8 +34,7 @@ typedef std::pair SegmentPair; typedef std::pair SegmentValue; typedef bgi::rtree> Tree; -namespace node_fontnik -{ +namespace node_fontnik { struct FaceMetadata { std::string family_name; @@ -74,6 +73,34 @@ struct LoadBaton { } }; +struct TableBaton { + v8::Persistent callback; + v8::Persistent buffer; + std::string table; + const char * font_data; + std::size_t font_size; + std::string error_name; + std::string message; + uv_work_t request; + TableBaton(v8::Local buf, + std::string _table, + v8::Local cb) : + table(_table), + font_data(node::Buffer::Data(buf)), + font_size(node::Buffer::Length(buf)), + error_name(), + message(), + request() { + request.data = this; + NanAssignPersistent(callback, cb.As()); + NanAssignPersistent(buffer, buf.As()); + } + ~TableBaton() { + NanDisposePersistent(callback); + NanDisposePersistent(buffer); + } +}; + struct RangeBaton { v8::Persistent callback; v8::Persistent buffer; @@ -128,6 +155,35 @@ NAN_METHOD(Load) { NanReturnUndefined(); } +NAN_METHOD(Table) { + NanScope(); + + // Validate arguments. + if (!args[0]->IsObject()) { + return NanThrowTypeError("First argument must be a font buffer"); + } + v8::Local obj = args[0]->ToObject(); + if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { + return NanThrowTypeError("First argument must be a font buffer"); + } + + if (!args[1]->IsString()) { + return NanThrowTypeError("Second argument must be a string table name"); + } + std::string table = *v8::String::Utf8Value(args[1]->ToString()); + if (table.empty()) { + return NanThrowTypeError("Second argument must be a string of non-zero size"); + } + + if (args.Length() < 3 || !args[2]->IsFunction()) { + return NanThrowTypeError("Callback must be a function"); + } + + TableBaton* baton = new TableBaton(obj,table,args[2]); + uv_queue_work(uv_default_loop(), &baton->request, TableAsync, (uv_after_work_cb)AfterTable); + NanReturnUndefined(); +} + NAN_METHOD(Range) { NanScope(); @@ -265,6 +321,77 @@ void AfterLoad(uv_work_t* req) { delete baton; }; +void TableAsync(uv_work_t* req) { + TableBaton* baton = static_cast(req->data); + + FT_Library library = nullptr; + ft_library_guard library_guard(&library); + FT_Error error = FT_Init_FreeType(&library); + if (error) { + /* LCOV_EXCL_START */ + baton->error_name = std::string("could not open FreeType library"); + return; + /* LCOV_EXCL_END */ + } + FT_Face ft_face = 0; + int num_faces = 0; + for ( int i = 0; ft_face == 0 || i < num_faces; ++i ) + { + FT_Error face_error = FT_New_Memory_Face(library, reinterpret_cast(baton->font_data), static_cast(baton->font_size), i, &ft_face); + if (face_error) { + baton->error_name = std::string("could not open font file"); + return; + } + + FT_ULong length = 0; + FT_Byte *buffer; + + FT_ULong tag = FT_MAKE_TAG(baton->table.at(0), + baton->table.at(1), + baton->table.at(2), + baton->table.at(3)); + + face_error = FT_Load_Sfnt_Table(ft_face, tag, 0, NULL, &length); + if (face_error) { + baton->error_name = std::string("error retrieving table"); + return; + } + + buffer = (FT_Byte *) malloc (length); + if (buffer == NULL) { + baton->error_name = std::string("error retrieving 0-length table"); + } + + face_error = FT_Load_Sfnt_Table(ft_face, tag, 0, buffer, &length); + if (face_error) { + baton->error_name = std::string("error retrieving table"); + return; + } + const char _message = reinterpret_cast(buffer); + + baton->message = _message; + + if (ft_face) { + FT_Done_Face(ft_face); + } + } +}; + +void AfterTable(uv_work_t* req) { + NanScope(); + TableBaton* baton = static_cast(req->data); + + if (!baton->error_name.empty()) { + v8::Local argv[1] = { NanError(baton->error_name.c_str()) }; + NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 1, argv); + } else { + v8::Local argv[2] = { NanNull(), NanNewBufferHandle(baton->message.data(), baton->message.size()) }; + NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 2, argv); + } + + delete baton; +}; + void RangeAsync(uv_work_t* req) { RangeBaton* baton = static_cast(req->data); @@ -349,8 +476,6 @@ void AfterRange(uv_work_t* req) { v8::Local argv[1] = { NanError(baton->error_name.c_str()) }; NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 1, argv); } else { - v8::Local js_faces = NanNew(); - unsigned idx = 0; v8::Local argv[2] = { NanNull(), NanNewBufferHandle(baton->message.data(), baton->message.size()) }; NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 2, argv); } diff --git a/src/glyphs.hpp b/src/glyphs.hpp index 22e02c57f..7fb419b34 100644 --- a/src/glyphs.hpp +++ b/src/glyphs.hpp @@ -13,10 +13,10 @@ extern "C" #include FT_FREETYPE_H #include FT_GLYPH_H #include FT_OUTLINE_H +#include FT_TRUETYPE_TABLES_H } -namespace node_fontnik -{ +namespace node_fontnik { NAN_METHOD(Load); void LoadAsync(uv_work_t* req); @@ -24,6 +24,9 @@ void AfterLoad(uv_work_t* req); NAN_METHOD(Range); void RangeAsync(uv_work_t* req); void AfterRange(uv_work_t* req); +NAN_METHOD(Table); +void TableAsync(uv_work_t* req); +void AfterTable(uv_work_t* req); struct glyph_info; void RenderSDF(glyph_info &glyph, int size, diff --git a/src/node_fontnik.cpp b/src/node_fontnik.cpp index 9f1627ab6..1d0f9f137 100644 --- a/src/node_fontnik.cpp +++ b/src/node_fontnik.cpp @@ -5,13 +5,12 @@ #include #include -namespace node_fontnik -{ +namespace node_fontnik { void RegisterModule(v8::Handle target) { NODE_SET_METHOD(target, "load", node_fontnik::Load); + NODE_SET_METHOD(target, "table", node_fontnik::Table); NODE_SET_METHOD(target, "range", node_fontnik::Range); - } NODE_MODULE(fontnik, RegisterModule); diff --git a/test/expected/Noto Kufi Arabic Regular/codepoints.json b/test/expected/Noto Kufi Arabic Regular/codepoints.json new file mode 100644 index 000000000..47eabc57b --- /dev/null +++ b/test/expected/Noto Kufi Arabic Regular/codepoints.json @@ -0,0 +1 @@ +[13,32,160,1536,1537,1538,1539,1547,1548,1549,1550,1551,1552,1553,1554,1555,1556,1557,1563,1566,1567,1569,1570,1571,1572,1573,1574,1575,1576,1577,1578,1579,1580,1581,1582,1583,1584,1585,1586,1587,1588,1589,1590,1591,1592,1593,1594,1600,1601,1602,1603,1604,1605,1606,1607,1608,1609,1610,1611,1612,1613,1614,1615,1616,1617,1618,1619,1620,1621,1622,1623,1624,1625,1626,1627,1628,1629,1630,1632,1633,1634,1635,1636,1637,1638,1639,1640,1641,1642,1643,1644,1645,1646,1647,1648,1649,1650,1651,1653,1654,1655,1656,1657,1658,1659,1660,1661,1662,1663,1664,1665,1666,1667,1668,1669,1670,1671,1672,1673,1674,1675,1676,1677,1678,1679,1680,1681,1682,1683,1684,1685,1686,1687,1688,1689,1690,1691,1692,1693,1694,1695,1696,1697,1698,1699,1700,1701,1702,1703,1704,1705,1706,1707,1708,1709,1710,1711,1712,1713,1714,1715,1716,1717,1718,1719,1720,1721,1722,1723,1724,1725,1726,1727,1728,1729,1730,1731,1732,1733,1734,1735,1736,1737,1738,1739,1740,1741,1742,1743,1744,1745,1746,1747,1748,1749,1750,1751,1752,1753,1754,1755,1756,1757,1758,1759,1760,1761,1762,1763,1764,1765,1766,1767,1768,1769,1770,1771,1773,1774,1775,1776,1777,1778,1779,1780,1781,1782,1783,1784,1785,1786,1787,1788,1789,1790,1791,1872,1873,1874,1875,1876,1877,1878,1879,1880,1881,1882,1883,1884,1885,1886,1887,1888,1889,1890,1891,1892,1893,1894,1895,1896,1897,1898,1899,1900,1901,8203,8204,8205,8206,8207,9676,64336,64337,64342,64343,64344,64345,64358,64359,64360,64361,64362,64363,64364,64365,64378,64379,64380,64381,64392,64393,64394,64395,64396,64397,64398,64399,64400,64401,64402,64403,64404,64405,64414,64415,64420,64421,64422,64423,64424,64425,64426,64427,64428,64429,64430,64431,64432,64433,64486,64487,64488,64489,64508,64509,64510,64511,64606,64607,64608,64609,64610,64611,64830,64831,65010,65020,65136,65138,65140,65142,65144,65146,65148,65150,65152,65153,65154,65155,65156,65157,65158,65159,65160,65161,65162,65163,65164,65165,65166,65167,65168,65169,65170,65171,65172,65173,65174,65175,65176,65177,65178,65179,65180,65181,65182,65183,65184,65185,65186,65187,65188,65189,65190,65191,65192,65193,65194,65195,65196,65197,65198,65199,65200,65201,65202,65203,65204,65205,65206,65207,65208,65209,65210,65211,65212,65213,65214,65215,65216,65217,65218,65219,65220,65221,65222,65223,65224,65225,65226,65227,65228,65229,65230,65231,65232,65233,65234,65235,65236,65237,65238,65239,65240,65241,65242,65243,65244,65245,65246,65247,65248,65249,65250,65251,65252,65253,65254,65255,65256,65257,65258,65259,65260,65261,65262,65263,65264,65265,65266,65267,65268,65269,65270,65271,65272,65273,65274,65275,65276,65279] \ No newline at end of file diff --git a/test/expected/Noto Kufi Arabic Regular/gpos.sfnt b/test/expected/Noto Kufi Arabic Regular/gpos.sfnt new file mode 100644 index 000000000..f76dd238a Binary files /dev/null and b/test/expected/Noto Kufi Arabic Regular/gpos.sfnt differ diff --git a/test/expected/Open Sans Regular/codepoints.json b/test/expected/Open Sans Regular/codepoints.json new file mode 100644 index 000000000..34000b6fb --- /dev/null +++ b/test/expected/Open Sans Regular/codepoints.json @@ -0,0 +1 @@ +[33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,402,416,417,431,432,496,506,507,508,509,510,511,536,537,538,539,567,700,710,711,713,728,729,730,731,732,733,755,768,769,771,777,783,803,900,901,902,903,904,905,906,908,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,977,978,982,1024,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,1104,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1117,1118,1119,1120,1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,1131,1132,1133,1134,1135,1136,1137,1138,1139,1140,1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,1151,1152,1153,1154,1155,1156,1157,1158,1160,1161,1162,1163,1164,1165,1166,1167,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1179,1180,1181,1182,1183,1184,1185,1186,1187,1188,1189,1190,1191,1192,1193,1194,1195,1196,1197,1198,1199,1200,1201,1202,1203,1204,1205,1206,1207,1208,1209,1210,1211,1212,1213,1214,1215,1216,1217,1218,1219,1220,1221,1222,1223,1224,1225,1226,1227,1228,1229,1230,1231,1232,1233,1234,1235,1236,1237,1238,1239,1240,1241,1242,1243,1244,1245,1246,1247,1248,1249,1250,1251,1252,1253,1254,1255,1256,1257,1258,1259,1260,1261,1262,1263,1264,1265,1266,1267,1268,1269,1270,1271,1272,1273,1274,1275,1276,1277,1278,1279,1280,1281,1282,1283,1284,1285,1286,1287,1288,1289,1290,1291,1292,1293,1294,1295,1296,1297,1298,1299,7680,7681,7742,7743,7808,7809,7810,7811,7812,7813,7840,7841,7842,7843,7844,7845,7846,7847,7848,7849,7850,7851,7852,7853,7854,7855,7856,7857,7858,7859,7860,7861,7862,7863,7864,7865,7866,7867,7868,7869,7870,7871,7872,7873,7874,7875,7876,7877,7878,7879,7880,7881,7882,7883,7884,7885,7886,7887,7888,7889,7890,7891,7892,7893,7894,7895,7896,7897,7898,7899,7900,7901,7902,7903,7904,7905,7906,7907,7908,7909,7910,7911,7912,7913,7914,7915,7916,7917,7918,7919,7920,7921,7922,7923,7924,7925,7926,7927,7928,7929,8013,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8203,8211,8212,8213,8215,8216,8217,8218,8219,8220,8221,8222,8224,8225,8226,8230,8240,8242,8243,8249,8250,8252,8260,8304,8308,8309,8310,8311,8312,8313,8319,8355,8356,8359,8363,8364,8453,8467,8470,8480,8482,8486,8494,8539,8540,8541,8542,8706,8710,8719,8721,8722,8730,8734,8747,8776,8800,8804,8805,9674,64256,64257,64258,64259,64260,65279,65532,65533] \ No newline at end of file diff --git a/test/expected/Open Sans Regular/gpos.sfnt b/test/expected/Open Sans Regular/gpos.sfnt new file mode 100644 index 000000000..04f7b5be6 --- /dev/null +++ b/test/expected/Open Sans Regular/gpos.sfnt @@ -0,0 +1 @@ +ð \ No newline at end of file diff --git a/test/expected/range.json b/test/expected/Open Sans Regular/range.json similarity index 100% rename from test/expected/range.json rename to test/expected/Open Sans Regular/range.json diff --git a/test/expected/load.json b/test/expected/load.json deleted file mode 100644 index 75bdfa03f..000000000 --- a/test/expected/load.json +++ /dev/null @@ -1 +0,0 @@ -[{"family_name":"Fira Sans","style_name":"Medium","points":[32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,402,508,509,510,511,536,537,538,539,567,700,710,711,728,729,730,731,732,733,768,769,770,771,772,774,775,776,778,779,780,787,788,806,807,900,901,902,904,905,906,908,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,1024,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,1104,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1117,1118,1119,1122,1123,1138,1139,1140,1141,1168,1169,1170,1171,1174,1175,1176,1177,1178,1179,1180,1181,1184,1185,1186,1187,1194,1195,1196,1197,1198,1199,1200,1201,1202,1203,1206,1207,1208,1209,1210,1211,1216,1217,1218,1227,1228,1231,1232,1233,1234,1235,1236,1237,1238,1239,1240,1241,1242,1243,1244,1245,1246,1247,1250,1251,1252,1253,1254,1255,1256,1257,1258,1259,1260,1261,1262,1263,1264,1265,1266,1267,1268,1269,1270,1271,1272,1273,1308,1309,1316,1317,1318,1319,7808,7809,7810,7811,7812,7813,7922,7923,8048,8049,8050,8051,8052,8053,8054,8055,8056,8057,8058,8059,8060,8061,8112,8113,8118,8120,8121,8122,8123,8128,8134,8136,8137,8138,8139,8144,8145,8146,8147,8150,8151,8152,8153,8154,8155,8160,8161,8162,8163,8166,8167,8168,8169,8170,8171,8182,8184,8185,8186,8187,8199,8200,8203,8204,8205,8206,8207,8210,8211,8212,8213,8216,8217,8218,8220,8221,8222,8224,8225,8226,8230,8240,8249,8250,8260,8304,8308,8309,8310,8311,8312,8313,8314,8315,8316,8317,8318,8320,8321,8322,8323,8324,8325,8326,8327,8328,8329,8330,8331,8332,8333,8334,8364,8470,8482,8486,8494,8531,8532,8533,8534,8535,8536,8537,8538,8539,8540,8541,8542,8543,8592,8593,8594,8595,8596,8597,8598,8599,8600,8601,8678,8679,8680,8681,8682,8706,8709,8710,8719,8721,8722,8725,8729,8730,8734,8747,8776,8800,8804,8805,8901,8998,8999,9000,9003,9166,9647,9674,10145,11013,11014,11015,57344,57345,57346,57347,64257,64258,65279,127760]}] diff --git a/test/fixtures/fonts/noto-kufi-arabic/LICENSE.txt b/test/fixtures/fonts/noto-kufi-arabic/LICENSE.txt new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/test/fixtures/fonts/noto-kufi-arabic/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/test/fixtures/fonts/noto-kufi-arabic/NotoKufiArabic-Regular.ttf b/test/fixtures/fonts/noto-kufi-arabic/NotoKufiArabic-Regular.ttf new file mode 100644 index 000000000..85b4ffd88 Binary files /dev/null and b/test/fixtures/fonts/noto-kufi-arabic/NotoKufiArabic-Regular.ttf differ diff --git a/fonts/open-sans/Apache License.txt b/test/fixtures/fonts/open-sans/Apache License.txt similarity index 100% rename from fonts/open-sans/Apache License.txt rename to test/fixtures/fonts/open-sans/Apache License.txt diff --git a/fonts/open-sans/OpenSans-Regular.ttf b/test/fixtures/fonts/open-sans/OpenSans-Regular.ttf similarity index 100% rename from fonts/open-sans/OpenSans-Regular.ttf rename to test/fixtures/fonts/open-sans/OpenSans-Regular.ttf diff --git a/test/load.test.js b/test/load.test.js new file mode 100644 index 000000000..f4ca0f2a5 --- /dev/null +++ b/test/load.test.js @@ -0,0 +1,85 @@ +'use strict'; + +/* jshint node: true */ + +var fontnik = require('..'); +var test = require('tape'); +var fs = require('fs'); +var mkdirp = require('mkdirp'); +var UPDATE = process.env.UPDATE; + +var opensans = fs.readFileSync(__dirname + '/fixtures/fonts/open-sans/OpenSans-Regular.ttf'); +var notokufiarabic = fs.readFileSync(__dirname + '/fixtures/fonts/noto-kufi-arabic/NotoKufiArabic-Regular.ttf'); + +test('load', function(t) { + t.test('loads: Open Sans Regular', function(t) { + fontnik.load(opensans, function(err, faces) { + t.error(err); + + var family = faces[0].family_name; + var style = faces[0].style_name; + var face = [family, style].join(' '); + var dir = __dirname + '/expected/' + face; + var codepoints = dir + '/codepoints.json'; + + t.equal(family, 'Open Sans'); + t.equal(style, 'Regular'); + + if (UPDATE) { + mkdirp(dir); + fs.writeFileSync(codepoints, JSON.stringify(faces[0].points)); + } + + t.deepEqual(faces[0].points, require(codepoints)); + + t.end(); + }); + }); + + t.test('loads: Noto Kufi Arabic Regular', function(t) { + fontnik.load(notokufiarabic, function(err, faces) { + t.error(err); + + var family = faces[0].family_name; + var style = faces[0].style_name; + var face = [family, style].join(' '); + var dir = __dirname + '/expected/' + face; + var codepoints = dir + '/codepoints.json'; + + t.equal(family, 'Noto Kufi Arabic'); + t.equal(style, 'Regular'); + + if (UPDATE) { + mkdirp(dir); + fs.writeFileSync(codepoints, JSON.stringify(faces[0].points)); + } + + t.deepEqual(faces[0].points, JSON.parse(fs.readFileSync(codepoints))) + + t.end(); + }); + }); + + t.test('invalid font loading', function(t) { + t.throws(function() { + fontnik.load(undefined, function(err, faces) {}); + }, /First argument must be a font buffer/); + t.end(); + }); + + t.test('non existent font loading', function(t) { + var doesnotexistsans = new Buffer('baloney'); + fontnik.load(doesnotexistsans, function(err, faces) { + t.ok(err.message.indexOf('Font buffer is not an object')); + t.end(); + }); + }); + + t.test('load typeerror callback', function(t) { + t.throws(function() { + fontnik.load(opensans); + }, /Callback must be a function/); + t.end(); + }); +}); + diff --git a/test/fontnik.test.js b/test/range.test.js similarity index 61% rename from test/fontnik.test.js rename to test/range.test.js index 9dbe77558..14f94c8c6 100644 --- a/test/fontnik.test.js +++ b/test/range.test.js @@ -5,70 +5,13 @@ var fontnik = require('..'); var test = require('tape'); var fs = require('fs'); -var path = require('path'); var zlib = require('zlib'); var zdata = fs.readFileSync(__dirname + '/fixtures/range.0.256.pbf'); var Protobuf = require('pbf'); var Glyphs = require('./format/glyphs'); var UPDATE = process.env.UPDATE; -function nobuffer(key, val) { - return key !== '_buffer' && key !== 'bitmap' ? val : undefined; -} - -function jsonEqual(t, key, json) { - if (UPDATE) fs.writeFileSync(__dirname + '/expected/' + key + '.json', JSON.stringify(json, null, 2)); - t.deepEqual(json, require('./expected/' + key + '.json')); -} - -var expected = JSON.parse(fs.readFileSync(__dirname + '/expected/load.json').toString()); -var firasans = fs.readFileSync(path.resolve(__dirname + '/../fonts/firasans-medium/FiraSans-Medium.ttf')); -var opensans = fs.readFileSync(path.resolve(__dirname + '/../fonts/open-sans/OpenSans-Regular.ttf')); - -test('load', function(t) { - t.test('loads: fira sans', function(t) { - fontnik.load(firasans, function(err, faces) { - t.error(err); - t.equal(faces[0].points.length, 789); - t.equal(faces[0].family_name, 'Fira Sans'); - t.equal(faces[0].style_name, 'Medium'); - t.end(); - }); - }); - - t.test('loads: open sans', function(t) { - fontnik.load(opensans, function(err, faces) { - t.error(err); - t.equal(faces[0].points.length, 882); - t.equal(faces[0].family_name, 'Open Sans'); - t.equal(faces[0].style_name, 'Regular'); - t.end(); - }); - }); - - t.test('invalid font loading', function(t) { - t.throws(function() { - fontnik.load(undefined, function(err, faces) {}); - }, /First argument must be a font buffer/); - t.end(); - }); - - t.test('non existent font loading', function(t) { - var doesnotexistsans = new Buffer('baloney'); - fontnik.load(doesnotexistsans, function(err, faces) { - t.ok(err.message.indexOf('Font buffer is not an object')); - t.end(); - }); - }); - - t.test('load typeerror callback', function(t) { - t.throws(function() { - fontnik.load(firasans); - }, /Callback must be a function/); - t.end(); - }); - -}); +var opensans = fs.readFileSync(__dirname + '/fixtures/fonts/open-sans/OpenSans-Regular.ttf'); test('range', function(t) { var data; @@ -82,9 +25,17 @@ test('range', function(t) { t.error(err); t.ok(res); t.deepEqual(res, data); + var vt = new Glyphs(new Protobuf(new Uint8Array(res))); - var json = JSON.parse(JSON.stringify(vt, nobuffer)); - jsonEqual(t, 'range', json); + var json = JSON.parse(JSON.stringify(vt, function(key, val) { + return key !== '_buffer' && key !== 'bitmap' ? val : undefined; + })); + + var range = __dirname + '/expected/Open Sans Regular/range.json'; + + if (UPDATE) fs.writeFileSync(range, JSON.stringify(json, null, 2)); + t.deepEqual(json, require(range)); + t.end(); }); }); diff --git a/test/table.test.js b/test/table.test.js new file mode 100644 index 000000000..398c54198 --- /dev/null +++ b/test/table.test.js @@ -0,0 +1,63 @@ +'use strict'; + +/* jshint node: true */ + +var fontnik = require('..'); +var test = require('tape'); +var fs = require('fs'); +var mkdirp = require('mkdirp'); +var UPDATE = process.env.UPDATE; + +var notokufiarabic = fs.readFileSync(__dirname + '/fixtures/fonts/noto-kufi-arabic/NotoKufiArabic-Regular.ttf'); + +test('table', function(t) { + t.test('tables', function(t) { + fontnik.table(notokufiarabic, 'GPOS', function(err, res) { + t.error(err); + + var dir = __dirname + '/expected/Noto Kufi Arabic Regular'; + + if (UPDATE) { + mkdirp(dir); + fs.writeFileSync(dir + '/gpos.sfnt', res); + } + + t.ok(res); + t.end(); + }); + }); + + t.test('TypeError font buffer', function(t) { + t.throws(function() { + fontnik.table(); + }, /First argument must be a font buffer/); + t.throws(function() { + fontnik.table({}); + }, /First argument must be a font buffer/); + t.end(); + }); + + t.test('TypeError string table name', function(t) { + t.throws(function() { + fontnik.table(notokufiarabic, undefined, function() {}); + }, /Second argument must be a string table name/); + t.end(); + }); + + t.test('TypeError string of non-zero size', function(t) { + t.throws(function() { + fontnik.table(notokufiarabic, '', function() {}); + }, /Second argument must be a string of non-zero size/); + t.end(); + }); + + t.test('TypeError callback', function(t) { + t.throws(function() { + fontnik.table(notokufiarabic, 'GPOS'); + }, /Callback must be a function/); + t.throws(function() { + fontnik.table(notokufiarabic, 'GPOS', undefined); + }, /Callback must be a function/); + t.end(); + }); +});