const char *aglfn13(unsigned short uni);
+
#ifdef WITH_AGLFN
-static const char *agl_l207e[]={
- "space","exclam","quotedbl","numbersign", "dollar","percent","ampersand","quotesingle",
- "parenleft","parenright","asterisk","plus", "comma","hyphen","period","slash",
- "zero","one","two","three", "four","five","six","seven", "eight","nine","colon","semicolon", "less","equal","greater","question",
- "at","A","B","C", "D","E","F","G", "H","I","J","K", "L","M","N","O",
- "P","Q","R","S", "T","U","V","W", "X","Y","Z","bracketleft", "backslash","bracketright","asciicircum","underscore",
- "grave","a","b","c", "d","e","f","g", "h","i","j","k", "l","m","n","o",
- "p","q","r","s", "t","u","v","w", "x","y","z","braceleft", "bar","braceright","asciitilde"};
+static const char *agl_l207e[] =
+{
+ "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle",
+ "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
+ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question",
+ "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
+ "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
+ "grave", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
+ "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde"};
-static const char *agl_la1ff[]={
- "exclamdown","cent","sterling","currency", "yen","brokenbar","section","dieresis",
- "copyright","ordfeminine","guillemotleft","logicalnot", "registered","macron","degree","plusminus",
- 0,0,"acute",0, "paragraph","periodcentered","cedilla",0,
- "ordmasculine","guillemotright","onequarter","onehalf", "threequarters","questiondown","Agrave","Aacute",
- "Acircumflex","Atilde","Adieresis","Aring", "AE","Ccedilla","Egrave","Eacute",
- "Ecircumflex","Edieresis","Igrave","Iacute", "Icircumflex","Idieresis","Eth","Ntilde",
- "Ograve","Oacute","Ocircumflex","Otilde", "Odieresis","multiply","Oslash","Ugrave",
- "Uacute","Ucircumflex","Udieresis","Yacute", "Thorn","germandbls","agrave","aacute",
- "acircumflex","atilde","adieresis","aring", "ae","ccedilla","egrave","eacute",
- "ecircumflex","edieresis","igrave","iacute", "icircumflex","idieresis","eth","ntilde",
- "ograve","oacute","ocircumflex","otilde", "odieresis","divide","oslash","ugrave",
- "uacute","ucircumflex","udieresis","yacute", "thorn","ydieresis"};
+static const char *agl_la1ff[] =
+{
+ "exclamdown", "cent", "sterling", "currency", "yen", "brokenbar", "section", "dieresis",
+ "copyright", "ordfeminine", "guillemotleft", "logicalnot", "registered", "macron", "degree", "plusminus",
+ 0, 0, "acute", 0, "paragraph", "periodcentered", "cedilla", 0,
+ "ordmasculine", "guillemotright", "onequarter", "onehalf", "threequarters", "questiondown", "Agrave", "Aacute",
+ "Acircumflex", "Atilde", "Adieresis", "Aring", "AE", "Ccedilla", "Egrave", "Eacute",
+ "Ecircumflex", "Edieresis", "Igrave", "Iacute", "Icircumflex", "Idieresis", "Eth", "Ntilde",
+ "Ograve", "Oacute", "Ocircumflex", "Otilde", "Odieresis", "multiply", "Oslash", "Ugrave",
+ "Uacute", "Ucircumflex", "Udieresis", "Yacute", "Thorn", "germandbls", "agrave", "aacute",
+ "acircumflex", "atilde", "adieresis", "aring", "ae", "ccedilla", "egrave", "eacute",
+ "ecircumflex", "edieresis", "igrave", "iacute", "icircumflex", "idieresis", "eth", "ntilde",
+ "ograve", "oacute", "ocircumflex", "otilde", "odieresis", "divide", "oslash", "ugrave",
+ "uacute", "ucircumflex", "udieresis", "yacute", "thorn", "ydieresis"};
-static const char *agl_l1007f[]={
- "Amacron","amacron","Abreve","abreve", "Aogonek","aogonek","Cacute","cacute",
- "Ccircumflex","ccircumflex","Cdotaccent","cdotaccent", "Ccaron","ccaron","Dcaron","dcaron",
- "Dcroat","dcroat","Emacron","emacron", "Ebreve","ebreve","Edotaccent","edotaccent",
- "Eogonek","eogonek","Ecaron","ecaron", "Gcircumflex","gcircumflex","Gbreve","gbreve",
- "Gdotaccent","gdotaccent","Gcommaaccent","gcommaaccent", "Hcircumflex","hcircumflex","Hbar","hbar",
- "Itilde","itilde","Imacron","imacron", "Ibreve","ibreve","Iogonek","iogonek",
- "Idotaccent","dotlessi","IJ","ij", "Jcircumflex","jcircumflex","Kcommaaccent","kcommaaccent",
- "kgreenlandic","Lacute","lacute","Lcommaaccent", "lcommaaccent","Lcaron","lcaron","Ldot",
- "ldot","Lslash","lslash","Nacute", "nacute","Ncommaaccent","ncommaaccent","Ncaron",
- "ncaron","napostrophe","Eng","eng", "Omacron","omacron","Obreve","obreve",
- "Ohungarumlaut","ohungarumlaut","OE","oe", "Racute","racute","Rcommaaccent","rcommaaccent",
- "Rcaron","rcaron","Sacute","sacute", "Scircumflex","scircumflex","Scedilla","scedilla",
- "Scaron","scaron","Tcommaaccent","tcommaaccent", "Tcaron","tcaron","Tbar","tbar",
- "Utilde","utilde","Umacron","umacron", "Ubreve","ubreve","Uring","uring",
- "Uhungarumlaut","uhungarumlaut","Uogonek","uogonek", "Wcircumflex","wcircumflex","Ycircumflex","ycircumflex",
- "Ydieresis","Zacute","zacute","Zdotaccent", "zdotaccent","Zcaron","zcaron","longs"};
+static const char *agl_l1007f[] =
+{
+ "Amacron", "amacron", "Abreve", "abreve", "Aogonek", "aogonek", "Cacute", "cacute",
+ "Ccircumflex", "ccircumflex", "Cdotaccent", "cdotaccent", "Ccaron", "ccaron", "Dcaron", "dcaron",
+ "Dcroat", "dcroat", "Emacron", "emacron", "Ebreve", "ebreve", "Edotaccent", "edotaccent",
+ "Eogonek", "eogonek", "Ecaron", "ecaron", "Gcircumflex", "gcircumflex", "Gbreve", "gbreve",
+ "Gdotaccent", "gdotaccent", "Gcommaaccent", "gcommaaccent", "Hcircumflex", "hcircumflex", "Hbar", "hbar",
+ "Itilde", "itilde", "Imacron", "imacron", "Ibreve", "ibreve", "Iogonek", "iogonek",
+ "Idotaccent", "dotlessi", "IJ", "ij", "Jcircumflex", "jcircumflex", "Kcommaaccent", "kcommaaccent",
+ "kgreenlandic", "Lacute", "lacute", "Lcommaaccent", "lcommaaccent", "Lcaron", "lcaron", "Ldot",
+ "ldot", "Lslash", "lslash", "Nacute", "nacute", "Ncommaaccent", "ncommaaccent", "Ncaron",
+ "ncaron", "napostrophe", "Eng", "eng", "Omacron", "omacron", "Obreve", "obreve",
+ "Ohungarumlaut", "ohungarumlaut", "OE", "oe", "Racute", "racute", "Rcommaaccent", "rcommaaccent",
+ "Rcaron", "rcaron", "Sacute", "sacute", "Scircumflex", "scircumflex", "Scedilla", "scedilla",
+ "Scaron", "scaron", "Tcommaaccent", "tcommaaccent", "Tcaron", "tcaron", "Tbar", "tbar",
+ "Utilde", "utilde", "Umacron", "umacron", "Ubreve", "ubreve", "Uring", "uring",
+ "Uhungarumlaut", "uhungarumlaut", "Uogonek", "uogonek", "Wcircumflex", "wcircumflex", "Ycircumflex", "ycircumflex",
+ "Ydieresis", "Zacute", "zacute", "Zdotaccent", "zdotaccent", "Zcaron", "zcaron", "longs"};
-struct agl_lt { unsigned short uid; const char *name; } agl_lxx[]={
- {0x0192,"florin"},{0x01A0,"Ohorn"},{0x01A1,"ohorn"},{0x01AF,"Uhorn"},
- {0x01B0,"uhorn"},{0x01E6,"Gcaron"},{0x01E7,"gcaron"},{0x01FA,"Aringacute"},
- {0x01FB,"aringacute"},{0x01FC,"AEacute"},{0x01FD,"aeacute"},{0x01FE,"Oslashacute"},
- {0x01FF,"oslashacute"},{0x0218,"Scommaaccent"},{0x0219,"scommaaccent"},{0x02BC,"afii57929"},
- {0x02BD,"afii64937"},{0x02C6,"circumflex"},{0x02C7,"caron"},{0x02D8,"breve"},
- {0x02D9,"dotaccent"},{0x02DA,"ring"},{0x02DB,"ogonek"},{0x02DC,"tilde"},
- {0x02DD,"hungarumlaut"},{0x0300,"gravecomb"},{0x0301,"acutecomb"},{0x0303,"tildecomb"},
- {0x0309,"hookabovecomb"},{0x0323,"dotbelowcomb"},{0x0384,"tonos"},{0x0385,"dieresistonos"},
- {0x0386,"Alphatonos"},{0x0387,"anoteleia"},{0x0388,"Epsilontonos"},{0x0389,"Etatonos"},
- {0x038A,"Iotatonos"},{0x038C,"Omicrontonos"},{0x038E,"Upsilontonos"},{0x038F,"Omegatonos"},
- {0x0390,"iotadieresistonos"},{0x0391,"Alpha"},{0x0392,"Beta"},{0x0393,"Gamma"},
- {0x0394,"Delta"},{0x0395,"Epsilon"},{0x0396,"Zeta"},{0x0397,"Eta"},
- {0x0398,"Theta"},{0x0399,"Iota"},{0x039A,"Kappa"},{0x039B,"Lambda"},
- {0x039C,"Mu"},{0x039D,"Nu"},{0x039E,"Xi"},{0x039F,"Omicron"},
- {0x03A0,"Pi"},{0x03A1,"Rho"},{0x03A3,"Sigma"},{0x03A4,"Tau"},
- {0x03A5,"Upsilon"},{0x03A6,"Phi"},{0x03A7,"Chi"},{0x03A8,"Psi"},
- {0x03A9,"Omega"},{0x03AA,"Iotadieresis"},{0x03AB,"Upsilondieresis"},{0x03AC,"alphatonos"},
- {0x03AD,"epsilontonos"},{0x03AE,"etatonos"},{0x03AF,"iotatonos"},{0x03B0,"upsilondieresistonos"},
- {0x03B1,"alpha"},{0x03B2,"beta"},{0x03B3,"gamma"},{0x03B4,"delta"},
- {0x03B5,"epsilon"},{0x03B6,"zeta"},{0x03B7,"eta"},{0x03B8,"theta"},
- {0x03B9,"iota"},{0x03BA,"kappa"},{0x03BB,"lambda"},{0x03BC,"mu"},
- {0x03BD,"nu"},{0x03BE,"xi"},{0x03BF,"omicron"},{0x03C0,"pi"},
- {0x03C1,"rho"},{0x03C2,"sigma1"},{0x03C3,"sigma"},{0x03C4,"tau"},
- {0x03C5,"upsilon"},{0x03C6,"phi"},{0x03C7,"chi"},{0x03C8,"psi"},
- {0x03C9,"omega"},{0x03CA,"iotadieresis"},{0x03CB,"upsilondieresis"},
- {0x03CC,"omicrontonos"},{0x03CD,"upsilontonos"},{0x03CE,"omegatonos"},
- {0x03D1,"theta1"},{0x03D2,"Upsilon1"},{0x03D5,"phi1"},{0x03D6,"omega1"},
- {0x0401,"afii10023"},{0x0402,"afii10051"},{0x0403,"afii10052"},{0x0404,"afii10053"},
- {0x0405,"afii10054"},{0x0406,"afii10055"},{0x0407,"afii10056"},{0x0408,"afii10057"},
- {0x0409,"afii10058"},{0x040A,"afii10059"},{0x040B,"afii10060"},{0x040C,"afii10061"},
- {0x040E,"afii10062"},{0x040F,"afii10145"},{0x0410,"afii10017"},{0x0411,"afii10018"},
- {0x0412,"afii10019"},{0x0413,"afii10020"},{0x0414,"afii10021"},{0x0415,"afii10022"},
- {0x0416,"afii10024"},{0x0417,"afii10025"},{0x0418,"afii10026"},{0x0419,"afii10027"},
- {0x041A,"afii10028"},{0x041B,"afii10029"},{0x041C,"afii10030"},{0x041D,"afii10031"},
- {0x041E,"afii10032"},{0x041F,"afii10033"},{0x0420,"afii10034"},{0x0421,"afii10035"},
- {0x0422,"afii10036"},{0x0423,"afii10037"},{0x0424,"afii10038"},{0x0425,"afii10039"},
- {0x0426,"afii10040"},{0x0427,"afii10041"},{0x0428,"afii10042"},{0x0429,"afii10043"},
- {0x042A,"afii10044"},{0x042B,"afii10045"},{0x042C,"afii10046"},{0x042D,"afii10047"},
- {0x042E,"afii10048"},{0x042F,"afii10049"},{0x0430,"afii10065"},{0x0431,"afii10066"},
- {0x0432,"afii10067"},{0x0433,"afii10068"},{0x0434,"afii10069"},{0x0435,"afii10070"},
- {0x0436,"afii10072"},{0x0437,"afii10073"},{0x0438,"afii10074"},{0x0439,"afii10075"},
- {0x043A,"afii10076"},{0x043B,"afii10077"},{0x043C,"afii10078"},{0x043D,"afii10079"},
- {0x043E,"afii10080"},{0x043F,"afii10081"},{0x0440,"afii10082"},{0x0441,"afii10083"},
- {0x0442,"afii10084"},{0x0443,"afii10085"},{0x0444,"afii10086"},{0x0445,"afii10087"},
- {0x0446,"afii10088"},{0x0447,"afii10089"},{0x0448,"afii10090"},{0x0449,"afii10091"},
- {0x044A,"afii10092"},{0x044B,"afii10093"},{0x044C,"afii10094"},{0x044D,"afii10095"},
- {0x044E,"afii10096"},{0x044F,"afii10097"},{0x0451,"afii10071"},{0x0452,"afii10099"},
- {0x0453,"afii10100"},{0x0454,"afii10101"},{0x0455,"afii10102"},{0x0456,"afii10103"},
- {0x0457,"afii10104"},{0x0458,"afii10105"},{0x0459,"afii10106"},{0x045A,"afii10107"},
- {0x045B,"afii10108"},{0x045C,"afii10109"},{0x045E,"afii10110"},{0x045F,"afii10193"},
- {0x0462,"afii10146"},{0x0463,"afii10194"},{0x0472,"afii10147"},{0x0473,"afii10195"},
- {0x0474,"afii10148"},{0x0475,"afii10196"},{0x0490,"afii10050"},{0x0491,"afii10098"},
- {0x04D9,"afii10846"},{0x05B0,"afii57799"},{0x05B1,"afii57801"},{0x05B2,"afii57800"},
- {0x05B3,"afii57802"},{0x05B4,"afii57793"},{0x05B5,"afii57794"},{0x05B6,"afii57795"},
- {0x05B7,"afii57798"},{0x05B8,"afii57797"},{0x05B9,"afii57806"},{0x05BB,"afii57796"},
- {0x05BC,"afii57807"},{0x05BD,"afii57839"},{0x05BE,"afii57645"},{0x05BF,"afii57841"},
- {0x05C0,"afii57842"},{0x05C1,"afii57804"},{0x05C2,"afii57803"},{0x05C3,"afii57658"},
- {0x05D0,"afii57664"},{0x05D1,"afii57665"},{0x05D2,"afii57666"},{0x05D3,"afii57667"},
- {0x05D4,"afii57668"},{0x05D5,"afii57669"},{0x05D6,"afii57670"},{0x05D7,"afii57671"},
- {0x05D8,"afii57672"},{0x05D9,"afii57673"},{0x05DA,"afii57674"},{0x05DB,"afii57675"},
- {0x05DC,"afii57676"},{0x05DD,"afii57677"},{0x05DE,"afii57678"},{0x05DF,"afii57679"},
- {0x05E0,"afii57680"},{0x05E1,"afii57681"},{0x05E2,"afii57682"},{0x05E3,"afii57683"},
- {0x05E4,"afii57684"},{0x05E5,"afii57685"},{0x05E6,"afii57686"},{0x05E7,"afii57687"},
- {0x05E8,"afii57688"},{0x05E9,"afii57689"},{0x05EA,"afii57690"},{0x05F0,"afii57716"},
- {0x05F1,"afii57717"},{0x05F2,"afii57718"},{0x060C,"afii57388"},{0x061B,"afii57403"},
- {0x061F,"afii57407"},{0x0621,"afii57409"},{0x0622,"afii57410"},{0x0623,"afii57411"},
- {0x0624,"afii57412"},{0x0625,"afii57413"},{0x0626,"afii57414"},{0x0627,"afii57415"},
- {0x0628,"afii57416"},{0x0629,"afii57417"},{0x062A,"afii57418"},{0x062B,"afii57419"},
- {0x062C,"afii57420"},{0x062D,"afii57421"},{0x062E,"afii57422"},{0x062F,"afii57423"},
- {0x0630,"afii57424"},{0x0631,"afii57425"},{0x0632,"afii57426"},{0x0633,"afii57427"},
- {0x0634,"afii57428"},{0x0635,"afii57429"},{0x0636,"afii57430"},{0x0637,"afii57431"},
- {0x0638,"afii57432"},{0x0639,"afii57433"},{0x063A,"afii57434"},{0x0640,"afii57440"},
- {0x0641,"afii57441"},{0x0642,"afii57442"},{0x0643,"afii57443"},{0x0644,"afii57444"},
- {0x0645,"afii57445"},{0x0646,"afii57446"},{0x0647,"afii57470"},{0x0648,"afii57448"},
- {0x0649,"afii57449"},{0x064A,"afii57450"},{0x064B,"afii57451"},{0x064C,"afii57452"},
- {0x064D,"afii57453"},{0x064E,"afii57454"},{0x064F,"afii57455"},{0x0650,"afii57456"},
- {0x0651,"afii57457"},{0x0652,"afii57458"},{0x0660,"afii57392"},{0x0661,"afii57393"},
- {0x0662,"afii57394"},{0x0663,"afii57395"},{0x0664,"afii57396"},{0x0665,"afii57397"},
- {0x0666,"afii57398"},{0x0667,"afii57399"},{0x0668,"afii57400"},{0x0669,"afii57401"},
- {0x066A,"afii57381"},{0x066D,"afii63167"},{0x0679,"afii57511"},{0x067E,"afii57506"},
- {0x0686,"afii57507"},{0x0688,"afii57512"},{0x0691,"afii57513"},{0x0698,"afii57508"},
- {0x06A4,"afii57505"},{0x06AF,"afii57509"},{0x06BA,"afii57514"},{0x06D2,"afii57519"},
- {0x06D5,"afii57534"},{0x1E80,"Wgrave"},{0x1E81,"wgrave"},{0x1E82,"Wacute"},
- {0x1E83,"wacute"},{0x1E84,"Wdieresis"},{0x1E85,"wdieresis"},{0x1EF2,"Ygrave"},
- {0x1EF3,"ygrave"},{0x200C,"afii61664"},{0x200D,"afii301"},{0x200E,"afii299"},
- {0x200F,"afii300"},{0x2012,"figuredash"},{0x2013,"endash"},{0x2014,"emdash"},
- {0x2015,"afii00208"},{0x2017,"underscoredbl"},{0x2018,"quoteleft"},{0x2019,"quoteright"},
- {0x201A,"quotesinglbase"},{0x201B,"quotereversed"},{0x201C,"quotedblleft"},{0x201D,"quotedblright"},
- {0x201E,"quotedblbase"},{0x2020,"dagger"},{0x2021,"daggerdbl"},{0x2022,"bullet"},
- {0x2024,"onedotenleader"},{0x2025,"twodotenleader"},{0x2026,"ellipsis"},{0x202C,"afii61573"},
- {0x202D,"afii61574"},{0x202E,"afii61575"},{0x2030,"perthousand"},{0x2032,"minute"},
- {0x2033,"second"},{0x2039,"guilsinglleft"},{0x203A,"guilsinglright"},{0x203C,"exclamdbl"},
- {0x2044,"fraction"},{0x20A1,"colonmonetary"},{0x20A3,"franc"},{0x20A4,"lira"},
- {0x20A7,"peseta"},{0x20AA,"afii57636"},{0x20AB,"dong"},{0x20AC,"Euro"},
- {0x2105,"afii61248"},{0x2111,"Ifraktur"},{0x2113,"afii61289"},{0x2116,"afii61352"},
- {0x2118,"weierstrass"},{0x211C,"Rfraktur"},{0x211E,"prescription"},{0x2122,"trademark"},
- {0x212E,"estimated"},{0x2135,"aleph"},{0x2153,"onethird"},{0x2154,"twothirds"},
- {0x215B,"oneeighth"},{0x215C,"threeeighths"},{0x215D,"fiveeighths"},{0x215E,"seveneighths"},
- {0x2190,"arrowleft"},{0x2191,"arrowup"},{0x2192,"arrowright"},{0x2193,"arrowdown"},
- {0x2194,"arrowboth"},{0x2195,"arrowupdn"},{0x21A8,"arrowupdnbse"},{0x21B5,"carriagereturn"},
- {0x21D0,"arrowdblleft"},{0x21D1,"arrowdblup"},{0x21D2,"arrowdblright"},{0x21D3,"arrowdbldown"},
- {0x21D4,"arrowdblboth"},{0x2200,"universal"},{0x2202,"partialdiff"},{0x2203,"existential"},
- {0x2205,"emptyset"},{0x2207,"gradient"},{0x2208,"element"},{0x2209,"notelement"},
- {0x220B,"suchthat"},{0x220F,"product"},{0x2211,"summation"},{0x2212,"minus"},
- {0x2217,"asteriskmath"},{0x221A,"radical"},{0x221D,"proportional"},{0x221E,"infinity"},
- {0x221F,"orthogonal"},{0x2220,"angle"},{0x2227,"logicaland"},{0x2228,"logicalor"},
- {0x2229,"intersection"},{0x222A,"union"},{0x222B,"integral"},{0x2234,"therefore"},
- {0x223C,"similar"},{0x2245,"congruent"},{0x2248,"approxequal"},{0x2260,"notequal"},
- {0x2261,"equivalence"},{0x2264,"lessequal"},{0x2265,"greaterequal"},{0x2282,"propersubset"},
- {0x2283,"propersuperset"},{0x2284,"notsubset"},{0x2286,"reflexsubset"},{0x2287,"reflexsuperset"},
- {0x2295,"circleplus"},{0x2297,"circlemultiply"},{0x22A5,"perpendicular"},{0x22C5,"dotmath"},
- {0x2302,"house"},{0x2310,"revlogicalnot"},{0x2320,"integraltp"},{0x2321,"integralbt"},
- {0x2329,"angleleft"},{0x232A,"angleright"},{0x2500,"SF100000"},{0x2502,"SF110000"},
- {0x250C,"SF010000"},{0x2510,"SF030000"},{0x2514,"SF020000"},{0x2518,"SF040000"},
- {0x251C,"SF080000"},{0x2524,"SF090000"},{0x252C,"SF060000"},{0x2534,"SF070000"},
- {0x253C,"SF050000"},{0x2550,"SF430000"},{0x2551,"SF240000"},{0x2552,"SF510000"},
- {0x2553,"SF520000"},{0x2554,"SF390000"},{0x2555,"SF220000"},{0x2556,"SF210000"},
- {0x2557,"SF250000"},{0x2558,"SF500000"},{0x2559,"SF490000"},{0x255A,"SF380000"},
- {0x255B,"SF280000"},{0x255C,"SF270000"},{0x255D,"SF260000"},{0x255E,"SF360000"},
- {0x255F,"SF370000"},{0x2560,"SF420000"},{0x2561,"SF190000"},{0x2562,"SF200000"},
- {0x2563,"SF230000"},{0x2564,"SF470000"},{0x2565,"SF480000"},{0x2566,"SF410000"},
- {0x2567,"SF450000"},{0x2568,"SF460000"},{0x2569,"SF400000"},{0x256A,"SF540000"},
- {0x256B,"SF530000"},{0x256C,"SF440000"},{0x2580,"upblock"},{0x2584,"dnblock"},
- {0x2588,"block"},{0x258C,"lfblock"},{0x2590,"rtblock"},{0x2591,"ltshade"},
- {0x2592,"shade"},{0x2593,"dkshade"},{0x25A0,"filledbox"},{0x25A1,"H22073"},
- {0x25AA,"H18543"},{0x25AB,"H18551"},{0x25AC,"filledrect"},{0x25B2,"triagup"},
- {0x25BA,"triagrt"},{0x25BC,"triagdn"},{0x25C4,"triaglf"},{0x25CA,"lozenge"},
- {0x25CB,"circle"},{0x25CF,"H18533"},{0x25D8,"invbullet"},{0x25D9,"invcircle"},
- {0x25E6,"openbullet"},{0x263A,"smileface"},{0x263B,"invsmileface"},{0x263C,"sun"},
- {0x2640,"female"},{0x2642,"male"},{0x2660,"spade"},{0x2663,"club"},
- {0x2665,"heart"},{0x2666,"diamond"},{0x266A,"musicalnote"},{0x266B,"musicalnotedbl"}};
+struct agl_lt { unsigned short uid; const char *name; } agl_lxx[] =
+{
+ {0x0192, "florin"}, {0x01A0, "Ohorn"}, {0x01A1, "ohorn"}, {0x01AF, "Uhorn"},
+ {0x01B0, "uhorn"}, {0x01E6, "Gcaron"}, {0x01E7, "gcaron"}, {0x01FA, "Aringacute"},
+ {0x01FB, "aringacute"}, {0x01FC, "AEacute"}, {0x01FD, "aeacute"}, {0x01FE, "Oslashacute"},
+ {0x01FF, "oslashacute"}, {0x0218, "Scommaaccent"}, {0x0219, "scommaaccent"}, {0x02BC, "afii57929"},
+ {0x02BD, "afii64937"}, {0x02C6, "circumflex"}, {0x02C7, "caron"}, {0x02D8, "breve"},
+ {0x02D9, "dotaccent"}, {0x02DA, "ring"}, {0x02DB, "ogonek"}, {0x02DC, "tilde"},
+ {0x02DD, "hungarumlaut"}, {0x0300, "gravecomb"}, {0x0301, "acutecomb"}, {0x0303, "tildecomb"},
+ {0x0309, "hookabovecomb"}, {0x0323, "dotbelowcomb"}, {0x0384, "tonos"}, {0x0385, "dieresistonos"},
+ {0x0386, "Alphatonos"}, {0x0387, "anoteleia"}, {0x0388, "Epsilontonos"}, {0x0389, "Etatonos"},
+ {0x038A, "Iotatonos"}, {0x038C, "Omicrontonos"}, {0x038E, "Upsilontonos"}, {0x038F, "Omegatonos"},
+ {0x0390, "iotadieresistonos"}, {0x0391, "Alpha"}, {0x0392, "Beta"}, {0x0393, "Gamma"},
+ {0x0394, "Delta"}, {0x0395, "Epsilon"}, {0x0396, "Zeta"}, {0x0397, "Eta"},
+ {0x0398, "Theta"}, {0x0399, "Iota"}, {0x039A, "Kappa"}, {0x039B, "Lambda"},
+ {0x039C, "Mu"}, {0x039D, "Nu"}, {0x039E, "Xi"}, {0x039F, "Omicron"},
+ {0x03A0, "Pi"}, {0x03A1, "Rho"}, {0x03A3, "Sigma"}, {0x03A4, "Tau"},
+ {0x03A5, "Upsilon"}, {0x03A6, "Phi"}, {0x03A7, "Chi"}, {0x03A8, "Psi"},
+ {0x03A9, "Omega"}, {0x03AA, "Iotadieresis"}, {0x03AB, "Upsilondieresis"}, {0x03AC, "alphatonos"},
+ {0x03AD, "epsilontonos"}, {0x03AE, "etatonos"}, {0x03AF, "iotatonos"}, {0x03B0, "upsilondieresistonos"},
+ {0x03B1, "alpha"}, {0x03B2, "beta"}, {0x03B3, "gamma"}, {0x03B4, "delta"},
+ {0x03B5, "epsilon"}, {0x03B6, "zeta"}, {0x03B7, "eta"}, {0x03B8, "theta"},
+ {0x03B9, "iota"}, {0x03BA, "kappa"}, {0x03BB, "lambda"}, {0x03BC, "mu"},
+ {0x03BD, "nu"}, {0x03BE, "xi"}, {0x03BF, "omicron"}, {0x03C0, "pi"},
+ {0x03C1, "rho"}, {0x03C2, "sigma1"}, {0x03C3, "sigma"}, {0x03C4, "tau"},
+ {0x03C5, "upsilon"}, {0x03C6, "phi"}, {0x03C7, "chi"}, {0x03C8, "psi"},
+ {0x03C9, "omega"}, {0x03CA, "iotadieresis"}, {0x03CB, "upsilondieresis"},
+ {0x03CC, "omicrontonos"}, {0x03CD, "upsilontonos"}, {0x03CE, "omegatonos"},
+ {0x03D1, "theta1"}, {0x03D2, "Upsilon1"}, {0x03D5, "phi1"}, {0x03D6, "omega1"},
+ {0x0401, "afii10023"}, {0x0402, "afii10051"}, {0x0403, "afii10052"}, {0x0404, "afii10053"},
+ {0x0405, "afii10054"}, {0x0406, "afii10055"}, {0x0407, "afii10056"}, {0x0408, "afii10057"},
+ {0x0409, "afii10058"}, {0x040A, "afii10059"}, {0x040B, "afii10060"}, {0x040C, "afii10061"},
+ {0x040E, "afii10062"}, {0x040F, "afii10145"}, {0x0410, "afii10017"}, {0x0411, "afii10018"},
+ {0x0412, "afii10019"}, {0x0413, "afii10020"}, {0x0414, "afii10021"}, {0x0415, "afii10022"},
+ {0x0416, "afii10024"}, {0x0417, "afii10025"}, {0x0418, "afii10026"}, {0x0419, "afii10027"},
+ {0x041A, "afii10028"}, {0x041B, "afii10029"}, {0x041C, "afii10030"}, {0x041D, "afii10031"},
+ {0x041E, "afii10032"}, {0x041F, "afii10033"}, {0x0420, "afii10034"}, {0x0421, "afii10035"},
+ {0x0422, "afii10036"}, {0x0423, "afii10037"}, {0x0424, "afii10038"}, {0x0425, "afii10039"},
+ {0x0426, "afii10040"}, {0x0427, "afii10041"}, {0x0428, "afii10042"}, {0x0429, "afii10043"},
+ {0x042A, "afii10044"}, {0x042B, "afii10045"}, {0x042C, "afii10046"}, {0x042D, "afii10047"},
+ {0x042E, "afii10048"}, {0x042F, "afii10049"}, {0x0430, "afii10065"}, {0x0431, "afii10066"},
+ {0x0432, "afii10067"}, {0x0433, "afii10068"}, {0x0434, "afii10069"}, {0x0435, "afii10070"},
+ {0x0436, "afii10072"}, {0x0437, "afii10073"}, {0x0438, "afii10074"}, {0x0439, "afii10075"},
+ {0x043A, "afii10076"}, {0x043B, "afii10077"}, {0x043C, "afii10078"}, {0x043D, "afii10079"},
+ {0x043E, "afii10080"}, {0x043F, "afii10081"}, {0x0440, "afii10082"}, {0x0441, "afii10083"},
+ {0x0442, "afii10084"}, {0x0443, "afii10085"}, {0x0444, "afii10086"}, {0x0445, "afii10087"},
+ {0x0446, "afii10088"}, {0x0447, "afii10089"}, {0x0448, "afii10090"}, {0x0449, "afii10091"},
+ {0x044A, "afii10092"}, {0x044B, "afii10093"}, {0x044C, "afii10094"}, {0x044D, "afii10095"},
+ {0x044E, "afii10096"}, {0x044F, "afii10097"}, {0x0451, "afii10071"}, {0x0452, "afii10099"},
+ {0x0453, "afii10100"}, {0x0454, "afii10101"}, {0x0455, "afii10102"}, {0x0456, "afii10103"},
+ {0x0457, "afii10104"}, {0x0458, "afii10105"}, {0x0459, "afii10106"}, {0x045A, "afii10107"},
+ {0x045B, "afii10108"}, {0x045C, "afii10109"}, {0x045E, "afii10110"}, {0x045F, "afii10193"},
+ {0x0462, "afii10146"}, {0x0463, "afii10194"}, {0x0472, "afii10147"}, {0x0473, "afii10195"},
+ {0x0474, "afii10148"}, {0x0475, "afii10196"}, {0x0490, "afii10050"}, {0x0491, "afii10098"},
+ {0x04D9, "afii10846"}, {0x05B0, "afii57799"}, {0x05B1, "afii57801"}, {0x05B2, "afii57800"},
+ {0x05B3, "afii57802"}, {0x05B4, "afii57793"}, {0x05B5, "afii57794"}, {0x05B6, "afii57795"},
+ {0x05B7, "afii57798"}, {0x05B8, "afii57797"}, {0x05B9, "afii57806"}, {0x05BB, "afii57796"},
+ {0x05BC, "afii57807"}, {0x05BD, "afii57839"}, {0x05BE, "afii57645"}, {0x05BF, "afii57841"},
+ {0x05C0, "afii57842"}, {0x05C1, "afii57804"}, {0x05C2, "afii57803"}, {0x05C3, "afii57658"},
+ {0x05D0, "afii57664"}, {0x05D1, "afii57665"}, {0x05D2, "afii57666"}, {0x05D3, "afii57667"},
+ {0x05D4, "afii57668"}, {0x05D5, "afii57669"}, {0x05D6, "afii57670"}, {0x05D7, "afii57671"},
+ {0x05D8, "afii57672"}, {0x05D9, "afii57673"}, {0x05DA, "afii57674"}, {0x05DB, "afii57675"},
+ {0x05DC, "afii57676"}, {0x05DD, "afii57677"}, {0x05DE, "afii57678"}, {0x05DF, "afii57679"},
+ {0x05E0, "afii57680"}, {0x05E1, "afii57681"}, {0x05E2, "afii57682"}, {0x05E3, "afii57683"},
+ {0x05E4, "afii57684"}, {0x05E5, "afii57685"}, {0x05E6, "afii57686"}, {0x05E7, "afii57687"},
+ {0x05E8, "afii57688"}, {0x05E9, "afii57689"}, {0x05EA, "afii57690"}, {0x05F0, "afii57716"},
+ {0x05F1, "afii57717"}, {0x05F2, "afii57718"}, {0x060C, "afii57388"}, {0x061B, "afii57403"},
+ {0x061F, "afii57407"}, {0x0621, "afii57409"}, {0x0622, "afii57410"}, {0x0623, "afii57411"},
+ {0x0624, "afii57412"}, {0x0625, "afii57413"}, {0x0626, "afii57414"}, {0x0627, "afii57415"},
+ {0x0628, "afii57416"}, {0x0629, "afii57417"}, {0x062A, "afii57418"}, {0x062B, "afii57419"},
+ {0x062C, "afii57420"}, {0x062D, "afii57421"}, {0x062E, "afii57422"}, {0x062F, "afii57423"},
+ {0x0630, "afii57424"}, {0x0631, "afii57425"}, {0x0632, "afii57426"}, {0x0633, "afii57427"},
+ {0x0634, "afii57428"}, {0x0635, "afii57429"}, {0x0636, "afii57430"}, {0x0637, "afii57431"},
+ {0x0638, "afii57432"}, {0x0639, "afii57433"}, {0x063A, "afii57434"}, {0x0640, "afii57440"},
+ {0x0641, "afii57441"}, {0x0642, "afii57442"}, {0x0643, "afii57443"}, {0x0644, "afii57444"},
+ {0x0645, "afii57445"}, {0x0646, "afii57446"}, {0x0647, "afii57470"}, {0x0648, "afii57448"},
+ {0x0649, "afii57449"}, {0x064A, "afii57450"}, {0x064B, "afii57451"}, {0x064C, "afii57452"},
+ {0x064D, "afii57453"}, {0x064E, "afii57454"}, {0x064F, "afii57455"}, {0x0650, "afii57456"},
+ {0x0651, "afii57457"}, {0x0652, "afii57458"}, {0x0660, "afii57392"}, {0x0661, "afii57393"},
+ {0x0662, "afii57394"}, {0x0663, "afii57395"}, {0x0664, "afii57396"}, {0x0665, "afii57397"},
+ {0x0666, "afii57398"}, {0x0667, "afii57399"}, {0x0668, "afii57400"}, {0x0669, "afii57401"},
+ {0x066A, "afii57381"}, {0x066D, "afii63167"}, {0x0679, "afii57511"}, {0x067E, "afii57506"},
+ {0x0686, "afii57507"}, {0x0688, "afii57512"}, {0x0691, "afii57513"}, {0x0698, "afii57508"},
+ {0x06A4, "afii57505"}, {0x06AF, "afii57509"}, {0x06BA, "afii57514"}, {0x06D2, "afii57519"},
+ {0x06D5, "afii57534"}, {0x1E80, "Wgrave"}, {0x1E81, "wgrave"}, {0x1E82, "Wacute"},
+ {0x1E83, "wacute"}, {0x1E84, "Wdieresis"}, {0x1E85, "wdieresis"}, {0x1EF2, "Ygrave"},
+ {0x1EF3, "ygrave"}, {0x200C, "afii61664"}, {0x200D, "afii301"}, {0x200E, "afii299"},
+ {0x200F, "afii300"}, {0x2012, "figuredash"}, {0x2013, "endash"}, {0x2014, "emdash"},
+ {0x2015, "afii00208"}, {0x2017, "underscoredbl"}, {0x2018, "quoteleft"}, {0x2019, "quoteright"},
+ {0x201A, "quotesinglbase"}, {0x201B, "quotereversed"}, {0x201C, "quotedblleft"}, {0x201D, "quotedblright"},
+ {0x201E, "quotedblbase"}, {0x2020, "dagger"}, {0x2021, "daggerdbl"}, {0x2022, "bullet"},
+ {0x2024, "onedotenleader"}, {0x2025, "twodotenleader"}, {0x2026, "ellipsis"}, {0x202C, "afii61573"},
+ {0x202D, "afii61574"}, {0x202E, "afii61575"}, {0x2030, "perthousand"}, {0x2032, "minute"},
+ {0x2033, "second"}, {0x2039, "guilsinglleft"}, {0x203A, "guilsinglright"}, {0x203C, "exclamdbl"},
+ {0x2044, "fraction"}, {0x20A1, "colonmonetary"}, {0x20A3, "franc"}, {0x20A4, "lira"},
+ {0x20A7, "peseta"}, {0x20AA, "afii57636"}, {0x20AB, "dong"}, {0x20AC, "Euro"},
+ {0x2105, "afii61248"}, {0x2111, "Ifraktur"}, {0x2113, "afii61289"}, {0x2116, "afii61352"},
+ {0x2118, "weierstrass"}, {0x211C, "Rfraktur"}, {0x211E, "prescription"}, {0x2122, "trademark"},
+ {0x212E, "estimated"}, {0x2135, "aleph"}, {0x2153, "onethird"}, {0x2154, "twothirds"},
+ {0x215B, "oneeighth"}, {0x215C, "threeeighths"}, {0x215D, "fiveeighths"}, {0x215E, "seveneighths"},
+ {0x2190, "arrowleft"}, {0x2191, "arrowup"}, {0x2192, "arrowright"}, {0x2193, "arrowdown"},
+ {0x2194, "arrowboth"}, {0x2195, "arrowupdn"}, {0x21A8, "arrowupdnbse"}, {0x21B5, "carriagereturn"},
+ {0x21D0, "arrowdblleft"}, {0x21D1, "arrowdblup"}, {0x21D2, "arrowdblright"}, {0x21D3, "arrowdbldown"},
+ {0x21D4, "arrowdblboth"}, {0x2200, "universal"}, {0x2202, "partialdiff"}, {0x2203, "existential"},
+ {0x2205, "emptyset"}, {0x2207, "gradient"}, {0x2208, "element"}, {0x2209, "notelement"},
+ {0x220B, "suchthat"}, {0x220F, "product"}, {0x2211, "summation"}, {0x2212, "minus"},
+ {0x2217, "asteriskmath"}, {0x221A, "radical"}, {0x221D, "proportional"}, {0x221E, "infinity"},
+ {0x221F, "orthogonal"}, {0x2220, "angle"}, {0x2227, "logicaland"}, {0x2228, "logicalor"},
+ {0x2229, "intersection"}, {0x222A, "union"}, {0x222B, "integral"}, {0x2234, "therefore"},
+ {0x223C, "similar"}, {0x2245, "congruent"}, {0x2248, "approxequal"}, {0x2260, "notequal"},
+ {0x2261, "equivalence"}, {0x2264, "lessequal"}, {0x2265, "greaterequal"}, {0x2282, "propersubset"},
+ {0x2283, "propersuperset"}, {0x2284, "notsubset"}, {0x2286, "reflexsubset"}, {0x2287, "reflexsuperset"},
+ {0x2295, "circleplus"}, {0x2297, "circlemultiply"}, {0x22A5, "perpendicular"}, {0x22C5, "dotmath"},
+ {0x2302, "house"}, {0x2310, "revlogicalnot"}, {0x2320, "integraltp"}, {0x2321, "integralbt"},
+ {0x2329, "angleleft"}, {0x232A, "angleright"}, {0x2500, "SF100000"}, {0x2502, "SF110000"},
+ {0x250C, "SF010000"}, {0x2510, "SF030000"}, {0x2514, "SF020000"}, {0x2518, "SF040000"},
+ {0x251C, "SF080000"}, {0x2524, "SF090000"}, {0x252C, "SF060000"}, {0x2534, "SF070000"},
+ {0x253C, "SF050000"}, {0x2550, "SF430000"}, {0x2551, "SF240000"}, {0x2552, "SF510000"},
+ {0x2553, "SF520000"}, {0x2554, "SF390000"}, {0x2555, "SF220000"}, {0x2556, "SF210000"},
+ {0x2557, "SF250000"}, {0x2558, "SF500000"}, {0x2559, "SF490000"}, {0x255A, "SF380000"},
+ {0x255B, "SF280000"}, {0x255C, "SF270000"}, {0x255D, "SF260000"}, {0x255E, "SF360000"},
+ {0x255F, "SF370000"}, {0x2560, "SF420000"}, {0x2561, "SF190000"}, {0x2562, "SF200000"},
+ {0x2563, "SF230000"}, {0x2564, "SF470000"}, {0x2565, "SF480000"}, {0x2566, "SF410000"},
+ {0x2567, "SF450000"}, {0x2568, "SF460000"}, {0x2569, "SF400000"}, {0x256A, "SF540000"},
+ {0x256B, "SF530000"}, {0x256C, "SF440000"}, {0x2580, "upblock"}, {0x2584, "dnblock"},
+ {0x2588, "block"}, {0x258C, "lfblock"}, {0x2590, "rtblock"}, {0x2591, "ltshade"},
+ {0x2592, "shade"}, {0x2593, "dkshade"}, {0x25A0, "filledbox"}, {0x25A1, "H22073"},
+ {0x25AA, "H18543"}, {0x25AB, "H18551"}, {0x25AC, "filledrect"}, {0x25B2, "triagup"},
+ {0x25BA, "triagrt"}, {0x25BC, "triagdn"}, {0x25C4, "triaglf"}, {0x25CA, "lozenge"},
+ {0x25CB, "circle"}, {0x25CF, "H18533"}, {0x25D8, "invbullet"}, {0x25D9, "invcircle"},
+ {0x25E6, "openbullet"}, {0x263A, "smileface"}, {0x263B, "invsmileface"}, {0x263C, "sun"},
+ {0x2640, "female"}, {0x2642, "male"}, {0x2660, "spade"}, {0x2663, "club"},
+ {0x2665, "heart"}, {0x2666, "diamond"}, {0x266A, "musicalnote"}, {0x266B, "musicalnotedbl"}};
-static int agl_cmp(const void *a,const void *b)
+static int
+agl_cmp(const void *a,
+ const void *b)
{
- const unsigned short aa=((struct agl_lt *)a)->uid,bb=((struct agl_lt *)b)->uid;
- if (aa<bb) {
- return -1;
- } else if (aa>bb) {
- return 1;
- }
- return 0;
+ const unsigned short aa = ((struct agl_lt *)a)->uid,
+ bb = ((struct agl_lt *)b)->uid;
+ if (aa < bb)
+ return (-1);
+ else if (aa > bb)
+ return (1);
+ return (0);
}
-const char *aglfn13(unsigned short uni)
+const char *
+aglfn13(unsigned short uni)
{
- if ( (uni>=0x0020)&&(uni<0x007f) ) {
- return agl_l207e[uni-0x0020];
- } else if ( (uni>=0x00a1)&&(uni<=0x00ff) ) {
- return agl_la1ff[uni-0x00a1];
- } else if ( (uni>=0x0100)&&(uni<=0x017f) ) {
- return agl_l1007f[uni-0x0100];
- } else if (uni>=0x0180) {
- struct agl_lt key,*res;
- key.uid=uni;
- res=bsearch(&key,agl_lxx,(sizeof(agl_lxx)/sizeof(struct agl_lt)),sizeof(struct agl_lt),agl_cmp);
- if (res) {
- return res->name;
- }
+ if ((uni >= 0x0020) && (uni < 0x007f))
+ return (agl_l207e[uni-0x0020]);
+ else if ((uni >= 0x00a1) && (uni <= 0x00ff))
+ return (agl_la1ff[uni-0x00a1]);
+ else if ((uni >= 0x0100) && (uni <= 0x017f))
+ return (agl_l1007f[uni-0x0100]);
+ else if (uni >= 0x0180)
+ {
+ struct agl_lt key, *res;
+ key.uid = uni;
+ res = bsearch(&key, agl_lxx, (sizeof(agl_lxx) / sizeof(struct agl_lt)),
+ sizeof(struct agl_lt), agl_cmp);
+ if (res)
+ return (res->name);
}
- return NULL;
+ return (NULL);
}
#else
-const char *aglfn13(unsigned short uni)
+
+
+const char *
+aglfn13(unsigned short uni)
{
- return NULL;
+ return (NULL);
}
-#endif
+#endif // WITH_AGLFN
-#ifndef _BITSET_H
-#define _BITSET_H
+#ifndef _FONTEMBED_BITSET_H_
+#define _FONTEMBED_BITSET_H_
#include <stdlib.h>
-typedef int * BITSET;
+typedef int* BITSET;
-static inline void bit_set(BITSET bs,int num)
+
+static inline void
+bit_set(BITSET bs,
+ int num)
{
- bs[num/(8*sizeof(int))]|=1<<(num%(8*sizeof(int)));
+ bs[num / (8 * sizeof(int))] |= 1 << (num % (8 * sizeof(int)));
}
-static inline int bit_check(BITSET bs,int num)
+
+static inline int
+bit_check(BITSET bs,
+ int num)
{
- return bs[num/(8*sizeof(int))]&1<<(num%(8*sizeof(int)));
+ return bs [num / (8 * sizeof(int))] & 1 << (num % (8 * sizeof(int)));
}
-// use free() when done. returns NULL on bad_alloc
-static inline BITSET bitset_new(int size)
+
+// Use free() when done. returns NULL on bad_alloc
+static inline BITSET
+bitset_new(int size)
{
- return (BITSET)calloc(1,((size+8*sizeof(int)-1)&~(8*sizeof(int)-1))/8);
+ return (BITSET)calloc(1, ((size + 8 * sizeof(int) - 1) &
+ ~(8 * sizeof(int) - 1)) / 8);
}
-static inline int bits_used(BITSET bits,int size) // {{{ returns true if any bit is used
+
+static inline int
+bits_used(BITSET bits,
+ int size) // {{{ returns true if any bit is used
{
- size=(size+8*sizeof(int)-1)/(8*sizeof(int));
- while (size>0) {
- if (*bits) {
- return 1;
- }
- bits++;
- size--;
+ size = (size + 8 * sizeof(int) - 1) / (8 * sizeof(int));
+ while (size > 0)
+ {
+ if (*bits)
+ return (1);
+ bits ++;
+ size --;
}
- return 0;
+ return (0);
}
// }}}
-#endif
+#endif // !_FONTEMBED_BITSET_H_
-/*
- * Internal debugging macros for libfontembed.
- *
- * Copyright © 2007-2018 by Apple Inc.
- * Copyright © 1997-2005 by Easy Software Products.
- *
- * Licensed under Apache License v2.0. See the file "LICENSE" for more
- * information.
- */
+//
+// Internal debugging macros for libfontembed.
+//
+// Copyright © 2007-2018 by Apple Inc.
+// Copyright © 1997-2005 by Easy Software Products.
+//
+// Licensed under Apache License v2.0. See the file "LICENSE" for more
+// information.
+//
#ifndef _FONTEMBED_DEBUG_INTERNAL_H_
# define _FONTEMBED_DEBUG_INTERNAL_H_
-/*
- * C++ magic...
- */
+//
+// C++ magic...
+//
# ifdef __cplusplus
extern "C" {
-# endif /* __cplusplus */
+# endif // __cplusplus
-/*
- * The debug macros are used if you compile with DEBUG defined.
- *
- * Usage:
- *
- * DEBUG_assert(boolean expression);
- */
+//
+// The debug macros are used if you compile with DEBUG defined.
+//
+// Usage:
+//
+// DEBUG_assert(boolean expression);
+//
# ifdef DEBUG
# include <assert.h>
# define DEBUG_assert(x) assert(x)
# else
# define DEBUG_assert(x)
-# endif /* DEBUG */
+# endif // DEBUG
# ifdef __cplusplus
}
-# endif /* __cplusplus */
+# endif // __cplusplus
-#endif /* !_FONTEMBED_DEBUG_INTERNAL_H_ */
+#endif // !_FONTEMBED_DEBUG_INTERNAL_H_
-#ifndef _DYNSTRING_H
-#define _DYNSTRING_H
+#ifndef _FONTEMBED_DYNSTRING_H_
+#define _FONTEMBED_DYNSTRING_H_
-typedef struct {
- int len,alloc;
+typedef struct
+{
+ int len, alloc;
char *buf;
} DYN_STRING;
-int dyn_init(DYN_STRING *ds,int reserve_size); // -1 on error
+int dyn_init(DYN_STRING *ds, int reserve_size); // -1 on error
void dyn_free(DYN_STRING *ds);
-int dyn_ensure(DYN_STRING *ds,int free_space);
-int dyn_printf(DYN_STRING *ds,const char *fmt,...) // appends
+int dyn_ensure(DYN_STRING *ds, int free_space);
+int dyn_printf(DYN_STRING *ds, const char *fmt, ...) // appends
__attribute__((format(printf, 2, 3)));
-#endif
-
+#endif // !_FONTEMBED_DYNSTRING_H_
#include <stdlib.h>
#include <string.h>
-int dyn_init(DYN_STRING *ds,int reserve_size) // {{{
+
+int
+dyn_init(DYN_STRING *ds,
+ int reserve_size) // {{{
{
DEBUG_assert(ds);
- DEBUG_assert(reserve_size>0);
+ DEBUG_assert(reserve_size > 0);
- ds->len=0;
- ds->alloc=reserve_size;
- ds->buf=malloc(ds->alloc+1);
- if (!ds->buf) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
+ ds->len = 0;
+ ds->alloc = reserve_size;
+ ds->buf = malloc(ds->alloc + 1);
+ if (!ds->buf)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
DEBUG_assert(0);
- ds->len=-1;
- return -1;
+ ds->len = -1;
+ return (-1);
}
- return 0;
+ return (0);
}
// }}}
-void dyn_free(DYN_STRING *ds) // {{{
+
+void
+dyn_free(DYN_STRING *ds) // {{{
{
DEBUG_assert(ds);
- ds->len=-1;
- ds->alloc=0;
+ ds->len= -1;
+ ds->alloc = 0;
free(ds->buf);
- ds->buf=NULL;
+ ds->buf = NULL;
}
// }}}
-int dyn_ensure(DYN_STRING *ds,int free_space) // {{{
+
+int
+dyn_ensure(DYN_STRING *ds,
+ int free_space) // {{{
{
DEBUG_assert(ds);
DEBUG_assert(free_space);
- if (ds->len<0) {
- return -1;
- }
- if (ds->alloc - ds->len >= free_space) {
- return 0; // done
- }
- ds->alloc+=free_space;
- char *tmp=realloc(ds->buf,ds->alloc+1);
- if (!tmp) {
- ds->len=-1;
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
+ if (ds->len < 0)
+ return (-1);
+ if (ds->alloc - ds->len >= free_space)
+ return (0); // done
+ ds->alloc += free_space;
+ char *tmp = realloc(ds->buf, ds->alloc + 1);
+ if (!tmp)
+ {
+ ds->len = -1;
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
DEBUG_assert(0);
- return -1;
+ return (-1);
}
- ds->buf=tmp;
- return 0;
+ ds->buf = tmp;
+ return (0);
}
// }}}
-int dyn_vprintf(DYN_STRING *ds,const char *fmt,va_list ap) // {{{
+
+int
+dyn_vprintf(DYN_STRING *ds,
+ const char *fmt,
+ va_list ap) // {{{
{
DEBUG_assert(ds);
- int need,len=strlen(fmt)+100;
+ int need, len = strlen(fmt) + 100;
va_list va;
- if (dyn_ensure(ds,len)==-1) {
- return -1;
- }
+ if (dyn_ensure(ds, len) == -1)
+ return (-1);
- while (1) {
- va_copy(va,ap);
- need=vsnprintf(ds->buf+ds->len,ds->alloc-ds->len+1,fmt,va);
+ while (1)
+ {
+ va_copy(va, ap);
+ need = vsnprintf(ds->buf + ds->len, ds->alloc-ds->len + 1, fmt, va);
va_end(va);
- if (need==-1) {
- len+=100;
- } else if (need>=len) {
- len=need;
- } else {
- ds->len+=need;
+ if (need == -1)
+ len += 100;
+ else if (need >= len)
+ len = need;
+ else {
+ ds->len += need;
break;
}
- if (dyn_ensure(ds,len)==-1) {
- return -1;
- }
+ if (dyn_ensure(ds, len) == -1)
+ return (-1);
}
- return 0;
+ return (0);
}
// }}}
-int dyn_printf(DYN_STRING *ds,const char *fmt,...) // {{{
+int
+dyn_printf(DYN_STRING *ds,
+ const char *fmt,
+ ...) // {{{
{
va_list va;
int ret;
- va_start(va,fmt);
- ret=dyn_vprintf(ds,fmt,va);
+ va_start(va, fmt);
+ ret = dyn_vprintf(ds, fmt, va);
va_end(va);
- return ret;
+ return (ret);
}
// }}}
-
-#ifndef EMBED_PDF_INT_H
-#define EMBED_PDF_INT_H
+#ifndef _FONTEMBED_EMBED_PDF_INT_H_
+#define _FONTEMBED_EMBED_PDF_INT_H_
EMB_PDF_FONTWIDTHS *emb_pdf_fw_new(int datasize);
-// if default_width==-1: default_width will be estimated
-// glyphs==NULL -> output all
-EMB_PDF_FONTWIDTHS *emb_pdf_fw_cidwidths(const BITSET glyphs,int len,int default_width,int (*getGlyphWidth)(void *context,int gid),void *context);
+// if default_width == -1: default_width will be estimated
+// glyphs == NULL -> output all
+EMB_PDF_FONTWIDTHS *emb_pdf_fw_cidwidths(const BITSET glyphs,
+ int len, int default_width,
+ int (*getGlyphWidth)
+ (void *context,int gid),
+ void *context);
-#endif
+#endif // !_FONTEMBED_EMBED_PDF_INT_H_
#include <time.h>
#include "frequent-private.h"
+
// NOTE: these must be in sync with the EMB_FORMAT enum
-static const char *emb_pdf_font_subtype[][2]={ // {{{ (output_format,multibyte)
- {"Type1",NULL},
- {"TrueType","CIDFontType2"},
- {"Type1","CIDFontType0"},
- {"Type1","CIDFontType0"},
- {"Type1",NULL}};
+static const char *emb_pdf_font_subtype[][2] =
+{ // {{{ (output_format, multibyte)
+ {"Type1", NULL},
+ {"TrueType", "CIDFontType2"},
+ {"Type1", "CIDFontType0"},
+ {"Type1", "CIDFontType0"},
+ {"Type1", NULL}};
// }}}
-static const char *emb_pdf_fontfile_key[]={ // {{{ (output_format)
- "FontFile","FontFile2","FontFile3","FontFile3",NULL};
+static const char *emb_pdf_fontfile_key[] =
+{ // {{{ (output_format)
+ "FontFile",
+ "FontFile2",
+ "FontFile3",
+ "FontFile3",
+ NULL};
// }}}
// ... PDF1.6 here
-static const char *emb_pdf_fontfile_subtype[][2]={ // {{{ (output_format,multibyte)
- {NULL,NULL},
- {NULL,NULL},
- {"OpenType","OpenType"},
- {"Type1C","CIDFontType0C"},
- {NULL,NULL}};
+static const char *emb_pdf_fontfile_subtype[][2] =
+{ // {{{ (output_format,multibyte)
+ {NULL, NULL},
+ {NULL, NULL},
+ {"OpenType", "OpenType"},
+ {"Type1C", "CIDFontType0C"},
+ {NULL, NULL}};
// }}}
-static inline int emb_multibyte(EMB_PARAMS *emb) // {{{
+
+static inline int
+emb_multibyte(EMB_PARAMS *emb) // {{{
{
- return (emb->plan&EMB_A_MULTIBYTE)?1:0;
+ return ((emb->plan & EMB_A_MULTIBYTE) ? 1 : 0);
}
// }}}
-static const char *emb_pdf_escape_name(const char *name,int len) // {{{ // - statically allocated buffer
+
+static const char
+*emb_pdf_escape_name(const char *name,
+ int len) // {{{ // - statically allocated buffer
{
DEBUG_assert(name);
- if (len==-1) {
- len=strlen(name);
- }
- DEBUG_assert(len<=127); // pdf implementation limit
+ if (len == -1)
+ len = strlen(name);
+ DEBUG_assert(len <= 127); // PDF implementation limit
- static char buf[128*3];
- int iA,iB;
+ static char buf[128 * 3];
+ int iA, iB;
const char hex[]="0123456789abcdef";
- for (iA=0,iB=0;iA<len;iA++,iB++) {
- if ( ((unsigned char)name[iA]<33)||((unsigned char)name[iA]>126)||
- (strchr("#()<>[]{}/%",name[iA])) ) {
- buf[iB]='#';
- buf[++iB]=hex[(name[iA]>>4)&0x0f];
- buf[++iB]=hex[name[iA]&0xf];
- } else {
- buf[iB]=name[iA];
+ for (iA = 0, iB = 0; iA < len; iA ++, iB ++)
+ {
+ if (((unsigned char)name[iA] < 33) || ((unsigned char)name[iA] > 126) ||
+ (strchr("#()<>[]{}/%", name[iA])))
+ {
+ buf[iB] = '#';
+ buf[++iB] = hex[(name[iA] >> 4) & 0x0f];
+ buf[++iB] = hex[name[iA] & 0xf];
}
+ else
+ buf[iB] = name[iA];
}
- buf[iB]=0;
- return buf;
+ buf[iB] = 0;
+ return (buf);
}
// }}}
+
// this is in the font dict
-const char *emb_pdf_get_font_subtype(EMB_PARAMS *emb) // {{{
+
+const char *
+emb_pdf_get_font_subtype(EMB_PARAMS *emb) // {{{
{
DEBUG_assert(emb);
- return emb_pdf_font_subtype[emb->outtype][emb_multibyte(emb)];
+ return (emb_pdf_font_subtype[emb->outtype][emb_multibyte(emb)]);
}
// }}}
+
// in font descriptor
-const char *emb_pdf_get_fontfile_key(EMB_PARAMS *emb) // {{{
+
+const char *
+emb_pdf_get_fontfile_key(EMB_PARAMS *emb) // {{{
{
DEBUG_assert(emb);
- return emb_pdf_fontfile_key[emb->outtype];
+ return (emb_pdf_fontfile_key[emb->outtype]);
}
// }}}
+
// this is what to put in the font-stream dict
-const char *emb_pdf_get_fontfile_subtype(EMB_PARAMS *emb) // {{{
+
+const char *
+emb_pdf_get_fontfile_subtype(EMB_PARAMS *emb) // {{{
{
DEBUG_assert(emb);
- return emb_pdf_fontfile_subtype[emb->outtype][emb_multibyte(emb)];
+ return (emb_pdf_fontfile_subtype[emb->outtype][emb_multibyte(emb)]);
}
// }}}
-// {{{ static EMB_PDF_FONTDESCR *emb_pdf_fd_new(fontname,subset_tag,cid_registry,cid_ordering,cid_supplement,panose)
-static EMB_PDF_FONTDESCR *emb_pdf_fd_new(const char *fontname,
- const char *subset_tag,
- const char *cid_registry, // or supplement==-1
- const char *cid_ordering, // or supplement==-1
- int cid_supplement) // -1 for non-cid
+
+// {{{ static EMB_PDF_FONTDESCR *
+// emb_pdf_fd_new(fontname, subset_tag, cid_registry, cid_ordering,
+// cid_supplement, panose)
+
+static EMB_PDF_FONTDESCR *
+emb_pdf_fd_new(const char *fontname,
+ const char *subset_tag,
+ const char *cid_registry, // or supplement==-1
+ const char *cid_ordering, // or supplement==-1
+ int cid_supplement) // -1 for non-cid
{
DEBUG_assert(fontname);
EMB_PDF_FONTDESCR *ret;
- int len=sizeof(EMB_PDF_FONTDESCR);
- if (subset_tag) {
- DEBUG_assert(strlen(subset_tag)==6);
- len+=7;
+ int len = sizeof(EMB_PDF_FONTDESCR);
+ if (subset_tag)
+ {
+ DEBUG_assert(strlen(subset_tag) == 6);
+ len += 7;
}
- len+=strlen(fontname)+1;
- if (cid_supplement>=0) { // cid font
- len+=12; // space for panose
+ len += strlen(fontname) + 1;
+ if (cid_supplement >= 0)
+ { // cid font
+ len += 12; // space for panose
DEBUG_assert(cid_registry);
DEBUG_assert(cid_ordering);
- len+=strlen(cid_registry)+1;
- len+=strlen(cid_ordering)+1;
+ len += strlen(cid_registry) + 1;
+ len += strlen(cid_ordering) + 1;
}
- ret=calloc(1,len);
- if (!ret) {
+ ret = calloc(1, len);
+ if (!ret)
+ {
fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
DEBUG_assert(0);
- return NULL;
+ return (NULL);
}
// now fill the struct
- len=0;
- if (cid_supplement>=0) { // free space for panose is at beginning
- len+=12;
- }
- ret->fontname=ret->data+len;
- len+=strlen(fontname)+1;
- if (subset_tag) {
+ len = 0;
+ if (cid_supplement >= 0) // free space for panose is at beginning
+ len += 12;
+ ret->fontname = ret->data + len;
+ len += strlen(fontname) + 1;
+ if (subset_tag)
+ {
snprintf(ret->fontname, 6, "%s", subset_tag);
- ret->fontname[6]='+';
- strcpy(ret->fontname+7,fontname);
- len+=7;
- } else {
- strcpy(ret->fontname,fontname);
+ ret->fontname[6] = '+';
+ strcpy(ret->fontname + 7, fontname);
+ len += 7;
+ }
+ else
+ {
+ strcpy(ret->fontname, fontname);
}
- ret->italicAngle=90;
- if (cid_supplement>=0) {
- ret->registry=ret->data+len;
- strcpy(ret->registry,cid_registry);
- len+=strlen(cid_registry)+1;
-
- ret->ordering=ret->data+len;
- strcpy(ret->ordering,cid_ordering);
- len+=strlen(cid_registry)+1;
+ ret->italicAngle = 90;
+ if (cid_supplement >= 0)
+ {
+ ret->registry = ret->data + len;
+ strcpy(ret->registry, cid_registry);
+ len += strlen(cid_registry) + 1;
+
+ ret->ordering = ret->data + len;
+ strcpy(ret->ordering, cid_ordering);
+ len += strlen(cid_registry) + 1;
}
- ret->supplement=cid_supplement;
+ ret->supplement = cid_supplement;
- return ret;
+ return (ret);
}
// }}}
-EMB_PDF_FONTDESCR *emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ - to be freed by user
+
+EMB_PDF_FONTDESCR *
+emb_pdf_fontdescr(EMB_PARAMS *emb) // {{{ - to be freed by user
{
DEBUG_assert(emb);
- const char *subset_tag=NULL;
+ const char *subset_tag = NULL;
// {{{ generate pdf subtag
- static unsigned int rands=0;
- if (!rands) {
- rands=time(NULL);
- }
+ static unsigned int rands = 0;
+ if (!rands)
+ rands = time(NULL);
char subtag[7];
- subtag[6]=0;
- if (emb->plan&EMB_A_SUBSET) {
+ subtag[6] = 0;
+ if (emb->plan & EMB_A_SUBSET)
+ {
int iA;
- for (iA=0;iA<6;iA++) {
- const int x=(int)(26.0*(rand_r(&rands)/(RAND_MAX+1.0)));
- subtag[iA]='A'+x;
+ for (iA = 0; iA < 6; iA ++)
+ {
+ const int x = (int)(26.0 * (rand_r(&rands) / (RAND_MAX + 1.0)));
+ subtag[iA] = 'A' + x;
}
- subset_tag=subtag;
+ subset_tag = subtag;
}
// }}}
- const char *fontname=NULL;
- if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) { // TODO? use fontinfo from CFF when outtype==CFT, etc.?
+ const char *fontname = NULL;
+ if ((emb->intype == EMB_FMT_TTF) || (emb->intype == EMB_FMT_OTF))
+ { // TODO? use fontinfo from CFF when outtype==CFT, etc.?
DEBUG_assert(emb->font->sfnt);
- fontname=emb_otf_get_fontname(emb->font->sfnt);
- } else if (emb->outtype==EMB_FMT_STDFONT) {
- return NULL;
- } else {
- fprintf(stderr,"NOT IMPLEMENTED\n");
+ fontname = emb_otf_get_fontname(emb->font->sfnt);
+ }
+ else if (emb->outtype == EMB_FMT_STDFONT)
+ return (NULL);
+ else
+ {
+ fprintf(stderr, "NOT IMPLEMENTED\n");
DEBUG_assert(0);
- return NULL;
+ return (NULL);
}
EMB_PDF_FONTDESCR *ret;
- if (emb->plan&EMB_A_MULTIBYTE) { // multibyte
- ret=emb_pdf_fd_new(fontname,subset_tag,"Adobe","Identity",0); // TODO other /ROS ?
- } else {
- ret=emb_pdf_fd_new(fontname,subset_tag,NULL,NULL,-1);
- }
- if (!ret) {
- return NULL;
- }
-
- if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) {
- emb_otf_get_pdf_fontdescr(emb->font->sfnt,ret);
- } else {
+ if (emb->plan & EMB_A_MULTIBYTE) // multibyte
+ ret = emb_pdf_fd_new(fontname, subset_tag, "Adobe", "Identity", 0);
+ // TODO other /ROS ?
+ else
+ ret = emb_pdf_fd_new(fontname, subset_tag, NULL, NULL, -1);
+ if (!ret)
+ return (NULL);
+
+ if ((emb->intype == EMB_FMT_TTF) || (emb->intype == EMB_FMT_OTF))
+ emb_otf_get_pdf_fontdescr(emb->font->sfnt, ret);
+ else
DEBUG_assert(0);
- }
- return ret;
+ return (ret);
}
// }}}
-EMB_PDF_FONTWIDTHS *emb_pdf_fw_new(int datasize) // {{{
+
+EMB_PDF_FONTWIDTHS *
+emb_pdf_fw_new(int datasize) // {{{
{
- DEBUG_assert(datasize>=0);
- EMB_PDF_FONTWIDTHS *ret=calloc(1,sizeof(EMB_PDF_FONTWIDTHS)+datasize*sizeof(int));
- if (!ret) {
+ DEBUG_assert(datasize >= 0);
+ EMB_PDF_FONTWIDTHS *ret =
+ calloc(1, sizeof(EMB_PDF_FONTWIDTHS) + datasize * sizeof(int));
+ if (!ret)
+ {
fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
DEBUG_assert(0);
- return NULL;
+ return (NULL);
}
- return ret;
+ return (ret);
}
// }}}
-// if default_width==-1: default_width will be estimated
-EMB_PDF_FONTWIDTHS *emb_pdf_fw_cidwidths(const BITSET glyphs,int len,int default_width,int (*getGlyphWidth)(void *context,int gid),void *context) // {{{ glyphs==NULL -> output all
+
+// if default_width == -1: default_width will be estimated
+
+EMB_PDF_FONTWIDTHS *
+emb_pdf_fw_cidwidths(const BITSET glyphs,
+ int len,
+ int default_width,
+ int (*getGlyphWidth)(void *context, int gid),
+ void *context) // {{{ glyphs == NULL -> output all
{
DEBUG_assert(getGlyphWidth);
- FREQUENT *freq=NULL;
- if (default_width<0) {
- freq=frequent_new(3);
- }
+ FREQUENT *freq = NULL;
+ if (default_width < 0)
+ freq = frequent_new(3);
- int iA,b,c;
- int size=0,in_region=0; // current number of elements in after region start
+ int iA, b, c;
+ int size = 0,
+ in_region = 0; // current number of elements in after region start
// first pass: find continuous regions, calculate needed size, estimate dw
- for (iA=0,b=0,c=1;iA<len;iA++,c<<=1) {
- if (!c) {
- b++;
- c=1;
+ for (iA = 0, b = 0, c = 1; iA < len; iA ++, c <<= 1)
+ {
+ if (!c)
+ {
+ b ++;
+ c = 1;
}
- if ( (!glyphs)||(glyphs[b]&c) ) {
- if (freq) {
- const int w=(*getGlyphWidth)(context,iA);
- frequent_add(freq,w);
+ if ((!glyphs) || (glyphs[b] & c))
+ {
+ if (freq)
+ {
+ const int w = (*getGlyphWidth)(context, iA);
+ frequent_add(freq, w);
}
- if (in_region) {
- in_region++;
- } else { // start new region
- size+=2; // len c
+ if (in_region)
+ in_region ++;
+ else
+ {
+ // start new region
+ size += 2; // len c
in_region=1;
}
- } else { // region end
- size+=in_region;
- in_region=0;
+ }
+ else
+ {
+ // region end
+ size += in_region;
+ in_region = 0;
}
}
- size+=in_region;
+ size += in_region;
- if (freq) {
- default_width=frequent_get(freq,0);
+ if (freq)
+ {
+ default_width = frequent_get(freq, 0);
free(freq);
}
- DEBUG_assert(default_width>0);
+ DEBUG_assert(default_width > 0);
// now create the array
- EMB_PDF_FONTWIDTHS *ret=emb_pdf_fw_new(size+1);
- if (!ret) {
- return NULL;
- }
- ret->default_width=default_width;
- ret->warray=ret->data;
+ EMB_PDF_FONTWIDTHS *ret = emb_pdf_fw_new(size + 1);
+ if (!ret)
+ return (NULL);
+ ret->default_width = default_width;
+ ret->warray = ret->data;
// second pass
- in_region=0;
- size=0;
- int *rlen=0; // position of current len field (only valid if in_region!=0)
- for (iA=0,b=0,c=1;iA<len;iA++,c<<=1) {
- if (!c) {
- b++;
- c=1;
+ in_region = 0;
+ size = 0;
+ int *rlen = 0; // position of current len field (only valid if in_region != 0)
+ for (iA = 0, b = 0, c = 1; iA < len; iA ++, c <<= 1)
+ {
+ if (!c)
+ {
+ b ++;
+ c = 1;
}
- if ( (!glyphs)||(glyphs[b]&c) ) {
- const int w=(*getGlyphWidth)(context,iA);
- if (in_region>0) { // in array region
- if ( (w==default_width)&&(ret->warray[size-1]==default_width) ) { // omit this and prev entry
- size--;
- *rlen=in_region-1; // !=0, as it does not start with >default_width
- in_region=0; // end region, immediate restart will take just the same amount of space
- } else if ( (in_region>=4)&&
- (ret->warray[size-1]==w)&&(ret->warray[size-2]==w)&&
- (ret->warray[size-3]==w)&&(ret->warray[size-4]==w) ) {
- // five in a row. c1 c2 w [l c] is equally short and can be extended (-len c1 w) [w/ cost of array-region restart]
- if (in_region==4) { // completely replace
- size-=6;
- } else { // first end previous region
- size-=4;
- *rlen=in_region-4;
+ if ((!glyphs) || (glyphs[b] & c))
+ {
+ const int w = (*getGlyphWidth)(context, iA);
+ if (in_region > 0)
+ {
+ // in array region
+ if ((w == default_width) && (ret->warray[size - 1] == default_width))
+ {
+ // omit this and prev entry
+ size --;
+ *rlen = in_region - 1; // !=0, as it does not start
+ // with > default_width
+ in_region = 0; // end region, immediate restart will take just the
+ // same amount of space
+ }
+ else if ((in_region >= 4) &&
+ (ret->warray[size - 1] == w) && (ret->warray[size - 2] == w) &&
+ (ret->warray[size - 3] == w) && (ret->warray[size - 4] == w))
+ {
+ // five in a row. c1 c2 w [l c] is equally short and can be extended
+ // (-len c1 w) [w/ cost of array-region restart]
+ if (in_region == 4) // completely replace
+ size -= 6;
+ else
+ {
+ // first end previous region
+ size -= 4;
+ *rlen = in_region - 4;
}
- in_region=-4; // start range region instead
- rlen=&ret->warray[size++];
- ret->warray[size++]=iA-4;
- ret->warray[size++]=w;
- } else { // just add
- in_region++;
- ret->warray[size++]=w;
+ in_region =- 4; // start range region instead
+ rlen = &ret->warray[size++];
+ ret->warray[size ++] = iA - 4;
+ ret->warray[size ++] = w;
+ }
+ else
+ {
+ // just add
+ in_region ++;
+ ret->warray[size ++] = w;
}
continue;
- } else if (in_region<0) { // in range region
- if (ret->warray[size-1]==w) {
- in_region--; // just add
+ }
+ else if (in_region < 0)
+ {
+ // in range region
+ if (ret->warray[size - 1] == w)
+ {
+ in_region --; // just add
continue;
}
- *rlen=in_region; // end
- in_region=0;
+ *rlen = in_region; // end
+ in_region = 0;
}
- if (w!=default_width) { // start new array region
- in_region=1;
- rlen=&ret->warray[size++];
- ret->warray[size++]=iA; // c
- ret->warray[size++]=w;
+ if (w != default_width)
+ {
+ // start new array region
+ in_region = 1;
+ rlen = &ret->warray[size ++];
+ ret->warray[size ++] = iA; // c
+ ret->warray[size ++] = w;
}
- } else if (in_region) {
- // TODO? no need to stop range region? } else if (in_region<0) { inregion--; }
- *rlen=in_region;
- in_region=0;
+ }
+ else if (in_region)
+ {
+ // TODO? no need to stop range region?
+ // } else if (in_region<0) { inregion--; }
+ *rlen = in_region;
+ in_region = 0;
}
}
- if (in_region) {
- *rlen=in_region;
- }
- ret->warray[size]=0; // terminator
- return ret;
+ if (in_region)
+ *rlen = in_region;
+ ret->warray[size] = 0; // terminator
+ return (ret);
}
// }}}
-// TODO: encoding into EMB_PARAMS (emb_new_enc(...,encoding,len ,to_unicode));
-// -> will then change interpretation of BITSET...(?really?); can we allow dynamic encoding map generation?
+
+// TODO: encoding into EMB_PARAMS (emb_new_enc(..., encoding, len, to_unicode));
+// -> will then change interpretation of BITSET...(?really?); can we allow
+// dynamic encoding map generation?
// -> encoding has a "len"; len<256
-EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
+
+EMB_PDF_FONTWIDTHS *
+emb_pdf_fontwidths(EMB_PARAMS *emb) // {{{
{
DEBUG_assert(emb);
- if ( (emb->intype==EMB_FMT_TTF)||(emb->intype==EMB_FMT_OTF) ) {
+ if ((emb->intype == EMB_FMT_TTF) || (emb->intype == EMB_FMT_OTF))
+ {
DEBUG_assert(emb->font->sfnt);
- if (emb->plan&EMB_A_MULTIBYTE) {
- return emb_otf_get_pdf_cidwidths(emb->font->sfnt,emb->subset);
- } else {
- return emb_otf_get_pdf_widths(emb->font->sfnt,/*encoding*/NULL,emb->font->sfnt->numGlyphs,emb->subset); // TODO: encoding
- }
- } else {
+ if (emb->plan & EMB_A_MULTIBYTE)
+ return (emb_otf_get_pdf_cidwidths(emb->font->sfnt,emb->subset));
+ else
+ return (emb_otf_get_pdf_widths(emb->font->sfnt, /*encoding*/NULL,
+ emb->font->sfnt->numGlyphs,
+ emb->subset)); // TODO: encoding
+ }
+ else
+ {
fprintf(stderr,"NOT IMPLEMENTED\n");
DEBUG_assert(0);
- return NULL;
+ return (NULL);
}
}
// }}}
-/*** PDF out stuff ***/
+
+// *** PDF out stuff ***
#include "dynstring-private.h"
#define NEXT /* {{{ */ \
- if ( (len<0)||(len>=size) ) { \
+ if ((len < 0) || (len >= size)) \
+ { \
DEBUG_assert(0); \
free(ret); \
- return NULL; \
+ return (NULL); \
} \
- pos+=len; \
- size-=len; /* }}} */
+ pos += len; \
+ size -= len; /* }}} */
+
-// TODO? /CIDSet TODO... /FontFamily /FontStretch /FontWeight (PDF1.5?) would be nice...
-char *emb_pdf_simple_fontdescr(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,int fontfile_obj_ref) // {{{ - to be freed by user
+// TODO? /CIDSet TODO... /FontFamily /FontStretch /FontWeight (PDF1.5?)
+// would be nice...
+
+char *
+emb_pdf_simple_fontdescr(EMB_PARAMS *emb,
+ EMB_PDF_FONTDESCR *fdes,
+ int fontfile_obj_ref) // {{{ - to be freed by user
{
DEBUG_assert(emb);
DEBUG_assert(fdes);
- char *ret=NULL,*pos;
- int len,size;
+ char *ret = NULL, *pos;
+ int len, size;
- size=300;
- pos=ret=malloc(size);
- if (!ret) {
+ size = 300;
+ pos = ret = malloc(size);
+ if (!ret)
+ {
fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- return NULL;
+ return (NULL);
}
- len=snprintf(pos,size,
- "<</Type /FontDescriptor\n"
- " /FontName /%s\n" // TODO? handle quoting in struct?
- " /Flags %d\n"
- " /ItalicAngle %d\n",
- emb_pdf_escape_name(fdes->fontname,-1),
- fdes->flags,
- fdes->italicAngle);
+ len = snprintf(pos, size,
+ "<</Type /FontDescriptor\n"
+ " /FontName /%s\n" // TODO? handle quoting in struct?
+ " /Flags %d\n"
+ " /ItalicAngle %d\n",
+ emb_pdf_escape_name(fdes->fontname, -1),
+ fdes->flags,
+ fdes->italicAngle);
NEXT;
- if (1) { // TODO type!=EMB_PDF_TYPE3
- len=snprintf(pos,size,
- " /FontBBox [%d %d %d %d]\n"
- " /Ascent %d\n"
- " /Descent %d\n"
- " /CapHeight %d\n" // if font has Latin chars
- " /StemV %d\n",
- fdes->bbxmin,fdes->bbymin,fdes->bbxmax,fdes->bbymax,
- fdes->ascent,
- fdes->descent,
- fdes->capHeight,
- fdes->stemV);
+ if (1)
+ {
+ // TODO type!=EMB_PDF_TYPE3
+ len = snprintf(pos, size,
+ " /FontBBox [%d %d %d %d]\n"
+ " /Ascent %d\n"
+ " /Descent %d\n"
+ " /CapHeight %d\n" // if font has Latin chars
+ " /StemV %d\n",
+ fdes->bbxmin, fdes->bbymin, fdes->bbxmax, fdes->bbymax,
+ fdes->ascent,
+ fdes->descent,
+ fdes->capHeight,
+ fdes->stemV);
NEXT;
}
- if (fdes->xHeight) {
- len=snprintf(pos,size," /XHeight %d\n",fdes->xHeight);
+ if (fdes->xHeight)
+ {
+ len = snprintf(pos, size, " /XHeight %d\n", fdes->xHeight);
NEXT;
}
- if (fdes->avgWidth) {
- len=snprintf(pos,size," /AvgWidth %d\n",fdes->avgWidth);
+ if (fdes->avgWidth)
+ {
+ len = snprintf(pos, size, " /AvgWidth %d\n", fdes->avgWidth);
NEXT;
}
- if (fdes->panose) {
+ if (fdes->panose)
+ {
int iA;
- len=snprintf(pos,size," /Style << /Panose <");
+ len = snprintf(pos, size, " /Style << /Panose <");
NEXT;
- if (size<30) {
+ if (size < 30)
+ {
DEBUG_assert(0);
free(ret);
- return NULL;
+ return (NULL);
}
- for (iA=0;iA<12;iA++) {
- snprintf(pos+iA*2,size-iA*2,"%02x",fdes->panose[iA]);
- }
- size-=24;
- pos+=24;
- len=snprintf(pos,size,"> >>\n");
+ for (iA = 0; iA < 12; iA ++)
+ snprintf(pos + iA * 2, size - iA * 2, "%02x", fdes->panose[iA]);
+ size -= 24;
+ pos += 24;
+ len = snprintf(pos, size, "> >>\n");
NEXT;
}
// TODO (for Type0)? CIDSet -> simply our glyphs BITSET (ok. endianess?)
- len=snprintf(pos,size,
- " /%s %d 0 R\n"
- ">>\n",
- emb_pdf_get_fontfile_key(emb),
- fontfile_obj_ref);
+ len = snprintf(pos, size,
+ " /%s %d 0 R\n"
+ ">>\n",
+ emb_pdf_get_fontfile_key(emb),
+ fontfile_obj_ref);
NEXT;
- return ret;
+ return (ret);
}
// }}}
-char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWIDTHS *fwid,int fontdescr_obj_ref) // {{{ - to be freed by user
+
+char *
+emb_pdf_simple_font(EMB_PARAMS *emb,
+ EMB_PDF_FONTDESCR *fdes,
+ EMB_PDF_FONTWIDTHS *fwid,
+ int fontdescr_obj_ref) // {{{ - to be freed by user
{
DEBUG_assert(emb);
DEBUG_assert(fdes);
DEBUG_assert(fwid);
- int iA,iB;
+ int iA, iB;
DYN_STRING ret;
- if (dyn_init(&ret,500)==-1) {
- return NULL;
- }
+ if (dyn_init(&ret, 500) == -1)
+ return (NULL);
- dyn_printf(&ret,"<</Type /Font\n"
- " /Subtype /%s\n"
- " /BaseFont /%s\n"
- " /FontDescriptor %d 0 R\n",
- emb_pdf_get_font_subtype(emb),
- emb_pdf_escape_name(fdes->fontname,-1),
- fontdescr_obj_ref);
+ dyn_printf(&ret, "<</Type /Font\n"
+ " /Subtype /%s\n"
+ " /BaseFont /%s\n"
+ " /FontDescriptor %d 0 R\n",
+ emb_pdf_get_font_subtype(emb),
+ emb_pdf_escape_name(fdes->fontname,-1),
+ fontdescr_obj_ref);
- if (emb->plan&EMB_A_MULTIBYTE) { // multibyte
+ if (emb->plan & EMB_A_MULTIBYTE)
+ {
+ // multibyte
DEBUG_assert(fwid->warray);
- dyn_printf(&ret," /CIDSystemInfo <<\n"
- " /Registry (%s)\n"
- " /Ordering (%s)\n"
- " /Supplement %d\n"
- " >>\n"
- " /DW %d\n",
-// " /CIDToGIDMap /Id...\n" // TrueType only, default /Identity [optional? which PDF version says what?]
- fdes->registry,
- fdes->ordering,
- fdes->supplement,
- fwid->default_width);
-
- if (fwid->warray[0]) {
- dyn_printf(&ret," /W [");
- for (iA=0;fwid->warray[iA];) {
- if (fwid->warray[iA]<0) { // c1 (c1-len) w
- dyn_printf(&ret," %d %d %d",
- fwid->warray[iA+1],
- fwid->warray[iA+1]-fwid->warray[iA],
- fwid->warray[iA+2]);
- iA+=3;
- } else { // c [w ... w]
- iB=fwid->warray[iA++]; // len
- dyn_printf(&ret," %d [",fwid->warray[iA++]); // c
- for (;iB>0;iB--) {
- dyn_printf(&ret," %d",fwid->warray[iA++]);
- }
- dyn_printf(&ret,"]");
+ dyn_printf(&ret, " /CIDSystemInfo <<\n"
+ " /Registry (%s)\n"
+ " /Ordering (%s)\n"
+ " /Supplement %d\n"
+ " >>\n"
+ " /DW %d\n",
+// " /CIDToGIDMap /Id...\n" // TrueType only, default
+ // Identity [optional? which
+ // PDF version says what?]
+ fdes->registry,
+ fdes->ordering,
+ fdes->supplement,
+ fwid->default_width);
+
+ if (fwid->warray[0])
+ {
+ dyn_printf(&ret, " /W [");
+ for (iA = 0; fwid->warray[iA];)
+ {
+ if (fwid->warray[iA] < 0)
+ {
+ // c1 (c1-len) w
+ dyn_printf(&ret, " %d %d %d",
+ fwid->warray[iA + 1],
+ fwid->warray[iA + 1] - fwid->warray[iA],
+ fwid->warray[iA + 2]);
+ iA += 3;
+ }
+ else
+ {
+ // c [w ... w]
+ iB = fwid->warray[iA ++]; // len
+ dyn_printf(&ret, " %d [", fwid->warray[iA ++]); // c
+ for (; iB > 0; iB --)
+ dyn_printf(&ret, " %d", fwid->warray[iA ++]);
+ dyn_printf(&ret, "]");
}
}
- dyn_printf(&ret,"]\n");
- }
- } else { // "not std14"
- DEBUG_assert(fwid->widths);
- dyn_printf(&ret,
- " /Encoding /MacRomanEncoding\n" // optional; TODO!!!!!
-// " /ToUnicode ?\n" // optional
- " /FirstChar %d\n"
- " /LastChar %d\n"
- " /Widths [",
- fwid->first,
- fwid->last);
- for (iA=0,iB=fwid->first;iB<=fwid->last;iA++,iB++) {
- dyn_printf(&ret," %d",fwid->widths[iA]);
+ dyn_printf(&ret, "]\n");
}
- dyn_printf(&ret,"]\n");
}
- dyn_printf(&ret,">>\n");
- if (ret.len==-1) {
+ else
+ {
+ // "not std14"
+ DEBUG_assert(fwid->widths);
+ dyn_printf(&ret, " /Encoding /MacRomanEncoding\n" // optional; TODO!!!!!
+// " /ToUnicode ?\n" // optional
+ " /FirstChar %d\n"
+ " /LastChar %d\n"
+ " /Widths [",
+ fwid->first,
+ fwid->last);
+ for (iA = 0, iB = fwid->first; iB <= fwid->last; iA ++, iB ++)
+ dyn_printf(&ret, " %d", fwid->widths[iA]);
+ dyn_printf(&ret, "]\n");
+ }
+ dyn_printf(&ret, ">>\n");
+ if (ret.len == -1)
+ {
dyn_free(&ret);
DEBUG_assert(0);
- return NULL;
+ return (NULL);
}
- return ret.buf;
+ return (ret.buf);
}
// }}}
-// TODO? + encoding as param? TODO + ToUnicode cmap => we need another struct EMB_PDF_FONTMAP
-// (TODO?? fontname here without subset-tag [_some_ pdfs out there seem to be that way])
+
+// TODO? + encoding as param? TODO + ToUnicode cmap
+// => we need another struct EMB_PDF_FONTMAP
+// (TODO?? fontname here without subset-tag [_some_ pdfs out there seem
+// to be that way])
// TODO? don't do the CidType0 check here?
// NOTE: this is _additionally_ to emb_pdf_simple_font()!
-char *emb_pdf_simple_cidfont(EMB_PARAMS *emb,const char *fontname,int descendant_obj_ref) // {{{ - to be freed by user
+
+char *
+emb_pdf_simple_cidfont(EMB_PARAMS *emb,
+ const char *fontname,
+ int descendant_obj_ref) // {{{ - to be freed by user
{
DEBUG_assert(emb);
DEBUG_assert(fontname);
- char *ret=NULL,*pos;
- int len,size;
-
- size=250;
- pos=ret=malloc(size);
- if (!ret) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- return NULL;
- }
- // for CFF: one of:
- // UniGB-UCS2-H, UniCNS-UCS2-H, UniJIS-UCS2-H, UniKS-UCS2-H
- const char *encoding="Identity-H",*addenc="-";
- if (emb->outtype==EMB_FMT_TTF) { // !=CidType0
- addenc="";
- }
-
- len=snprintf(pos,size,
- "<</Type /Font\n"
- " /Subtype /Type0\n"
- " /BaseFont /%s%s%s\n"
- " /Encoding /%s\n"
- " /DescendantFonts [%d 0 R]\n",
+ char *ret = NULL, *pos;
+ int len, size;
+
+ size = 250;
+ pos = ret = malloc(size);
+ if (!ret)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
+ return (NULL);
+ }
+ // for CFF: one of:
+ // UniGB-UCS2-H, UniCNS-UCS2-H, UniJIS-UCS2-H, UniKS-UCS2-H
+ const char *encoding = "Identity-H", *addenc = "-";
+ if (emb->outtype == EMB_FMT_TTF)
+ // !=CidType0
+ addenc = "";
+
+ len = snprintf(pos, size,
+ "<</Type /Font\n"
+ " /Subtype /Type0\n"
+ " /BaseFont /%s%s%s\n"
+ " /Encoding /%s\n"
+ " /DescendantFonts [%d 0 R]\n",
// " /ToUnicode ?\n" // TODO
- emb_pdf_escape_name(fontname,-1),
- addenc,((addenc[0])?encoding:""),
- encoding,
- descendant_obj_ref);
+ emb_pdf_escape_name(fontname, -1),
+ addenc, ((addenc[0]) ? encoding : ""),
+ encoding,
+ descendant_obj_ref);
NEXT;
- len=snprintf(pos,size,">>\n");
+ len = snprintf(pos, size, ">>\n");
NEXT;
- return ret;
+ return (ret);
}
// }}}
-char *emb_pdf_simple_stdfont(EMB_PARAMS *emb) // {{{ - to be freed by user
+
+char *
+emb_pdf_simple_stdfont(EMB_PARAMS *emb) // {{{ - to be freed by user
{
DEBUG_assert(emb);
DEBUG_assert(emb->font->stdname);
- char *ret=NULL,*pos;
- int len,size;
+ char *ret = NULL, *pos;
+ int len, size;
size=300;
- pos=ret=malloc(size);
- if (!ret) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- return NULL;
- }
-
- len=snprintf(pos,size,
- "<</Type/Font\n"
- " /Subtype /Type1\n"
- " /BaseFont /%s\n"
- ">>\n",
+ pos = ret = malloc(size);
+ if (!ret)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
+ return (NULL);
+ }
+
+ len = snprintf(pos, size,
+ "<</Type/Font\n"
+ " /Subtype /Type1\n"
+ " /BaseFont /%s\n"
+ ">>\n",
// emb_pdf_get_font_subtype(emb),
- emb->font->stdname);
+ emb->font->stdname);
NEXT;
- return ret;
+ return (ret);
}
// }}}
-#undef NEXT
+
+#undef NEXT
-#ifndef EMBED_PDF_H
-#define EMBED_PDF_H
+#ifndef _FONTEMBED_EMBED_PDF_H_
+#define _FONTEMBED_EMBED_PDF_H_
-// all the necessary information for pdf font embedding
-typedef struct {
+
+// all the necessary information for PDF font embedding
+typedef struct
+{
char *fontname;
unsigned int flags;
- // for the following: 0=not set/invalid
- int bbxmin,bbymin,bbxmax,bbymax;
- int italicAngle; // >=90: not set/invalid
+ // for the following: 0 = not set/invalid
+ int bbxmin, bbymin, bbxmax, bbymax;
+ int italicAngle; // >= 90: not set/invalid
int ascent;
int descent;
int capHeight;
int stemV;
- // optional, default=0:
+ // optional, default = 0:
int xHeight;
int avgWidth;
// CID-additions:
char *panose; // 12 bytes
- char *registry,*ordering;
+ char *registry, *ordering;
int supplement;
- char data[1]; // used for storing e.g. >fontname
+ char data[1]; // used for storing e.g. > fontname
} EMB_PDF_FONTDESCR;
-typedef struct {
+typedef struct
+{
// normal font
- int first,last;
+ int first, last;
int *widths;
// multibyte font
int default_width;
- int *warray; // format: (len c w ... w)* if (len<0) { c1 (c2=c1+(-len)) w } else { c w[len] }, terminated by len==0
+ int *warray; // format: (len c w ... w)*
+ // if (len < 0) { c1 (c2 = c1 + (-len)) w } else { c w[len] },
+ // terminated by len == 0
int data[1];
} EMB_PDF_FONTWIDTHS;
+
const char *emb_pdf_get_font_subtype(EMB_PARAMS *emb);
const char *emb_pdf_get_fontfile_key(EMB_PARAMS *emb);
const char *emb_pdf_get_fontfile_subtype(EMB_PARAMS *emb);
EMB_PDF_FONTWIDTHS *emb_pdf_fontwidths(EMB_PARAMS *emb);
/** TODO elsewhere **/
-char *emb_pdf_simple_fontdescr(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,int fontfile_obj_ref);
-char *emb_pdf_simple_font(EMB_PARAMS *emb,EMB_PDF_FONTDESCR *fdes,EMB_PDF_FONTWIDTHS *fwid,int fontdescr_obj_ref);
-char *emb_pdf_simple_cidfont(EMB_PARAMS *emb,const char *fontname,int descendant_obj_ref);
+char *emb_pdf_simple_fontdescr(EMB_PARAMS *emb, EMB_PDF_FONTDESCR *fdes,
+ int fontfile_obj_ref);
+char *emb_pdf_simple_font(EMB_PARAMS *emb, EMB_PDF_FONTDESCR *fdes,
+ EMB_PDF_FONTWIDTHS *fwid, int fontdescr_obj_ref);
+char *emb_pdf_simple_cidfont(EMB_PARAMS *emb, const char *fontname,
+ int descendant_obj_ref);
char *emb_pdf_simple_stdfont(EMB_PARAMS *emb);
-#endif
+#endif // !_FONTEMBED_EMBED_PDF_H_
-#ifndef EMBED_SFNT_INT_H
-#define EMBED_SFNT_INT_H
+#ifndef _FONTEMBED_EMBED_SFNT_INT_H_
+#define _FONTEMBED_EMBED_SFNT_INT_H_
#include "sfnt.h"
#include "embed-pdf.h"
+
EMB_RIGHT_TYPE emb_otf_get_rights(OTF_FILE *otf);
// NOTE: statically allocated buffer
const char *emb_otf_get_fontname(OTF_FILE *otf);
-void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret);
-EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_widths(OTF_FILE *otf,const unsigned short *encoding,int len,const BITSET glyphs);
-EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_cidwidths(OTF_FILE *otf,const BITSET glyph);
+void emb_otf_get_pdf_fontdescr(OTF_FILE *otf, EMB_PDF_FONTDESCR *ret);
+EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_widths(OTF_FILE *otf,
+ const unsigned short *encoding,
+ int len, const BITSET glyphs);
+EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_cidwidths(OTF_FILE *otf,
+ const BITSET glyph);
-int emb_otf_ps(OTF_FILE *otf,unsigned short *encoding,int len,unsigned short *to_unicode,OUTPUT_FN output,void *context);
+int emb_otf_ps(OTF_FILE *otf, unsigned short *encoding, int len,
+ unsigned short *to_unicode, OUTPUT_FN output, void *context);
-#endif
+#endif // !_FONTEMBED_EMBED_SFNT_INT_H_
#include <stdlib.h>
#include <string.h>
-EMB_RIGHT_TYPE emb_otf_get_rights(OTF_FILE *otf) // {{{
+
+EMB_RIGHT_TYPE
+emb_otf_get_rights(OTF_FILE *otf) // {{{
{
- EMB_RIGHT_TYPE ret=EMB_RIGHT_FULL;
+ EMB_RIGHT_TYPE ret = EMB_RIGHT_FULL;
int len;
- char *os2=otf_get_table(otf,OTF_TAG('O','S','/','2'),&len);
- if (os2) {
- const unsigned short os2_version=get_USHORT(os2);
+ char *os2 = otf_get_table(otf, OTF_TAG('O', 'S', '/', '2'), &len);
+ if (os2)
+ {
+ const unsigned short os2_version = get_USHORT(os2);
// check len
- DEBUG_assert( (os2_version!=0x0000)||(len==78) );
- DEBUG_assert( (os2_version!=0x0001)||(len==86) );
- DEBUG_assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
- if (os2_version<=0x0004) {
+ DEBUG_assert((os2_version != 0x0000) || (len == 78));
+ DEBUG_assert((os2_version != 0x0001) || (len == 86));
+ DEBUG_assert((os2_version < 0x0002) || (os2_version > 0x0004) ||
+ (len == 96));
+ if (os2_version <= 0x0004)
+ {
// get rights
- unsigned short fsType=get_USHORT(os2+8);
+ unsigned short fsType = get_USHORT(os2 + 8);
// from Adobe's Fontpolicies_v9.pdf, pg 13:
- if (fsType==0x0002) {
- ret=EMB_RIGHT_NONE;
- } else {
- ret=fsType&0x0300; // EMB_RIGHT_BITMAPONLY, EMB_RIGHT_NO_SUBSET
- if ((fsType&0x000c)==0x0004) {
- ret|=EMB_RIGHT_READONLY;
- }
+ if (fsType == 0x0002)
+ ret = EMB_RIGHT_NONE;
+ else
+ {
+ ret = fsType & 0x0300; // EMB_RIGHT_BITMAPONLY, EMB_RIGHT_NO_SUBSET
+ if ((fsType & 0x000c) == 0x0004)
+ ret |= EMB_RIGHT_READONLY;
}
}
free(os2);
}
- return ret;
+ return (ret);
}
// }}}
+
// NOTE: statically allocated buffer
-const char *emb_otf_get_fontname(OTF_FILE *otf) // {{{
+
+const char *
+emb_otf_get_fontname(OTF_FILE *otf) // {{{
{
static char fontname[64];
int len;
- const char *fname=otf_get_name(otf,3,1,0x409,6,&len); // microsoft
- if (fname) {
- int iA,iB=0;
- for (iA=0;(iA<63)&&(iA*2<len);iA++) {
- if ( (fname[2*iA]==0)&&
- (fname[2*iA+1]>=33)&&(fname[2*iA+1]<=126)&&
- (!strchr("[](){}<>/%",fname[iA*2+1])) ) {
- fontname[iB++]=fname[iA*2+1];
- }
+ const char *fname = otf_get_name(otf, 3, 1, 0x409, 6, &len); // Microsoft
+ if (fname)
+ {
+ int iA, iB = 0;
+ for (iA=0; (iA < 63) && (iA * 2 < len); iA ++)
+ {
+ if ((fname[2 * iA] == 0) &&
+ (fname[2 * iA + 1] >= 33) && (fname[2 * iA + 1] <= 126) &&
+ (!strchr("[](){}<>/%", fname[iA * 2 + 1])))
+ fontname[iB ++] = fname[iA * 2 + 1];
}
- fontname[iB]=0;
- } else if ((fname=otf_get_name(otf,1,0,0,6,&len))) { // mac
- int iA,iB=0;
- for (iA=0;(iA<63)&&(iA<len);iA++) {
- if ( (fname[iA]>=33)&&(fname[iA]<=126)&&
- (!strchr("[](){}<>/%",fname[iA])) ) {
- fontname[iB++]=fname[iA];
- }
+ fontname[iB] = 0;
+ }
+ else if ((fname = otf_get_name(otf, 1, 0, 0, 6, &len))) // Mac
+ {
+ int iA, iB = 0;
+ for (iA = 0; (iA < 63) && (iA < len); iA ++)
+ {
+ if ((fname[iA] >= 33) && (fname[iA] <= 126) &&
+ (!strchr("[](){}<>/%", fname[iA])))
+ fontname[iB ++] = fname[iA];
}
- fontname[iB]=0;
- } else {
- fontname[0]=0;
- }
- if (!*fontname) {
+ fontname[iB] = 0;
+ } else
+ fontname[0] = 0;
+
+ if (!*fontname)
// TODO construct a fontname, eg from */*/*/4
- fprintf(stderr,"WARNING: no fontName\n");
- }
- return fontname;
+ fprintf(stderr, "WARNING: no fontName\n");
+
+ return (fontname);
}
// }}}
+
// TODO? monospaced by actual glyph width?
// TODO? use PCLT table? (esp. CFF, as table dircouraged for glyf fonts)
-void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret) // {{{
+
+void
+emb_otf_get_pdf_fontdescr(OTF_FILE *otf,
+ EMB_PDF_FONTDESCR *ret) // {{{
{
int len;
// TODO
// ... fill in struct
- char *head=otf_get_table(otf,OTF_TAG('h','e','a','d'),&len);
+ char *head = otf_get_table(otf, OTF_TAG('h', 'e', 'a', 'd'), &len);
DEBUG_assert(head); // version is 1.0 from otf_load
- ret->bbxmin=get_SHORT(head+36)*1000/otf->unitsPerEm;
- ret->bbymin=get_SHORT(head+38)*1000/otf->unitsPerEm;
- ret->bbxmax=get_SHORT(head+40)*1000/otf->unitsPerEm;
- ret->bbymax=get_SHORT(head+42)*1000/otf->unitsPerEm;
- const int macStyle=get_USHORT(head+44);
+ ret->bbxmin = get_SHORT(head + 36) * 1000 / otf->unitsPerEm;
+ ret->bbymin = get_SHORT(head + 38) * 1000 / otf->unitsPerEm;
+ ret->bbxmax = get_SHORT(head + 40) * 1000 / otf->unitsPerEm;
+ ret->bbymax = get_SHORT(head + 42) * 1000 / otf->unitsPerEm;
+ const int macStyle = get_USHORT(head + 44);
free(head);
- char *post=otf_get_table(otf,OTF_TAG('p','o','s','t'),&len);
+ char *post = otf_get_table(otf, OTF_TAG('p', 'o', 's', 't'), &len);
DEBUG_assert(post);
- const unsigned int post_version=get_ULONG(post);
+ const unsigned int post_version = get_ULONG(post);
// check length
- DEBUG_assert( (post_version!=0x00010000)||(len==32) );
- DEBUG_assert( (post_version!=0x00020000)||(len>=34+2*otf->numGlyphs) );
- DEBUG_assert( (post_version!=0x00025000)||(len==35+otf->numGlyphs) );
- DEBUG_assert( (post_version!=0x00030000)||(len==32) );
- DEBUG_assert( (post_version!=0x00020000)||(get_USHORT(post+32)==otf->numGlyphs) ); // v4?
-// DEBUG_assert( (post_version==0x00030000)==(!!(otf->flags&OTF_F_FMT_CFF)) ); // ghostscript embedding does this..
+ DEBUG_assert((post_version != 0x00010000) || (len == 32));
+ DEBUG_assert((post_version != 0x00020000) ||
+ (len >= 34 + 2 * otf->numGlyphs));
+ DEBUG_assert((post_version != 0x00025000) || (len == 35 + otf->numGlyphs));
+ DEBUG_assert((post_version != 0x00030000) || (len == 32));
+ DEBUG_assert((post_version != 0x00020000) ||
+ (get_USHORT(post + 32) == otf->numGlyphs)); // v4?
+ // DEBUG_assert((post_version == 0x00030000) ==
+ // (!!(otf->flags&OTF_F_FMT_CFF)));
+ // // Ghostscript embedding does this..
// TODO: v4 (apple) : uint16 reencoding[numGlyphs]
- if ( (post_version==0x00010000)||
- (post_version==0x00020000)||
- (post_version==0x00025000)||
- (post_version==0x00030000)||
- (post_version==0x00040000) ) {
- ret->italicAngle=get_LONG(post+4)>>16;
- if (get_ULONG(post+12)>0) { // monospaced
- ret->flags|=1;
- }
- } else {
- fprintf(stderr,"WARNING: no italicAngle, no monospaced flag\n");
- }
+ if ((post_version == 0x00010000) ||
+ (post_version == 0x00020000) ||
+ (post_version == 0x00025000) ||
+ (post_version == 0x00030000) ||
+ (post_version == 0x00040000))
+ {
+ ret->italicAngle = get_LONG(post + 4) >> 16;
+ if (get_ULONG(post + 12) > 0) // monospaced
+ ret->flags |= 1;
+ }
+ else
+ fprintf(stderr, "WARNING: no italicAngle, no monospaced flag\n");
free(post);
- char *os2=otf_get_table(otf,OTF_TAG('O','S','/','2'),&len);
- if (os2) {
- const unsigned short os2_version=get_USHORT(os2);
+ char *os2 = otf_get_table(otf, OTF_TAG('O', 'S', '/', '2'), &len);
+ if (os2)
+ {
+ const unsigned short os2_version = get_USHORT(os2);
// check len
- DEBUG_assert( (os2_version!=0x0000)||(len==78) );
- DEBUG_assert( (os2_version!=0x0001)||(len==86) );
- DEBUG_assert( (os2_version<0x0002)||(os2_version>0x0004)||(len==96) );
- if (os2_version<=0x0004) {
-
+ DEBUG_assert((os2_version != 0x0000) || (len == 78));
+ DEBUG_assert((os2_version != 0x0001) || (len == 86));
+ DEBUG_assert((os2_version < 0x0002) || (os2_version > 0x0004) ||
+ (len == 96));
+ if (os2_version <= 0x0004)
+ {
// from PDF14Deltas.pdf, pg 113
- const int weightClass=get_USHORT(os2+4);
- ret->stemV=50+weightClass*weightClass/(65*65); // TODO, really bad
-//printf("a %d\n",weightClass);
-
- if (ret->supplement>=0) { // cid
- ret->panose=ret->data;
- memcpy(ret->panose,os2+30,12); // sFamilyClass + panose
- }
- const unsigned short fsSelection=get_USHORT(os2+62);
- if (fsSelection&0x01) { // italic
- ret->flags|=0x0040;
- }
- if ( (fsSelection&0x10)&&(weightClass>600) ) { // force bold
- ret->flags|=0x0400;
- }
- const unsigned char family_class=get_USHORT(os2+30)>>8;
- if (family_class==10) { // script
- ret->flags|=0x0008;
- }
- if (family_class!=8) { // not sans-serif
- ret->flags|=0x0002;
+ const int weightClass = get_USHORT(os2 + 4);
+ ret->stemV = 50 + weightClass * weightClass / (65 * 65);
+ // TODO, really bad
+ //printf("a %d\n", weightClass);
+ if (ret->supplement >= 0)
+ {
+ // cid
+ ret->panose = ret->data;
+ memcpy(ret->panose, os2 + 30, 12); // sFamilyClass + panose
}
-
- ret->avgWidth=get_SHORT(os2+2)*1000/otf->unitsPerEm;
- ret->ascent=get_SHORT(os2+68)*1000/otf->unitsPerEm;
- ret->descent=get_SHORT(os2+70)*1000/otf->unitsPerEm;
- if (os2_version>=0x0002) {
- ret->xHeight=get_SHORT(os2+86)*1000/otf->unitsPerEm;
- ret->capHeight=get_SHORT(os2+88)*1000/otf->unitsPerEm;
+ const unsigned short fsSelection = get_USHORT(os2 + 62);
+ if (fsSelection & 0x01)
+ // italic
+ ret->flags |= 0x0040;
+ if ((fsSelection & 0x10) && (weightClass > 600))
+ // force bold
+ ret->flags |= 0x0400;
+ const unsigned char family_class = get_USHORT(os2 + 30) >> 8;
+ if (family_class == 10)
+ // script
+ ret->flags |= 0x0008;
+ if (family_class != 8)
+ // not sans-serif
+ ret->flags |= 0x0002;
+
+ ret->avgWidth = get_SHORT(os2 + 2) * 1000 / otf->unitsPerEm;
+ ret->ascent = get_SHORT(os2 + 68) * 1000 / otf->unitsPerEm;
+ ret->descent = get_SHORT(os2 + 70) * 1000 / otf->unitsPerEm;
+ if (os2_version >= 0x0002)
+ {
+ ret->xHeight = get_SHORT(os2 + 86) * 1000 / otf->unitsPerEm;
+ ret->capHeight = get_SHORT(os2 + 88) * 1000 / otf->unitsPerEm;
} // else capHeight fixed later
- } else {
+ }
+ else
+ {
free(os2);
- os2=NULL;
+ os2 = NULL;
}
} else {
fprintf(stderr,"WARNING: no OS/2 table\n");
- // e.g. subsetted font from ghostscript // e.g. CFF
+ // e.g. Subsetted font from Ghostscript // e.g. CFF
}
- if (os2) {
+ if (os2)
free(os2);
- } else { // TODO (if(CFF))
- fprintf(stderr,"WARNING: no ascent/descent, capHeight, stemV, flags\n");
- if (macStyle&0x01) { // force bold - just do it on bold
- ret->flags|=0x0400;
- }
- if (macStyle&0x02) { // italic
- ret->flags|=0x0004;
- }
+ else
+ {
+ // TODO (if(CFF))
+ fprintf(stderr, "WARNING: no ascent/descent, capHeight, stemV, flags\n");
+ if (macStyle & 0x01) // force bold - just do it on bold
+ ret->flags |= 0x0400;
+ if (macStyle & 0x02) // italic
+ ret->flags |= 0x0004;
// ... flags TODO? (Serif, Script, Italic, AllCap,SmallCap, ForceBold)
}
-// ? maybe get ascent,descent,capHeight,xHeight,stemV directly from cff
+ // ? maybe get ascent, descent, capHeight, xHeight, stemV directly from cff
// Fallbacks
- if ( (!ret->ascent)||(!ret->descent) ) {
- char *hhea=otf_get_table(otf,OTF_TAG('h','h','e','a'),&len);
- if (hhea) {
- ret->ascent=get_SHORT(hhea+4)*1000/otf->unitsPerEm;
- ret->descent=get_SHORT(hhea+6)*1000/otf->unitsPerEm;
+ if ((!ret->ascent) || (!ret->descent))
+ {
+ char *hhea = otf_get_table(otf, OTF_TAG('h', 'h', 'e', 'a'), &len);
+ if (hhea)
+ {
+ ret->ascent = get_SHORT(hhea + 4) * 1000 / otf->unitsPerEm;
+ ret->descent = get_SHORT(hhea + 6) * 1000 / otf->unitsPerEm;
}
free(hhea);
}
- if (!ret->stemV) { // TODO? use name
- const unsigned short d_gid=otf_from_unicode(otf,'.');
- if (d_gid) { // stemV=bbox['.'].width;
- len=otf_get_glyph(otf,d_gid);
- DEBUG_assert(len>=10);
- ret->stemV=(get_SHORT(otf->gly+6)-get_SHORT(otf->gly+2))*1000/otf->unitsPerEm;
- } else {
- if (macStyle&1) { // bold
- ret->stemV=165;
- } else {
- ret->stemV=109; // TODO... unserious values...
- }
+ if (!ret->stemV)
+ {
+ // TODO? use name
+ const unsigned short d_gid = otf_from_unicode(otf, '.');
+ if (d_gid)
+ {
+ // stemV=bbox['.'].width;
+ len = otf_get_glyph(otf, d_gid);
+ DEBUG_assert(len >= 10);
+ ret->stemV = (get_SHORT(otf->gly + 6) - get_SHORT(otf->gly + 2)) * 1000 /
+ otf->unitsPerEm;
+ }
+ else
+ {
+ if (macStyle & 1)
+ // bold
+ ret->stemV = 165;
+ else
+ ret->stemV = 109; // TODO... unserious values...
}
}
- if (!ret->capHeight) { // TODO? only reqd. for fonts with latin...
- ret->capHeight=ret->ascent;
+ if (!ret->capHeight)
+ // TODO? only reqd. for fonts with latin...
+ ret->capHeight = ret->ascent;
// TODO: OTF spec says: use metrics of 'H' (0 if not available)
- }
- if (0) { // TODO? uses only adobe latin standard? ?? e.g. Type1
- ret->flags|=0x0020;
- } else {
- ret->flags|=0x0004;
- }
+ if (0) // TODO? uses only adobe latin standard? ?? e.g. Type1
+ ret->flags |= 0x0020;
+ else
+ ret->flags |= 0x0004;
// TODO SmallCap by font name(?)
// TODO ; ? cid ?
}
// }}}
+
// TODO: split generic part and otf part
// TODO: FIXME: gid vs. char ... NOTE: not called in multi_byte mode...
-// Adobe does: char --MacRoman/WinAnsi--> name --AGL--> unicode --cmap(3,1) --> gid only avoidable by setting 'symbol'+custom(1,0)/(3,0)
+// Adobe does: char --MacRoman/WinAnsi--> name --AGL-->
+// unicode --cmap(3, 1) --> gid only avoidable by setting
+// 'symbol' + custom(1, 0) / (3, 0)
// HINT: caller sets len == otf->numGlyphs (only when not using encoding...)
-EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_widths(OTF_FILE *otf,const unsigned short *encoding,int len,const BITSET glyphs) // {{{ glyphs==NULL -> all from 0 to len
+
+EMB_PDF_FONTWIDTHS *
+emb_otf_get_pdf_widths(OTF_FILE *otf,
+ const unsigned short *encoding,
+ int len,
+ const BITSET glyphs) // {{{ glyphs == NULL ->
+ // all from 0 to len
{
DEBUG_assert(otf);
- int first=len,last=0;
+ int first = len, last = 0;
int iA;
- if (glyphs) {
- for (iA=0;iA<len;iA++) { // iA is a "gid" when in multi_byte mode...
- const int gid=(encoding)?encoding[iA]:otf_from_unicode(otf,iA); // TODO
- if (bit_check(glyphs,gid)) {
- if (first>iA) { // first is a character index
- first=iA;
- }
- if (last<iA) {
- last=iA;
- }
+ if (glyphs)
+ {
+ for (iA = 0; iA < len; iA ++) // iA is a "gid" when in multi_byte mode...
+ {
+ const int gid = (encoding) ?
+ encoding[iA] : otf_from_unicode(otf, iA); // TODO
+ if (bit_check(glyphs, gid))
+ {
+ if (first > iA)
+ // first is a character index
+ first = iA;
+ if (last < iA)
+ last = iA;
}
}
- } else {
- first=0;
- last=len;
}
- if (last<first) {
+ else
+ {
+ first = 0;
+ last = len;
+ }
+ if (last < first)
+ {
// empty
- fprintf(stderr,"WARNING: empty embedding range\n");
- return NULL;
+ fprintf(stderr, "WARNING: empty embedding range\n");
+ return (NULL);
}
// ensure hmtx is there
- if (!otf->hmtx) {
- if (otf_load_more(otf)!=0) {
- fprintf(stderr,"Unsupported OTF font / cmap table \n");
- return NULL;
+ if (!otf -> hmtx)
+ {
+ if (otf_load_more(otf) != 0)
+ {
+ fprintf(stderr, "Unsupported OTF font / cmap table \n");
+ return (NULL);
}
}
// now create the array
- EMB_PDF_FONTWIDTHS *ret=emb_pdf_fw_new(last-first+1);
- if (!ret) {
- return NULL;
- }
- ret->first=first;
- ret->last=last;
- ret->widths=ret->data;
- for (iA=0;first<=last;iA++,first++) {
- const int gid=(encoding)?encoding[first]:otf_from_unicode(otf,first); // TODO
- if (gid>=otf->numGlyphs) {
- fprintf(stderr,"Bad glyphid\n");
+ EMB_PDF_FONTWIDTHS *ret = emb_pdf_fw_new(last - first + 1);
+ if (!ret)
+ return (NULL);
+ ret->first = first;
+ ret->last = last;
+ ret->widths = ret->data;
+ for (iA = 0; first <= last; iA ++, first ++)
+ {
+ const int gid = (encoding) ?
+ encoding[first] : otf_from_unicode(otf, first); // TODO
+ if (gid >= otf->numGlyphs)
+ {
+ fprintf(stderr, "Bad glyphid\n");
DEBUG_assert(0);
free(ret);
- return NULL;
+ return (NULL);
}
- if ( (!glyphs)||(bit_check(glyphs,gid)) ) {
- ret->widths[iA]=get_width_fast(otf,gid)*1000/otf->unitsPerEm;
- } // else 0 from calloc
+ if ((!glyphs) || (bit_check(glyphs, gid)))
+ ret->widths[iA] = get_width_fast(otf, gid) * 1000 / otf->unitsPerEm;
+ // else 0 from calloc
}
- return ret;
+ return (ret);
}
// }}}
+
// otf->hmtx must be there
-static int emb_otf_pdf_glyphwidth(void *context,int gid) // {{{
+
+static int
+emb_otf_pdf_glyphwidth(void *context, int gid) // {{{
{
- OTF_FILE *otf=(OTF_FILE *)context;
- return get_width_fast(otf,gid)*1000/otf->unitsPerEm;
+ OTF_FILE *otf = (OTF_FILE *)context;
+ return (get_width_fast(otf, gid) * 1000 / otf->unitsPerEm);
}
// }}}
-EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_cidwidths(OTF_FILE *otf,const BITSET glyphs) // {{{ // glyphs==NULL -> output all
+
+EMB_PDF_FONTWIDTHS *
+emb_otf_get_pdf_cidwidths(OTF_FILE *otf,
+ const BITSET glyphs) // {{{
+ // glyphs == NULL -> output all
{
DEBUG_assert(otf);
// ensure hmtx is there
- if (!otf->hmtx) {
- if (otf_load_more(otf)!=0) {
- fprintf(stderr,"Unsupported OTF font / cmap table \n");
+ if (!otf->hmtx)
+ {
+ if (otf_load_more(otf) != 0)
+ {
+ fprintf(stderr, "Unsupported OTF font / cmap table \n");
return NULL;
}
}
-// int dw=emb_otf_pdf_glyphwidth(otf,0); // e.g.
- int dw=-1; // let them estimate
+ // int dw = emb_otf_pdf_glyphwidth(otf, 0); // e.g.
+ int dw = -1; // let them estimate
- return emb_pdf_fw_cidwidths(glyphs,otf->numGlyphs,dw,emb_otf_pdf_glyphwidth,otf);
+ return (emb_pdf_fw_cidwidths(glyphs, otf->numGlyphs, dw,
+ emb_otf_pdf_glyphwidth, otf));
}
// }}}
+
/*** PS stuff ***/
#include "dynstring-private.h"
const char *aglfn13(unsigned short uni); // aglfn13.c
#include "macroman-private.h"
+
// TODO? optimize pascal string skipping? (create index)
// NOTE: might return a statically allocated string
-static const char *emb_otf_get_post_name(const char *post,unsigned short gid) // {{{
+
+static const char *
+emb_otf_get_post_name(const char *post,
+ unsigned short gid) // {{{
{
- if (!post) {
- return NULL;
- }
- const unsigned int post_version=get_ULONG(post);
- if (post_version==0x00010000) { // font has only 258 chars... font cannot be used on windows
- if (gid<sizeof(macRoman)/sizeof(macRoman[0])) {
- return macRoman[gid];
- }
- } else if (post_version==0x00020000) {
- const unsigned short num_glyphs=get_USHORT(post+32);
- // DEBUG_assert(num_glyphs==otf->numGlyphs);
- if (gid<num_glyphs) {
- unsigned short idx=get_USHORT(post+34+2*gid);
- if (idx<258) {
- if (idx<sizeof(macRoman)/sizeof(macRoman[0])) {
- return macRoman[idx];
- }
- } else if (idx<32768) {
- const unsigned char *pos=(unsigned char *)post+34+2*num_glyphs;
- for (idx-=258;idx>0;idx--) { // this sucks...
- pos+=*pos+1; // skip this string
- }
+ if (!post)
+ return (NULL);
+ const unsigned int post_version = get_ULONG(post);
+ if (post_version == 0x00010000) // font has only 258 chars...
+ // font cannot be used on windows
+ {
+ if (gid < sizeof(macRoman) / sizeof(macRoman[0]))
+ return (macRoman[gid]);
+ }
+ else if (post_version == 0x00020000)
+ {
+ const unsigned short num_glyphs = get_USHORT(post + 32);
+ // DEBUG_assert(num_glyphs == otf->numGlyphs);
+ if (gid < num_glyphs)
+ {
+ unsigned short idx = get_USHORT(post + 34 + 2 * gid);
+ if (idx < 258)
+ {
+ if (idx < sizeof(macRoman) / sizeof(macRoman[0]))
+ return (macRoman[idx]);
+ }
+ else if (idx < 32768)
+ {
+ const unsigned char *pos = (unsigned char *)post + 34 + 2 * num_glyphs;
+ for (idx -= 258; idx > 0; idx --) // this sucks...
+ pos += *pos + 1; // skip this string
// convert pascal string to asciiz
static char ret[256];
- const unsigned char len=*pos;
- memcpy(ret,(const char *)pos+1,len);
- ret[len]=0;
- return ret;
+ const unsigned char len = *pos;
+ memcpy(ret, (const char *)pos + 1, len);
+ ret[len] = 0;
+ return (ret);
}
}
- } else if (post_version==0x00025000) { // similiar to 0x00010000, deprecated
- const unsigned short num_glyphs=get_USHORT(post+32);
- if (gid<num_glyphs) {
- const unsigned short idx=post[34+gid]+gid; // post is signed char *
- if (idx<sizeof(macRoman)/sizeof(macRoman[0])) {
- return macRoman[idx];
- }
+ }
+ else if (post_version == 0x00025000)
+ {
+ // similiar to 0x00010000, deprecated
+ const unsigned short num_glyphs = get_USHORT(post + 32);
+ if (gid < num_glyphs)
+ {
+ const unsigned short idx = post[34 + gid] + gid; // post is signed char *
+ if (idx < sizeof(macRoman) / sizeof(macRoman[0]))
+ return (macRoman[idx]);
}
- } else if (post_version==0x00030000) {
+ }
+ else if (post_version == 0x00030000)
+ {
// no glyph names, sorry
-// } else if (post_version==0x00040000) { // apple AAT ?!
+ // } else if (post_version == 0x00040000) { // apple AAT ?!
}
- return NULL;
+ return (NULL);
}
// }}}
+
// TODO!? to_unicode should be able to represent more than one unicode character?
// NOTE: statically allocated string
-static const char *get_glyphname(const char *post,unsigned short *to_unicode,int charcode,unsigned short gid) // {{{ if charcode==0 -> force gid to be used
+
+static const char *
+get_glyphname(const char *post,
+ unsigned short *to_unicode,
+ int charcode,
+ unsigned short gid) // {{{ if charcode==0 -> force gid to be used
{
- if (gid==0) {
- return ".notdef";
- }
- const char *postName=emb_otf_get_post_name(post,gid);
- if (postName) {
- return postName;
- }
+ if (gid == 0)
+ return (".notdef");
+
+ const char *postName = emb_otf_get_post_name(post, gid);
+ if (postName)
+ return (postName);
+
static char ret[255];
- if (charcode) {
- if (to_unicode) { // i.e. encoding was there
- charcode=to_unicode[charcode];
- // TODO!? to_unicode should be able to represent more than one unicode character?
- // TODO for additional credit: for ligatures, etc create /f_f /uni12341234 or the like
- }
- const char *aglname=aglfn13(charcode); // TODO? special case ZapfDingbats?
- if (aglname) {
- return aglname;
- }
- snprintf(ret,250,"uni%04X",charcode); // allows extraction
- } else {
- snprintf(ret,250,"c%d",gid); // last resort: only by gid
- }
- return ret;
+ if (charcode)
+ {
+ if (to_unicode) // i.e. encoding was there
+ charcode = to_unicode[charcode];
+ // TODO!? to_unicode should be able to represent more than one unicode
+ // character?
+ // TODO for additional credit: for ligatures, etc create
+ // /f_f /uni12341234 or the like
+ const char *aglname = aglfn13(charcode); // TODO? special case ZapfDingbats?
+ if (aglname)
+ return (aglname);
+ snprintf(ret, 250, "uni%04X", charcode); // allows extraction
+ }
+ else
+ snprintf(ret, 250, "c%d", gid); // last resort: only by gid
+ return (ret);
}
// }}}
-struct OUTFILTER_PS {
+
+struct OUTFILTER_PS
+{
OUTPUT_FN out;
void *ctx;
int len;
};
-// TODO: for maximum compatiblity (PS<2013 interpreter) split only on table or glyph boundary (needs lookup in loca table!)
+
+// TODO: for maximum compatiblity (PS<2013 interpreter) split only on table
+// or glyph boundary (needs lookup in loca table!)
// Note: table boundaries are at each call!
-static void outfilter_ascii_ps(const char *buf,int len,void *context) // {{{
+
+static void
+outfilter_ascii_ps(const char *buf,
+ int len,
+ void *context) // {{{
{
- struct OUTFILTER_PS *of=context;
- OUTPUT_FN out=of->out;
+ struct OUTFILTER_PS *of = context;
+ OUTPUT_FN out = of->out;
int iA;
- (*out)("<",1,of->ctx);
- of->len++;
+ (*out)("<", 1, of->ctx);
+ of->len ++;
- const char *last=buf;
+ const char *last = buf;
char tmp[256];
- while (len>0) {
- for (iA=0;(iA<76)&&(len>0);iA+=2,len--) {
- const unsigned char ch=buf[iA>>1];
- tmp[iA]="0123456789abcdef"[ch>>4];
- tmp[iA+1]="0123456789abcdef"[ch&0x0f];
+ while (len > 0)
+ {
+ for (iA = 0; (iA < 76) && (len > 0); iA += 2, len --)
+ {
+ const unsigned char ch = buf[iA >> 1];
+ tmp[iA] = "0123456789abcdef"[ch >> 4];
+ tmp[iA + 1] = "0123456789abcdef"[ch & 0x0f];
}
- buf+=iA>>1;
- if (buf<last+64000) {
- if (len>0) {
- tmp[iA++]='\n';
- }
- (*out)(tmp,iA,of->ctx);
- } else {
- last=buf;
- strcpy(tmp+iA,"00>\n<");
- iA+=5;
- (*out)(tmp,iA,of->ctx);
+ buf += iA >> 1;
+ if (buf < last + 64000)
+ {
+ if (len > 0)
+ tmp[iA++] = '\n';
+ (*out)(tmp, iA, of->ctx);
+ }
+ else
+ {
+ last = buf;
+ strcpy(tmp + iA, "00>\n<");
+ iA += 5;
+ (*out)(tmp, iA, of->ctx);
}
- of->len+=iA;
+ of->len += iA;
}
(*out)("00>\n",4,of->ctx);
}
// }}}
-static void outfilter_binary_ps(const char *buf,int len,void *context) // {{{
+
+static void
+outfilter_binary_ps(const char *buf,
+ int len,
+ void *context) // {{{
{
- struct OUTFILTER_PS *of=context;
- OUTPUT_FN out=of->out;
+ struct OUTFILTER_PS *of = context;
+ OUTPUT_FN out = of->out;
char tmp[100];
- while (len>0) {
- const int maxlen=(len>64000)?64000:len;
- const int l=sprintf(tmp,"%d RD ",maxlen);
- (*out)(tmp,l,of->ctx);
- of->len+=l;
-
- (*out)(buf,maxlen,of->ctx);
- (*out)("\n",1,of->ctx);
- of->len+=maxlen+1;
- len-=maxlen;
- buf+=maxlen;
+ while (len > 0)
+ {
+ const int maxlen = (len > 64000) ? 64000 : len;
+ const int l = sprintf(tmp, "%d RD ", maxlen);
+ (*out)(tmp, l, of->ctx);
+ of->len += l;
+
+ (*out)(buf, maxlen, of->ctx);
+ (*out)("\n", 1, of->ctx);
+ of->len += maxlen + 1;
+ len -= maxlen;
+ buf += maxlen;
}
}
// }}}
-/*
- encoding: character-code -> glyph id ["required", NULL: identity, i.e. from_unicode()] // TODO: respect subsetting
- to_unicode: character-code -> unicode [NULL: no char names] // kind-of "reverse" of encoding (to_unicode does not make sense without >encoding)
-
-Status:
- - we need a 0..255 encoding to be used in the PS file
- - we want to allow the use of encoding[]; this should map from your desired PS-stream output character (0..255) directly to the gid
- - if encoding[] is not used, MacRoman/WinAnsi/latin1 is expected (easiest: latin1, as it is a subset of unicode)
- i.e. your want to output latin1 to the PS-stream
- - len is the length of >encoding, or the "last used latin1 character"
- - oh. in multibyte-mode no >encoding probably should mean identity(gid->gid) not (latin1->gid)
- - non-multibyte PDF -> only 255 chars ... not recommended (we can't just map to gids, but only to names, which acro will then cmap(3,1) to gids)
-
- => problem with subsetting BITSET (keyed by gid); we want BITSET keyed by 0..255 (via encoding)
-
- // TODO: a) multi font encoding
- // TODO: b) cid/big font encoding (PS>=2015) [/CIDFontType 2] : CMap does Charcode->CID, /CIDMap does CID->GID [e.g. Identity/delta value]
- // (also needed [or a)] for loca>64000 if split, etc) e.g. /CIDMap 0 [requires PS>=3011?]
- // [Danger: do not split composites]
- // TODO? incremental download [/GlyphDirectory array or dict] : /GlyphDirectory does GID-><glyf entry> mapping
- // need 'fake' gdir table (size,offset=0) in sfnt; loca, glyf can be ommited; hmtx can be omitted for PS>=3011 [/MetricsCount 2]
- // idea is to fill initial null entries in the array/dict [Beware of save/restore!]
- // NOTE: even when subsetting the font has to come first in the PS file
-
-
-... special information: when multi-byte PDF encoding is used <gid> is output.
- therefore /Encoding /Identity-H + /CIDSystemInfo Adobe-Identity-0 will yield 1-1 mapping for font.
- problem is that text is not selectable. therefore there is the /ToUnicode CMap option
-*/
-int emb_otf_ps(OTF_FILE *otf,unsigned short *encoding,int len,unsigned short *to_unicode,OUTPUT_FN output,void *context) // {{{
+
+//
+// encoding: character-code ->
+// glyph id ["required", NULL: identity, i.e. from_unicode()]
+// // TODO: respect subsetting
+// to_unicode: character-code ->
+// unicode [NULL: no char names]
+// // kind-of "reverse" of encoding (to_unicode
+// // does not make sense without >encoding)
+//
+// Status:
+// - we need a 0..255 encoding to be used in the PS file
+// - we want to allow the use of encoding[]; this should map from your
+// desired PS-stream output character (0..255) directly to the gid
+// - if encoding[] is not used, MacRoman/WinAnsi/latin1 is expected
+// (easiest: latin1, as it is a subset of unicode)
+// i.e. your want to output latin1 to the PS-stream
+// - len is the length of >encoding, or the "last used latin1 character"
+// - oh. in multibyte-mode no >encoding probably should mean
+// identity(gid->gid) not (latin1->gid)
+// - non-multibyte PDF -> only 255 chars ... not recommended (we can't
+// just map to gids, but only to names, which acro will then cmap(3, 1)
+// to gids)
+//
+// => problem with subsetting BITSET (keyed by gid); we want BITSET keyed
+// by 0..255 (via encoding)
+//
+// TODO: a) multi font encoding
+// TODO: b) cid/big font encoding (PS >= 2015) [/CIDFontType 2] : CMap does
+// Charcode->CID, /CIDMap does CID->GID [e.g. Identity/delta value]
+// (also needed [or a)] for loca>64000 if split, etc)
+// e.g. /CIDMap 0 [requires PS >= 3011?]
+// [Danger: do not split composites]
+// TODO? incremental download [/GlyphDirectory array or dict] :
+// /GlyphDirectory does GID-><glyf entry> mapping
+// need 'fake' gdir table (size,offset=0) in sfnt; loca, glyf can be
+// ommited; hmtx can be omitted for PS >= 3011 [/MetricsCount 2]
+// idea is to fill initial null entries in the array/dict
+// [Beware of save/restore!]
+// NOTE: even when subsetting the font has to come first in the PS file
+//
+// ... special information: when multi-byte PDF encoding is used <gid> is
+// output.
+// therefore /Encoding /Identity-H + /CIDSystemInfo Adobe-Identity-0 will
+// yield 1-1 mapping for font.
+// problem is that text is not selectable. therefore there is the
+// /ToUnicode CMap option
+//
+
+int
+emb_otf_ps(OTF_FILE *otf,
+ unsigned short *encoding,
+ int len,
+ unsigned short *to_unicode,
+ OUTPUT_FN output,
+ void *context) // {{{
{
- const int binary=0; // binary format? // TODO
- if (len>256) {
- fprintf(stderr,"Encoding too big(%d) for Type42\n",len);
- return -1;
+ const int binary = 0; // binary format? // TODO
+ if (len > 256)
+ {
+ fprintf(stderr, "Encoding too big(%d) for Type42\n", len);
+ return (-1);
}
- if (len<1) {
- fprintf(stderr,"At least .notdef required in Type42\n");
- return -1;
+ if (len < 1)
+ {
+ fprintf(stderr, "At least .notdef required in Type42\n");
+ return (-1);
}
- if (!encoding) {
- to_unicode=NULL; // does not make sense
- }
- int iA,ret=0;
+ if (!encoding)
+ to_unicode = NULL; // does not make sense
+
+ int iA, ret=0;
DYN_STRING ds;
- if (dyn_init(&ds,1024)==-1) {
- return -1;
- }
+ if (dyn_init(&ds, 1024) == -1)
+ return (-1);
- int rlen=0;
- char *head=otf_get_table(otf,OTF_TAG('h','e','a','d'),&rlen);
- if (!head) {
+ int rlen = 0;
+ char *head = otf_get_table(otf, OTF_TAG('h', 'e', 'a', 'd'), &rlen);
+ if (!head)
+ {
free(ds.buf);
- return -1;
- }
- dyn_printf(&ds,"%%!PS-TrueTypeFont-%d-%d\n",
- otf->version,get_ULONG(head+4));
- const int bbxmin=get_SHORT(head+36)*1000/otf->unitsPerEm,
- bbymin=get_SHORT(head+38)*1000/otf->unitsPerEm,
- bbxmax=get_SHORT(head+40)*1000/otf->unitsPerEm,
- bbymax=get_SHORT(head+42)*1000/otf->unitsPerEm;
+ return (-1);
+ }
+ dyn_printf(&ds, "%%!PS-TrueTypeFont-%d-%d\n",
+ otf->version, get_ULONG(head + 4));
+ const int bbxmin = get_SHORT(head + 36) * 1000 / otf->unitsPerEm,
+ bbymin = get_SHORT(head + 38) * 1000 / otf->unitsPerEm,
+ bbxmax = get_SHORT(head + 40) * 1000 / otf->unitsPerEm,
+ bbymax = get_SHORT(head + 42) * 1000 / otf->unitsPerEm;
free(head);
- char *post=otf_get_table(otf,OTF_TAG('p','o','s','t'),&rlen);
- if ( (!post)&&(rlen!=-1) ) { // other error than "not found"
+ char *post = otf_get_table(otf, OTF_TAG('p', 'o', 's', 't'), &rlen);
+ if ((!post) && (rlen != -1)) // other error than "not found"
+ {
free(ds.buf);
- return -1;
+ return (-1);
}
- if (post) {
- const unsigned int minMem=get_ULONG(post+16),maxMem=get_ULONG(post+20);
- if (minMem) {
- dyn_printf(&ds,"%%VMusage: %d %d\n",minMem,maxMem);
- }
+ if (post)
+ {
+ const unsigned int minMem = get_ULONG(post + 16),
+ maxMem = get_ULONG(post + 20);
+ if (minMem)
+ dyn_printf(&ds, "%%VMusage: %d %d\n", minMem, maxMem);
}
// don't forget the coordinate scaling...
- dyn_printf(&ds,"11 dict begin\n"
- "/FontName /%s def\n"
- "/FontType 42 def\n"
- "/FontMatrix [1 0 0 1 0 0] def\n"
- "/FontBBox [%f %f %f %f] def\n"
- "/PaintType 0 def\n",
-// "/XUID [42 16#%X 16#%X 16#%X 16#%X] def\n" // TODO?!? (md5 of font data) (16# means base16)
- emb_otf_get_fontname(otf),
- bbxmin/1000.0,bbymin/1000.0,bbxmax/1000.0,bbymax/1000.0);
- if (post) {
+ dyn_printf(&ds, "11 dict begin\n"
+ "/FontName /%s def\n"
+ "/FontType 42 def\n"
+ "/FontMatrix [1 0 0 1 0 0] def\n"
+ "/FontBBox [%f %f %f %f] def\n"
+ "/PaintType 0 def\n",
+// "/XUID [42 16#%X 16#%X 16#%X 16#%X] def\n"
+// // TODO?!? (md5 of font data) (16# means base16)
+ emb_otf_get_fontname(otf),
+ bbxmin / 1000.0, bbymin / 1000.0,
+ bbxmax / 1000.0, bbymax / 1000.0);
+ if (post)
dyn_printf(&ds,"/FontInfo 4 dict dup begin\n"
-// TODO? [even non-post]: /version|/Notice|/Copyright|/FullName|/FamilyName|/Weight () readonly def\n from name table: 5 7 0 4 1 2
-// using: otf_get_name(otf,3,1,0x409,?,&len) / otf_get_name(otf,1,0,0,?,&len) + encoding
+ // TODO? [even non-post]:
+ // /version|/Notice|/Copyright|/FullName|/FamilyName|/Weight
+ // () readonly def\n from name table: 5 7 0 4 1 2
+ // using: otf_get_name(otf, 3, 1, 0x409, ?, &len) /
+ // otf_get_name(otf, 1, 0, 0, ?, &len) + encoding
" /ItalicAngle %d def\n"
" /isFixedPitch %s def\n"
" /UnderlinePosition %f def\n"
" /UnderlineThickness %f def\n"
"end readonly def\n",
- get_LONG(post+4)>>16,
- (get_ULONG(post+12)?"true":"false"),
- (get_SHORT(post+8)-get_SHORT(post+10)/2)/(float)otf->unitsPerEm,
- get_SHORT(post+10)/(float)otf->unitsPerEm);
- }
- dyn_printf(&ds,"/Encoding 256 array\n"
- "0 1 255 { 1 index exch /.notdef put } for\n");
- for (iA=0;iA<len;iA++) { // encoding data: 0...255 -> /glyphname
- const int gid=(encoding)?encoding[iA]:otf_from_unicode(otf,iA);
- if (gid!=0) {
- dyn_printf(&ds,"dup %d /%s put\n",
- iA,get_glyphname(post,to_unicode,iA,gid));
- }
- }
- dyn_printf(&ds,"readonly def\n");
-
- if (binary) {
- dyn_printf(&ds,"/RD { string currentfile exch readstring pop } executeonly def\n");
- }
- dyn_printf(&ds,"/sfnts[\n");
-
- if (ds.len<0) {
+ get_LONG(post + 4) >> 16,
+ (get_ULONG(post + 12) ? "true" : "false"),
+ (get_SHORT(post + 8) - get_SHORT(post + 10) / 2) /
+ (float)otf->unitsPerEm,
+ get_SHORT(post + 10) / (float)otf->unitsPerEm);
+ dyn_printf(&ds, "/Encoding 256 array\n"
+ "0 1 255 { 1 index exch /.notdef put } for\n");
+ for (iA = 0; iA < len; iA ++) // encoding data: 0...255 -> /glyphname
+ {
+ const int gid = (encoding) ? encoding[iA] : otf_from_unicode(otf, iA);
+ if (gid != 0)
+ dyn_printf(&ds, "dup %d /%s put\n",
+ iA, get_glyphname(post, to_unicode, iA, gid));
+ }
+ dyn_printf(&ds, "readonly def\n");
+
+ if (binary)
+ dyn_printf(&ds,
+ "/RD { string currentfile exch readstring pop } executeonly def\n");
+ dyn_printf(&ds, "/sfnts[\n");
+
+ if (ds.len < 0)
+ {
free(post);
free(ds.buf);
- return -1;
+ return (-1);
}
- (*output)(ds.buf,ds.len,context);
- ret+=ds.len;
- ds.len=0;
+ (*output)(ds.buf, ds.len, context);
+ ret += ds.len;
+ ds.len = 0;
-// TODO: only tables as in otf_subset
-// TODO: somehow communicate table boundaries:
+ // TODO: only tables as in otf_subset
+ // TODO: somehow communicate table boundaries:
// otf_action_copy does exactly one output call (per table)
// only otf_action_replace might do two (padding)
// {{{ copy tables verbatim (does not affect ds .len)
- struct _OTF_WRITE *otfree=NULL;
+
+ struct _OTF_WRITE *otfree = NULL;
#if 0
struct _OTF_WRITE *otw;
- otwfree=otw=malloc(sizeof(struct _OTF_WRITE)*otf->numTables);
- if (!otw) {
- fprintf(stderr,"Bad alloc: %m\n");
+ otwfree = otw = malloc(sizeof(struct _OTF_WRITE) * otf->numTables);
+ if (!otw)
+ {
+ fprintf(stderr, "Bad alloc: %m\n");
free(post);
free(ds.buf);
- return -1;
+ return (-1);
}
// just copy everything
- for (iA=0;iA<otf->numTables;iA++) {
- otw[iA].tag=otf->tables[iA].tag;
- otw[iA].action=otf_action_copy;
- otw[iA].param=otf;
- otw[iA].length=iA;
- }
- int numTables=otf->numTables;
+ for (iA = 0; iA < otf->numTables; iA ++)
+ {
+ otw[iA].tag = otf->tables[iA].tag;
+ otw[iA].action = otf_action_copy;
+ otw[iA].param = otf;
+ otw[iA].length = iA;
+ }
+ int numTables = otf->numTables;
#else
- struct _OTF_WRITE otw[]={ // sorted
- {OTF_TAG('c','m','a','p'),otf_action_copy,otf,},
- {OTF_TAG('c','v','t',' '),otf_action_copy,otf,},
- {OTF_TAG('f','p','g','m'),otf_action_copy,otf,},
- {OTF_TAG('g','l','y','f'),otf_action_copy,otf,},
- {OTF_TAG('h','e','a','d'),otf_action_copy,otf,},
- {OTF_TAG('h','h','e','a'),otf_action_copy,otf,},
- {OTF_TAG('h','m','t','x'),otf_action_copy,otf,},
- {OTF_TAG('l','o','c','a'),otf_action_copy,otf,},
- {OTF_TAG('m','a','x','p'),otf_action_copy,otf,},
- {OTF_TAG('n','a','m','e'),otf_action_copy,otf,},
- {OTF_TAG('p','r','e','p'),otf_action_copy,otf,},
- // vhea vmtx (never used in PDF, but possible in PS>=3011)
- {0,0,0,0}};
- int numTables=otf_intersect_tables(otf,otw);
+ struct _OTF_WRITE otw[] = // sorted
+ {
+ {OTF_TAG('c', 'm', 'a', 'p'), otf_action_copy, otf,},
+ {OTF_TAG('c', 'v', 't', ' '), otf_action_copy, otf,},
+ {OTF_TAG('f', 'p', 'g', 'm'), otf_action_copy, otf,},
+ {OTF_TAG('g', 'l', 'y', 'f'), otf_action_copy, otf,},
+ {OTF_TAG('h', 'e', 'a', 'd'), otf_action_copy, otf,},
+ {OTF_TAG('h', 'h', 'e', 'a'), otf_action_copy, otf,},
+ {OTF_TAG('h', 'm', 't', 'x'), otf_action_copy, otf,},
+ {OTF_TAG('l', 'o', 'c', 'a'), otf_action_copy, otf,},
+ {OTF_TAG('m', 'a', 'x', 'p'), otf_action_copy, otf,},
+ {OTF_TAG('n', 'a', 'm', 'e'), otf_action_copy, otf,},
+ {OTF_TAG('p', 'r', 'e', 'p'), otf_action_copy, otf,},
+ // vhea vmtx (never used in PDF, but possible in PS >= 3011)
+ {0,0,0,0}};
+ int numTables = otf_intersect_tables(otf, otw);
#endif
struct OUTFILTER_PS of;
- of.out=output;
- of.ctx=context;
- of.len=0;
- if (binary) {
- iA=otf_write_sfnt(otw,otf->version,numTables,outfilter_binary_ps,&of);
- } else {
- iA=otf_write_sfnt(otw,otf->version,numTables,outfilter_ascii_ps,&of);
- }
+ of.out = output;
+ of.ctx = context;
+ of.len = 0;
+ if (binary)
+ iA = otf_write_sfnt(otw, otf->version, numTables, outfilter_binary_ps, &of);
+ else
+ iA = otf_write_sfnt(otw, otf->version, numTables, outfilter_ascii_ps, &of);
free(otfree);
- if (iA==-1) {
+ if (iA == -1)
+ {
free(post);
free(ds.buf);
- return -1;
+ return (-1);
}
- ret+=of.len;
+ ret += of.len;
// }}} done copying
- dyn_printf(&ds,"] def\n");
+ dyn_printf(&ds, "] def\n");
- dyn_printf(&ds,"/CharStrings %d dict dup begin\n"
- "/.notdef 0 def\n",len);
- for (iA=0;iA<len;iA++) { // charstrings data: /glyphname -> gid
- const int gid=(encoding)?encoding[iA]:otf_from_unicode(otf,iA);
- if (gid) {
- dyn_printf(&ds,"/%s %d def\n",get_glyphname(post,to_unicode,iA,gid),gid);
- }
+ dyn_printf(&ds, "/CharStrings %d dict dup begin\n"
+ "/.notdef 0 def\n", len);
+ for (iA = 0; iA < len; iA ++) // charstrings data: /glyphname -> gid
+ {
+ const int gid = (encoding) ? encoding[iA] : otf_from_unicode(otf, iA);
+ if (gid)
+ dyn_printf(&ds, "/%s %d def\n",
+ get_glyphname(post, to_unicode, iA, gid), gid);
// (respecting subsetting...)
}
- dyn_printf(&ds,"end readonly def\n");
- dyn_printf(&ds,"FontName currentdict end definefont pop\n");
+ dyn_printf(&ds, "end readonly def\n");
+ dyn_printf(&ds, "FontName currentdict end definefont pop\n");
free(post);
- if (ds.len<0) {
+ if (ds.len < 0)
+ {
free(ds.buf);
- return -1;
+ return (-1);
}
- (*output)(ds.buf,ds.len,context);
- ret+=ds.len;
- ds.len=0;
+ (*output)(ds.buf, ds.len, context);
+ ret += ds.len;
+ ds.len = 0;
free(ds.buf);
- return ret;
+ return (ret);
}
// }}}
-
#include <string.h>
#include <stdlib.h>
-static inline int copy_file(FILE *f,OUTPUT_FN output,void *context) // {{{
+
+static inline int
+copy_file(FILE *f,
+ OUTPUT_FN output,
+ void *context) // {{{
{
DEBUG_assert(f);
DEBUG_assert(output);
char buf[4096];
- int iA,ret=0;
+ int iA, ret = 0;
- ret=0;
+ ret = 0;
rewind(f);
- do {
- iA=fread(buf,1,4096,f);
- (*output)(buf,iA,context);
- ret+=iA;
- } while (iA>0);
- return ret;
+ do
+ {
+ iA = fread(buf, 1, 4096, f);
+ (*output)(buf, iA, context);
+ ret += iA;
+ }
+ while (iA > 0);
+ return (ret);
}
// }}}
-/* certain profiles: (=> constraints to be auto-applied in emb_new via >dest)
- PSold: T1->T1, TTF->T1, OTF->CFF->T1, STD->STD // output limit: T1 (maybe length, binary/text, ... limit)
- PS1: T1->T1, TTF->T1, OTF->CFF, STD->STD // output limit: T1,CFF [does this really exists?]
- PS2: T1->T1, TTF->TTF, OTF->T1, STD->STD // output limit: T1,TTF
- PS3: T1->T1, TTF->TTF, OTF->CFF, STD->STD
- PDF12/13?: OTF->CFF
- PDF16: OTF->OTF (,T1->CFF?)
- --- rename KEEP_T1 to NEED_T1? NO_T42?
-
- converters:
- OTF->CFF, CFF->OTF (extract metrics, etc)
- (T1->CFF, CFF->T1)
- ((TTF->T1 ['good'; T1->TTF: not good]))
- [subsetTTF,subsetCFF,subsetT1]
-
- output modes:
- subset,CID(multibyte),(PS:)text/binary,(PS:)incremental
- TODO: remove dest from emb_new, replace with EMB_ACTIONS constraints:
- - bitfield mask which ACTIONS are allowed. (problem: we want to force certain ones, e.g. MULTIBYTE)
- - e.g. currently EMB_C_PDF_OT has to functions
- - the only (other) 'difference' to now is the subsetting spec
- - another issue is, that emb_pdf_ might want some pdf version informatino (->extra flag?)
- and funtion to determine appropriate mask for certain destination
- EMB_ACTIONS emb_mask_for_dest(EMB_DESTINATION)
- TODO? determine viability before trying emb_embed
- (idea: use emb_embed(,NULL) -> will just return true/false [same codepath!])
+//
+// certain profiles: (=> constraints to be auto-applied in emb_new via >dest)
+// PSold: T1->T1, TTF->T1, OTF->CFF->T1, STD->STD // output limit: T1
+// // (maybe length,
+// // binary/text, ... limit)
+// PS1: T1->T1, TTF->T1, OTF->CFF, STD->STD // output limit: T1,CFF
+// // [does this really exists?]
+// PS2: T1->T1, TTF->TTF, OTF->T1, STD->STD // output limit: T1, TTF
+// PS3: T1->T1, TTF->TTF, OTF->CFF, STD->STD
+// PDF12/13?: OTF->CFF
+// PDF16: OTF->OTF (, T1->CFF?)
+// --- rename KEEP_T1 to NEED_T1? NO_T42?
+//
+// converters:
+// OTF->CFF, CFF->OTF (extract metrics, etc)
+// (T1->CFF, CFF->T1)
+// ((TTF->T1 ['good'; T1->TTF: not good]))
+// [subsetTTF, subsetCFF, subsetT1]
+//
+// output modes:
+// subset,CID(multibyte),(PS:)text/binary,(PS:)incremental
+//
+// TODO: remove dest from emb_new, replace with EMB_ACTIONS constraints:
+// - bitfield mask which ACTIONS are allowed. (problem: we want to force
+// certain ones, e.g. MULTIBYTE)
+// - e.g. currently EMB_C_PDF_OT has to functions
+// - the only (other) 'difference' to now is the subsetting spec
+// - another issue is, that emb_pdf_ might want some pdf version
+// informatino (-> extra flag?)
+// and funtion to determine appropriate mask for certain destination
+// EMB_ACTIONS emb_mask_for_dest(EMB_DESTINATION)
+// TODO? determine viability before trying emb_embed
+// (idea: use emb_embed(, NULL) -> will just return true/false [same
+// codepath!])
+//
+// TODO?! "always subset CJK"
+//
- TODO?! "always subset CJK"
-*/
-EMB_PARAMS *emb_new(FONTFILE *font,EMB_DESTINATION dest,EMB_CONSTRAINTS mode) // {{{
+EMB_PARAMS *
+emb_new(FONTFILE *font,
+ EMB_DESTINATION dest,
+ EMB_CONSTRAINTS mode) // {{{
{
DEBUG_assert(font);
- EMB_PARAMS *ret=calloc(1,sizeof(EMB_PARAMS));
- if (!ret) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- if (mode&EMB_C_TAKE_FONTFILE) {
+ EMB_PARAMS *ret = calloc(1, sizeof(EMB_PARAMS));
+ if (!ret)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
+ if (mode & EMB_C_TAKE_FONTFILE)
fontfile_close(font);
- }
- return NULL;
- }
- ret->dest=dest;
- ret->font=font;
- if (mode&EMB_C_TAKE_FONTFILE) {
- ret->plan|=EMB_A_CLOSE_FONTFILE;
+ return (NULL);
}
+ ret->dest = dest;
+ ret->font = font;
+ if (mode & EMB_C_TAKE_FONTFILE)
+ ret->plan |= EMB_A_CLOSE_FONTFILE;
// check parameters
- if ( (mode&EMB_C_KEEP_T1)&&(mode&EMB_C_FORCE_MULTIBYTE) ) {
- fprintf(stderr,"Incompatible mode: KEEP_T1 and FORCE_MULTIBYTE\n");
+ if ((mode & EMB_C_KEEP_T1) && (mode & EMB_C_FORCE_MULTIBYTE))
+ {
+ fprintf(stderr, "Incompatible mode: KEEP_T1 and FORCE_MULTIBYTE\n");
emb_close(ret);
- return NULL;
+ return (NULL);
}
- if ((mode&0x07)>5) {
- fprintf(stderr,"Bad subset specification\n");
+ if ((mode & 0x07) > 5)
+ {
+ fprintf(stderr, "Bad subset specification\n");
emb_close(ret);
- return NULL;
+ return (NULL);
}
// determine intype
- int numGlyphs=0;
- if (font->sfnt) {
- if (font->sfnt->flags&OTF_F_FMT_CFF) {
- ret->intype=EMB_FMT_OTF;
- } else {
- ret->intype=EMB_FMT_TTF;
- }
- ret->rights=emb_otf_get_rights(ret->font->sfnt);
- numGlyphs=ret->font->sfnt->numGlyphs; // TODO
- } else if (font->stdname) {
- ret->intype=EMB_FMT_STDFONT;
- ret->rights=EMB_RIGHT_NONE;
- } else {
- DEBUG_assert(0);
+ int numGlyphs = 0;
+ if (font->sfnt)
+ {
+ if (font->sfnt->flags & OTF_F_FMT_CFF)
+ ret->intype = EMB_FMT_OTF;
+ else
+ ret->intype = EMB_FMT_TTF;
+ ret->rights = emb_otf_get_rights(ret->font->sfnt);
+ numGlyphs = ret->font->sfnt->numGlyphs; // TODO
}
-/*
- if ( (ret->intype==EMB_FMT_CFF)&&
- (ret->cffFont.is_cid()) ) {
- ?= || ( (ret->intype==EMB_FMT_OTF)&&(ret->sfnt->cffFont.is_cid()) ) // TODO?
- ret->plan|=EMB_A_MULTIBYTE;
+ else if (font->stdname)
+ {
+ ret->intype = EMB_FMT_STDFONT;
+ ret->rights = EMB_RIGHT_NONE;
+ } else
+ DEBUG_assert(0);
+
+#if 0
+ if ((ret->intype == EMB_FMT_CFF) &&
+ (ret->cffFont.is_cid()))
+ {
+ ?= || ((ret->intype == EMB_FMT_OTF) &&
+ (ret->sfnt->cffFont.is_cid())) // TODO?
+ ret->plan |= EMB_A_MULTIBYTE;
}
-*/
+#endif // 0
// determine outtype
- if (ret->intype==EMB_FMT_STDFONT) {
- ret->outtype=ret->intype;
- if (mode&EMB_C_FORCE_MULTIBYTE) {
- fprintf(stderr,"Multibyte stdfonts are not possible\n");
+ if (ret->intype == EMB_FMT_STDFONT)
+ {
+ ret->outtype = ret->intype;
+ if (mode & EMB_C_FORCE_MULTIBYTE)
+ {
+ fprintf(stderr, "Multibyte stdfonts are not possible\n");
emb_close(ret);
- return NULL;
+ return (NULL);
}
- return ret; // never subset, no multibyte
- } else if (ret->intype==EMB_FMT_T1) {
- if (mode&EMB_C_KEEP_T1) {
- ret->outtype=EMB_FMT_T1;
- } else {
- ret->plan|=EMB_A_T1_TO_CFF;
- ret->outtype=EMB_FMT_CFF;
+ return (ret); // never subset, no multibyte
+ }
+ else if (ret->intype == EMB_FMT_T1)
+ {
+ if (mode & EMB_C_KEEP_T1)
+ ret->outtype = EMB_FMT_T1;
+ else {
+ ret->plan |= EMB_A_T1_TO_CFF;
+ ret->outtype = EMB_FMT_CFF;
}
- } else {
- ret->outtype=ret->intype;
}
- if (ret->outtype==EMB_FMT_CFF) {
- if (mode&EMB_C_PDF_OT) {
- ret->outtype=EMB_FMT_OTF;
- ret->plan|=EMB_A_CFF_TO_OTF;
+ else
+ ret->outtype = ret->intype;
+ if (ret->outtype == EMB_FMT_CFF)
+ {
+ if (mode & EMB_C_PDF_OT)
+ {
+ ret->outtype = EMB_FMT_OTF;
+ ret->plan |= EMB_A_CFF_TO_OTF;
}
- } else if (ret->outtype==EMB_FMT_OTF) {
+ }
+ else if (ret->outtype == EMB_FMT_OTF)
+ {
// TODO: no support yet; but we want to get the FontDescriptor/Name right
- mode|=EMB_C_NEVER_SUBSET;
- if (!(mode&EMB_C_PDF_OT)) { // TODO!?!
- ret->outtype=EMB_FMT_CFF;
- ret->plan|=EMB_A_OTF_TO_CFF;
+ mode |= EMB_C_NEVER_SUBSET;
+ if (!(mode & EMB_C_PDF_OT))
+ { // TODO!?!
+ ret->outtype = EMB_FMT_CFF;
+ ret->plan |= EMB_A_OTF_TO_CFF;
}
}
- if (mode&EMB_C_FORCE_MULTIBYTE) {
- ret->plan|=EMB_A_MULTIBYTE;
- }
+ if (mode & EMB_C_FORCE_MULTIBYTE)
+ ret->plan |= EMB_A_MULTIBYTE;
// check rights (for subsetting)
- if ( (ret->rights&EMB_RIGHT_NONE)||
- (ret->rights&EMB_RIGHT_BITMAPONLY)||
- ( (ret->rights&EMB_RIGHT_READONLY)&&(mode&EMB_C_EDITABLE_SUBSET) )||
- ( (ret->rights&EMB_RIGHT_NO_SUBSET)&&(mode&EMB_C_MUST_SUBSET) ) ) {
- fprintf(stderr,"The font does not permit the requested embedding\n");
+ if ((ret->rights & EMB_RIGHT_NONE) ||
+ (ret->rights & EMB_RIGHT_BITMAPONLY) ||
+ ((ret->rights & EMB_RIGHT_READONLY) && (mode & EMB_C_EDITABLE_SUBSET)) ||
+ ((ret->rights & EMB_RIGHT_NO_SUBSET) && (mode & EMB_C_MUST_SUBSET)))
+ {
+ fprintf(stderr, "The font does not permit the requested embedding\n");
emb_close(ret);
- return NULL;
- } else if ( (!(ret->rights&EMB_RIGHT_NO_SUBSET))&&
- (!(mode&EMB_C_NEVER_SUBSET)) ) {
- ret->plan|=EMB_A_SUBSET;
+ return (NULL);
}
+ else if ((!(ret->rights & EMB_RIGHT_NO_SUBSET)) &&
+ (!(mode & EMB_C_NEVER_SUBSET)))
+ ret->plan |= EMB_A_SUBSET;
// alloc subset
- if (ret->plan&EMB_A_SUBSET) {
- ret->subset=bitset_new(numGlyphs);
- if (!ret->subset) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
+ if (ret->plan & EMB_A_SUBSET)
+ {
+ ret->subset = bitset_new(numGlyphs);
+ if (!ret->subset)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
emb_close(ret);
- return NULL;
+ return (NULL);
}
}
- return ret;
+ return (ret);
}
// }}}
-int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context) // {{{
+
+int
+emb_embed(EMB_PARAMS *emb,
+ OUTPUT_FN output,
+ void *context) // {{{
{
DEBUG_assert(emb);
- if (emb->dest==EMB_DEST_NATIVE) {
- } else if (emb->dest<=EMB_DEST_PS) {
- int ret=-2;
- const char *fontname=emb_otf_get_fontname(emb->font->sfnt); // TODO!!
- (*output)("%%BeginFont: ",13,context);
- (*output)(fontname,strlen(fontname),context);
- (*output)("\n",1,context);
- if (emb->outtype==EMB_FMT_T1) {
- } else if (emb->outtype==EMB_FMT_TTF) { // emb->outtype==EMB_OUTPUT_OTF is stupid (?)
- // do Type42
- ret=emb_otf_ps(emb->font->sfnt,NULL,256,NULL,output,context); // TODO?
- } else if (emb->outtype==EMB_FMT_CFF) {
- } else if (emb->outtype==EMB_FMT_STDFONT) {
+ if (emb->dest == EMB_DEST_NATIVE)
+ {
+ }
+ else if (emb->dest <= EMB_DEST_PS)
+ {
+ int ret =- 2;
+ const char *fontname = emb_otf_get_fontname(emb->font->sfnt); // TODO!!
+ (*output)("%%BeginFont: ", 13, context);
+ (*output)(fontname, strlen(fontname), context);
+ (*output)("\n", 1, context);
+ if (emb->outtype == EMB_FMT_T1)
+ {
}
- if (ret!=-2) {
- if (ret!=-1) {
- (*output)("%%EndFont\n",10,context);
- } else {
- fprintf(stderr,"Failed\n");
- }
- return ret;
+ else if (emb->outtype == EMB_FMT_TTF) { // emb->outtype==EMB_OUTPUT_OTF
+ // is stupid (?)
+ // do Type42
+ ret = emb_otf_ps(emb->font->sfnt, NULL, 256, NULL, output, context);
+ // TODO?
}
- } else if (emb->dest<=EMB_DEST_PDF16) {
- if (emb->outtype==EMB_FMT_TTF) {
+ else if (emb->outtype == EMB_FMT_CFF)
+ {
+ }
+ else if (emb->outtype == EMB_FMT_STDFONT)
+ {
+ }
+ if (ret != -2)
+ {
+ if (ret != -1)
+ (*output)("%%EndFont\n", 10, context);
+ else
+ fprintf(stderr, "Failed\n");
+ return (ret);
+ }
+ }
+ else if (emb->dest <= EMB_DEST_PDF16)
+ {
+ if (emb->outtype == EMB_FMT_TTF)
+ {
DEBUG_assert(emb->font->sfnt);
- if (emb->plan&EMB_A_SUBSET) {
- return otf_subset(emb->font->sfnt,emb->subset,output,context);
- } else if (emb->font->sfnt->numTTC) { //
- return otf_ttc_extract(emb->font->sfnt,output,context);
- } else { // copy verbatim
- return copy_file(emb->font->sfnt->f,output,context);
- }
- } else if (emb->outtype==EMB_FMT_OTF) {
- if (emb->plan&EMB_A_CFF_TO_OTF) {
- if (emb->plan&EMB_A_T1_TO_CFF) {
+ if (emb->plan & EMB_A_SUBSET)
+ return (otf_subset(emb->font->sfnt, emb->subset, output, context));
+ else if (emb->font->sfnt->numTTC)
+ return (otf_ttc_extract(emb->font->sfnt, output, context));
+ else // copy verbatim
+ return (copy_file(emb->font->sfnt->f, output, context));
+ }
+ else if (emb->outtype == EMB_FMT_OTF)
+ {
+ if (emb->plan&EMB_A_CFF_TO_OTF)
+ {
+ if (emb->plan&EMB_A_T1_TO_CFF)
+ {
// TODO
- } else {
+ }
+ else
+ {
// DEBUG_assert(emb->font->cff);
// TODO
}
- } else {
+ }
+ else
+ {
DEBUG_assert(emb->font->sfnt);
- if (emb->plan&EMB_A_SUBSET) {
- return otf_subset_cff(emb->font->sfnt,emb->subset,output,context);
- } else {
- return copy_file(emb->font->sfnt->f,output,context);
- }
+ if (emb->plan & EMB_A_SUBSET)
+ return (otf_subset_cff(emb->font->sfnt, emb->subset, output,
+ context));
+ else
+ return (copy_file(emb->font->sfnt->f, output, context));
}
- } else if (emb->outtype==EMB_FMT_CFF) {
- if (emb->plan&EMB_A_OTF_TO_CFF) {
+ }
+ else if (emb->outtype == EMB_FMT_CFF)
+ {
+ if (emb->plan & EMB_A_OTF_TO_CFF)
+ {
DEBUG_assert(emb->font->sfnt);
- if (emb->plan&EMB_A_SUBSET) {
+ if (emb->plan & EMB_A_SUBSET)
+ {
// TODO
- } else {
- return otf_cff_extract(emb->font->sfnt,output,context);
}
- } else {
+ else
+ {
+ return (otf_cff_extract(emb->font->sfnt, output, context));
+ }
+ }
+ else
+ {
// TODO
}
}
}
- fprintf(stderr,"NOT IMPLEMENTED\n");
+ fprintf(stderr, "NOT IMPLEMENTED\n");
DEBUG_assert(0);
return -1;
}
// }}}
-void emb_close(EMB_PARAMS *emb) // {{{
+
+void
+emb_close(EMB_PARAMS *emb) // {{{
{
- if (emb) {
+ if (emb)
+ {
free(emb->subset);
- if (emb->plan&EMB_A_CLOSE_FONTFILE) {
+ if (emb->plan & EMB_A_CLOSE_FONTFILE)
fontfile_close(emb->font);
- }
free(emb);
}
}
// }}}
-
-#ifndef EMBED_H
-#define EMBED_H
+#ifndef _FONTEMBED_EMBED_H_
+#define _FONTEMBED_EMBED_H_
#include "bitset.h"
#include "fontfile.h"
#include "iofn.h"
-typedef enum { EMB_FMT_T1, // type1, with AFM/PFM,PFA/PFB
- EMB_FMT_TTF, // sfnt, for TTF(glyf)
- EMB_FMT_OTF, // sfnt+cff, for OTF(cff)
- EMB_FMT_CFF, // cff, for raw CFF
- EMB_FMT_STDFONT // don't embed (already present)
- } EMB_FORMAT;
-typedef enum { EMB_DEST_NATIVE, // just subsetting/conversion
- EMB_DEST_PS,
-// EMB_DEST_PS2,
-// EMB_DEST_PDF13,
- EMB_DEST_PDF16
- } EMB_DESTINATION;
-
-typedef enum { EMB_RIGHT_FULL=0, EMB_RIGHT_NONE=0x02,
- EMB_RIGHT_READONLY=0x04,
- EMB_RIGHT_NO_SUBSET=0x0100,
- EMB_RIGHT_BITMAPONLY=0x0200 } EMB_RIGHT_TYPE;
-
-typedef enum { EMB_A_MULTIBYTE=0x01, // embedd as multibyte font?
- EMB_A_SUBSET=0x02, // do subsetting?
- EMB_A_T1_TO_CFF=0x04, // convert Type1 to CFF?
- EMB_A_CFF_TO_OTF=0x08, // wrap CFF(from input or T1+CONVERT_CFF) in sfnt? (OTF)
- EMB_A_OTF_TO_CFF=0x10, // unwrap CFF
-
- EMB_A_CLOSE_FONTFILE=0x8000
- } EMB_ACTIONS;
-
-typedef enum { EMB_C_MUST_SUBSET=0x01, // (fail, when not possible)
- EMB_C_EDITABLE_SUBSET=0x02, // (...)
- EMB_C_NEVER_SUBSET=0x04, // (...)
-
- EMB_C_FORCE_MULTIBYTE=0x08, // always use multibyte fonts
-
- EMB_C_PDF_OT=0x10, // output TTF/OTF (esp. CFF to OTF)
- EMB_C_KEEP_T1=0x20, // don't convert T1 to CFF
-
- EMB_C_TAKE_FONTFILE=0x8000 // take ownership of fontfile
- } EMB_CONSTRAINTS;
-
-typedef struct _EMB_PARAMS {
+
+typedef enum
+{
+ EMB_FMT_T1, // type1, with AFM/PFM,PFA/PFB
+ EMB_FMT_TTF, // sfnt, for TTF(glyf)
+ EMB_FMT_OTF, // sfnt+cff, for OTF(cff)
+ EMB_FMT_CFF, // cff, for raw CFF
+ EMB_FMT_STDFONT // don't embed (already present)
+} EMB_FORMAT;
+
+typedef enum
+{
+ EMB_DEST_NATIVE, // just subsetting/conversion
+ EMB_DEST_PS,
+// EMB_DEST_PS2,
+// EMB_DEST_PDF13,
+ EMB_DEST_PDF16
+} EMB_DESTINATION;
+
+typedef enum
+{
+ EMB_RIGHT_FULL = 0,
+ EMB_RIGHT_NONE = 0x02,
+ EMB_RIGHT_READONLY = 0x04,
+ EMB_RIGHT_NO_SUBSET = 0x0100,
+ EMB_RIGHT_BITMAPONLY = 0x0200
+} EMB_RIGHT_TYPE;
+
+typedef enum
+{
+ EMB_A_MULTIBYTE = 0x01, // embedd as multibyte font?
+ EMB_A_SUBSET = 0x02, // do subsetting?
+ EMB_A_T1_TO_CFF = 0x04, // convert Type1 to CFF?
+ EMB_A_CFF_TO_OTF = 0x08, // wrap CFF(from input or T1+CONVERT_CFF) in sfnt?
+ // (OTF)
+ EMB_A_OTF_TO_CFF = 0x10, // unwrap CFF
+
+ EMB_A_CLOSE_FONTFILE = 0x8000
+} EMB_ACTIONS;
+
+typedef enum
+{
+ EMB_C_MUST_SUBSET = 0x01, // (fail, when not possible)
+ EMB_C_EDITABLE_SUBSET = 0x02, // (...)
+ EMB_C_NEVER_SUBSET = 0x04, // (...)
+
+ EMB_C_FORCE_MULTIBYTE = 0x08, // always use multibyte fonts
+
+ EMB_C_PDF_OT = 0x10, // output TTF/OTF (esp. CFF to OTF)
+ EMB_C_KEEP_T1 = 0x20, // don't convert T1 to CFF
+
+ EMB_C_TAKE_FONTFILE = 0x8000 // take ownership of fontfile
+} EMB_CONSTRAINTS;
+
+typedef struct _EMB_PARAMS
+{
EMB_FORMAT intype;
EMB_FORMAT outtype;
EMB_DESTINATION dest;
EMB_RIGHT_TYPE rights;
// public:
BITSET subset;
-
} EMB_PARAMS;
-EMB_PARAMS *emb_new(FONTFILE *font,EMB_DESTINATION dest,EMB_CONSTRAINTS mode);
-// emb_embedd does only the "binary" part
-int emb_embed(EMB_PARAMS *emb,OUTPUT_FN output,void *context); // returns number of bytes written
+
+EMB_PARAMS *emb_new(FONTFILE *font, EMB_DESTINATION dest, EMB_CONSTRAINTS mode);
+// emb_embed does only the "binary" part
+int emb_embed(EMB_PARAMS *emb, OUTPUT_FN output, void *context);
+ // returns number of bytes written
void emb_close(EMB_PARAMS *emb);
+
// TODO: encoding, TODO: ToUnicode
-static inline void emb_set(EMB_PARAMS *emb,int unicode,unsigned short gid) // {{{
+static inline void
+emb_set(EMB_PARAMS *emb,
+ int unicode,
+ unsigned short gid) // {{{
{
- if (emb->subset) {
- if (emb->plan&EMB_A_MULTIBYTE) {
- bit_set(emb->subset,gid);
- // ToUnicode.add(gid,unicode);
- } else {
+ if (emb->subset)
+ {
+ if (emb->plan & EMB_A_MULTIBYTE)
+ {
+ bit_set(emb->subset, gid);
+ // ToUnicode.add(gid, unicode);
+ }
+ else
+ {
// TODO ... encoding
}
}
}
// }}}
+
// TODO: encoding?, TODO: non-sfnt
-static inline unsigned short emb_get(EMB_PARAMS *emb,int unicode) // {{{ gid
+static inline unsigned short
+emb_get(EMB_PARAMS *emb, int unicode) // {{{ gid
{
- const unsigned short gid=otf_from_unicode(emb->font->sfnt,unicode);
- emb_set(emb,unicode,gid);
- return gid;
+ const unsigned short gid = otf_from_unicode(emb->font->sfnt, unicode);
+ emb_set(emb, unicode, gid);
+ return (gid);
}
// }}}
#include "embed-pdf.h"
-#endif
+#endif // !_FONTEMBED_EMBED_H_
#include "debug-internal.h"
#include <string.h>
+
//FONTFILE *fontfile_open(const char *filename);
-/*
+#if 0
FONTFILE *fontfile_open(const char *filename)
{
// TODO? check magic
if (...) {
}
}
-*/
+#endif // 0
+
FONTFILE *fontfile_open_sfnt(OTF_FILE *otf) // {{{
{
- if (!otf) {
+ if (!otf)
+ {
DEBUG_assert(0);
- return NULL;
+ return (NULL);
}
- FONTFILE *ret=calloc(1,sizeof(FONTFILE));
+ FONTFILE *ret = calloc(1, sizeof(FONTFILE));
- ret->sfnt=otf;
+ ret->sfnt = otf;
- return ret;
+ return (ret);
}
// }}}
-FONTFILE *fontfile_open_std(const char *name) // {{{
+
+FONTFILE *
+fontfile_open_std(const char *name) // {{{
{
DEBUG_assert(name);
- FONTFILE *ret=calloc(1,sizeof(FONTFILE));
+ FONTFILE *ret = calloc(1, sizeof(FONTFILE));
- ret->stdname=strdup(name);
+ ret->stdname = strdup(name);
- return ret;
+ return (ret);
}
// }}}
+
void fontfile_close(FONTFILE *ff) // {{{
{
- if (ff) {
+ if (ff)
+ {
otf_close(ff->sfnt);
// ??? cff_close(ff->cff);
free(ff->stdname);
-#ifndef _FONTFILE_H
-#define _FONTFILE_H
+#ifndef _FONTEMBED_FONTFILE_H_
+#define _FONTEMBED_FONTFILE_H_
#include "sfnt.h"
-struct _FONTFILE {
+struct _FONTFILE
+{
OTF_FILE *sfnt;
// ??? *cff;
char *stdname;
- union {
+ union
+ {
int fobj;
void *user;
};
FONTFILE *fontfile_open_std(const char *name);
void fontfile_close(FONTFILE *ff);
-#endif
+#endif // !_FONTEMBED_FONTFILE_H_
-#ifndef _FREQUENT_H
-#define _FREQUENT_H
+#ifndef _FONTEMBED_FREQUENT_H_
+#define _FONTEMBED_FREQUENT_H_
#include <stdint.h>
typedef struct _FREQUENT FREQUENT;
-// size is the precision/return size: it will find at most >size elements (i.e. all, if there) with frequency > 1/(size+1)
+// size is the precision/return size: it will find at most >size
+// elements (i.e. all, if there) with frequency > 1 / (size + 1)
FREQUENT *frequent_new(int size); // - just free() it
-void frequent_add(FREQUENT *freq,intptr_t key);
+void frequent_add(FREQUENT *freq, intptr_t key);
// might return INTPTR_MIN, if not populated
// this is only an approximation!
-intptr_t frequent_get(FREQUENT *freq,int pos); // 0 is "most frequent"
+intptr_t frequent_get(FREQUENT *freq, int pos); // 0 is "most frequent"
-#endif
+#endif // !_FONTEMBED_FREQUENT_H_
#include "debug-internal.h"
#include <stdlib.h>
+
// misra-gries
// http://www2.research.att.com/~marioh/papers/vldb08-2.pdf
-struct _FREQUENT {
- int size,czero;
+struct _FREQUENT
+{
+ int size, czero;
char sorted;
- struct { intptr_t key; int count,zero; } pair[];
+ struct
+ {
+ intptr_t key;
+ int count,
+ zero;
+ } pair[];
};
-// size is the precision/return size: in sequence with n _add(), it will find at most >size elements with occurence > n/(size+1) times
-FREQUENT *frequent_new(int size) // {{{ - just free() it
+
+// size is the precision/return size: in sequence with n _add(),
+// it will find at most >size elements with occurence > n/(size+1) times
+
+FREQUENT *
+frequent_new(int size) // {{{ - just free() it
{
DEBUG_assert(size>0);
- FREQUENT *ret=malloc(sizeof(ret[0])+sizeof(ret->pair[0])*size);
- if (!ret) {
- return NULL;
- }
- ret->size=size;
- ret->czero=0;
- ret->sorted=1;
+ FREQUENT *ret = malloc(sizeof(ret[0]) + sizeof(ret->pair[0]) * size);
+ if (!ret)
+ return (NULL);
+ ret->size = size;
+ ret->czero = 0;
+ ret->sorted = 1;
int iA;
- for (iA=0;iA<size;iA++) {
- ret->pair[iA].key=INTPTR_MIN;
- ret->pair[iA].count=0;
- ret->pair[iA].zero=0;
+ for (iA = 0; iA < size; iA ++)
+ {
+ ret->pair[iA].key = INTPTR_MIN;
+ ret->pair[iA].count = 0;
+ ret->pair[iA].zero = 0;
}
- return ret;
+ return (ret);
}
// }}}
-void frequent_add(FREQUENT *freq,intptr_t key) // {{{
+
+void
+frequent_add(FREQUENT *freq,
+ intptr_t key) // {{{
{
DEBUG_assert(freq);
- int iA,zero=-1;
- for (iA=freq->size-1;iA>=0;iA--) {
- if (freq->pair[iA].key==key) {
- freq->pair[iA].count++;
- freq->sorted=0;
+ int iA, zero = -1;
+ for (iA = freq->size - 1; iA >= 0; iA --)
+ {
+ if (freq->pair[iA].key == key)
+ {
+ freq->pair[iA].count ++;
+ freq->sorted = 0;
return;
- } else if (freq->pair[iA].count==freq->czero) {
- zero=iA;
}
+ else if (freq->pair[iA].count == freq->czero)
+ zero = iA;
}
- if (zero>=0) { // insert into set
- freq->pair[zero].key=key;
- freq->pair[zero].count++; // i.e. czero+1
- freq->pair[zero].zero=freq->czero;
- // if it was sorted, the free entries are at the end. zero points to the first free entry, because of the loop direction
- } else { // out-of-set count
- freq->czero++;
+ if (zero >= 0) // insert into set
+ {
+ freq->pair[zero].key = key;
+ freq->pair[zero].count ++; // i.e. czero + 1
+ freq->pair[zero].zero = freq->czero;
+ // if it was sorted, the free entries are at the end. zero points to the
+ // first free entry, because of the loop direction
}
+ else // out-of-set count
+ freq->czero ++;
}
// }}}
-static int frequent_cmp(const void *a,const void *b) // {{{
+
+static int
+frequent_cmp(const void *a, const void *b) // {{{
{
- const typeof(((FREQUENT *)0)->pair[0]) *aa=a;
- const typeof(((FREQUENT *)0)->pair[0]) *bb=b;
- return (bb->count-bb->zero)-(aa->count-aa->zero);
+ const typeof(((FREQUENT *)0)->pair[0]) *aa = a;
+ const typeof(((FREQUENT *)0)->pair[0]) *bb = b;
+ return ((bb->count - bb->zero) - (aa->count - aa->zero));
}
// }}}
+
// true frequency is somewhere between (count-zero) and count
-intptr_t frequent_get(FREQUENT *freq,int pos) // {{{
+
+intptr_t frequent_get(FREQUENT *freq, int pos) // {{{
{
DEBUG_assert(freq);
- if (!freq->sorted) {
+ if (!freq->sorted)
+ {
// sort by (count-zero)
- qsort(freq->pair,freq->size,sizeof(freq->pair[0]),frequent_cmp);
- freq->sorted=1;
+ qsort(freq->pair, freq->size, sizeof(freq->pair[0]), frequent_cmp);
+ freq->sorted = 1;
}
- if ( (pos<0)||(pos>=freq->size) ) {
- return INTPTR_MIN;
- }
- return freq->pair[pos].key;
+ if ((pos < 0) || (pos >= freq->size))
+ return (INTPTR_MIN);
+ return (freq->pair[pos].key);
}
// }}}
-
-#ifndef _IOFN_H
-#define _IOFN_H
+#ifndef _FONTEMBED_IOFN_H_
+#define _FONTEMBED_IOFN_H_
-typedef void (*OUTPUT_FN)(const char *buf,int len,void *context);
+typedef void (*OUTPUT_FN)(const char *buf, int len, void *context);
-#endif
+#endif // !_FONTEMBED_IOFN_H_
// data header only. for inclusion in only one file
+#ifndef _FONTEMBED_MACROMAN_PRIVATE_H_
+#define _FONTEMBED_MACROMAN_PRIVATE_H_
+
#ifdef WITH_MACROMAN
-static const char *macRoman[]=
- {".notdef",".null","nonmarkingreturn","space","exclam", "quotedbl","numbersign","dollar","percent","ampersand",
- "quotesingle","parenleft","parenright","asterisk","plus", "comma","hyphen","period","slash","zero",
- "one","two","three","four","five", "six","seven","eight","nine","colon",
- "semicolon","less","equal","greater","question", "at","A","B","C","D",
- "E","F","G","H","I", "J","K","L","M","N",
- "O","P","Q","R","S", "T","U","V","W","X",
- "Y","Z","bracketleft","backslash","bracketright", "asciicircum","underscore","grave","a","b",
- "c","d","e","f","g", "h","i","j","k","l",
- "m","n","o","p","q", "r","s","t","u","v",
- "w","x","y","z","braceleft", "bar","braceright","asciitilde","Adieresis","Aring",
- "Ccedilla","Eacute","Ntilde","Odieresis","Udieresis", "aacute","agrave","acircumflex","adieresis","atilde",
- "aring","ccedilla","eacute","egrave","ecircumflex", "edieresis","iacute","igrave","icircumflex","idieresis",
- "ntilde","oacute","ograve","ocircumflex","odieresis", "otilde","uacute","ugrave","ucircumflex","udieresis",
- "dagger","degree","cent","sterling","section", "bullet","paragraph","germandbls","registered","copyright",
- "trademark","acute","dieresis","notequal","AE", "Oslash","infinity","plusminus","lessequal","greaterequal",
- "yen","mu","partialdiff","summation","product", "pi","integral","ordfeminine","ordmasculine","Omega",
- "ae","oslash","questiondown","exclamdown","logicalnot", "radical","florin","approxequal","Delta","guillemotleft",
- "guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde", "Otilde","OE","oe","endash","emdash",
- "quotedblleft","quotedblright","quoteleft","quoteright","divide", "lozenge","ydieresis","Ydieresis","fraction","currency",
- "guilsinglleft","guilsinglright","fi","fl","daggerdbl", "periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex",
- "Ecircumflex","Aacute","Edieresis","Egrave","Iacute", "Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex",
- "apple","Ograve","Uacute","Ucircumflex","Ugrave", "dotlessi","circumflex","tilde","macron","breve",
- "dotaccent","ring","cedilla","hungarumlaut","ogonek", "caron","Lslash","lslash","Scaron","scaron",
- "Zcaron","zcaron","brokenbar","Eth","eth", "Yacute","yacute","Thorn","thorn","minus","multiply",
- "onesuperior","twosuperior","threesuperior","onehalf","onequarter", "threequarters","franc","Gbreve","gbreve","Idotaccent",
- "Scedilla","scedilla","Cacute","cacute","Ccaron", "ccaron","dcroat"};
+static const char *macRoman[] =
+{
+ ".notdef", ".null", "nonmarkingreturn", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand",
+ "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero",
+ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon",
+ "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D",
+ "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
+ "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
+ "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b",
+ "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
+ "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
+ "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "Adieresis", "Aring",
+ "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde",
+ "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis",
+ "ntilde", "oacute", "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis",
+ "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls", "registered", "copyright",
+ "trademark", "acute", "dieresis", "notequal", "AE", "Oslash", "infinity", "plusminus", "lessequal", "greaterequal",
+ "yen", "mu", "partialdiff", "summation", "product", "pi", "integral", "ordfeminine", "ordmasculine", "Omega",
+ "ae", "oslash", "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "Delta", "guillemotleft",
+ "guillemotright", "ellipsis", "nonbreakingspace", "Agrave", "Atilde", "Otilde", "OE", "oe", "endash", "emdash",
+ "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", "lozenge", "ydieresis", "Ydieresis", "fraction", "currency",
+ "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex",
+ "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex",
+ "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", "circumflex", "tilde", "macron", "breve",
+ "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash", "Scaron", "scaron",
+ "Zcaron", "zcaron", "brokenbar", "Eth", "eth", "Yacute", "yacute", "Thorn", "thorn", "minus", "multiply",
+ "onesuperior", "twosuperior", "threesuperior", "onehalf", "onequarter", "threequarters", "franc", "Gbreve", "gbreve", "Idotaccent",
+ "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", "ccaron", "dcroat"
+};
#else
-static const char *macRoman[]={0};
-#endif
+static const char *macRoman[] =
+{
+ NULL
+};
+#endif // WITH_MACROMAN
+
+#endif // !_FONTEMBED_MACROMAN_PRIVATE_H_
-#ifndef _SFNT_INT_H
-#define _SFNT_INT_H
+#ifndef _FONTEMBED_SFNT_INT_H_
+#define _FONTEMBED_SFNT_INT_H_
-static inline unsigned short get_USHORT(const char *buf) // {{{
+
+static inline unsigned short
+get_USHORT(const char *buf) // {{{
{
- return ((unsigned char)buf[0]<<8)|((unsigned char)buf[1]);
+ return (((unsigned char)buf[0] << 8) | ((unsigned char)buf[1]));
}
// }}}
-static inline short get_SHORT(const char *buf) // {{{
+
+
+static inline short
+get_SHORT(const char *buf) // {{{
{
- return (buf[0]<<8)|((unsigned char)buf[1]);
+ return ((buf[0] << 8) | ((unsigned char)buf[1]));
}
// }}}
-static inline unsigned int get_UINT24(const char *buf) // {{{
+
+
+static inline unsigned int
+get_UINT24(const char *buf) // {{{
{
- return ((unsigned char)buf[0]<<16)|
- ((unsigned char)buf[1]<<8)|
- ((unsigned char)buf[2]);
+ return (((unsigned char)buf[0] << 16) |
+ ((unsigned char)buf[1] << 8 )|
+ ((unsigned char)buf[2]));
}
// }}}
-static inline unsigned int get_ULONG(const char *buf) // {{{
+
+
+static inline unsigned int
+get_ULONG(const char *buf) // {{{
{
- return ((unsigned char)buf[0]<<24)|
- ((unsigned char)buf[1]<<16)|
- ((unsigned char)buf[2]<<8)|
- ((unsigned char)buf[3]);
+ return (((unsigned char)buf[0] << 24) |
+ ((unsigned char)buf[1] << 16) |
+ ((unsigned char)buf[2] << 8) |
+ ((unsigned char)buf[3]));
}
// }}}
-static inline int get_LONG(const char *buf) // {{{
+
+
+static inline int
+get_LONG(const char *buf) // {{{
{
- return (buf[0]<<24)|
- ((unsigned char)buf[1]<<16)|
- ((unsigned char)buf[2]<<8)|
- ((unsigned char)buf[3]);
+ return ((buf[0] << 24) |
+ ((unsigned char)buf[1] << 16) |
+ ((unsigned char)buf[2] << 8) |
+ ((unsigned char)buf[3]));
}
// }}}
-static inline void set_USHORT(char *buf,unsigned short val) // {{{
+
+static inline void
+set_USHORT(char *buf,
+ unsigned short val) // {{{
{
- buf[0]=val>>8;
- buf[1]=val&0xff;
+ buf[0] = val >> 8;
+ buf[1] = val & 0xff;
}
+
+
// }}}
-static inline void set_ULONG(char *buf,unsigned int val) // {{{
+static inline void
+set_ULONG(char *buf,
+ unsigned int val) // {{{
{
- buf[0]=val>>24;
- buf[1]=(val>>16)&0xff;
- buf[2]=(val>>8)&0xff;
- buf[3]=val&0xff;
+ buf[0] = val >> 24;
+ buf[1] = (val >> 16) & 0xff;
+ buf[2] = (val >> 8) & 0xff;
+ buf[3] = val & 0xff;
}
// }}}
-static inline unsigned int otf_checksum(const char *buf, unsigned int len) // {{{
+
+static inline unsigned int
+otf_checksum(const char *buf,
+ unsigned int len) // {{{
{
- unsigned int ret=0;
- for (len=(len+3)/4;len>0;len--,buf+=4) {
- ret+=get_ULONG(buf);
- }
- return ret;
+ unsigned int ret = 0;
+ for (len = (len + 3) / 4; len > 0; len--, buf += 4)
+ ret += get_ULONG(buf);
+ return (ret);
}
// }}}
-static inline int get_width_fast(OTF_FILE *otf,int gid) // {{{
+
+
+static inline int
+get_width_fast(OTF_FILE *otf,
+ int gid) // {{{
{
- if (gid>=otf->numberOfHMetrics) {
- return get_USHORT(otf->hmtx+(otf->numberOfHMetrics-1)*4);
- } else {
- return get_USHORT(otf->hmtx+gid*4);
- }
+ if (gid >= otf->numberOfHMetrics)
+ return (get_USHORT(otf->hmtx + (otf->numberOfHMetrics - 1) * 4));
+ else
+ return (get_USHORT(otf->hmtx + gid * 4));
}
// }}}
+
int otf_load_glyf(OTF_FILE *otf); // - 0 on success
int otf_load_more(OTF_FILE *otf); // - 0 on success
-int otf_find_table(OTF_FILE *otf,unsigned int tag); // - table_index or -1 on error
+int otf_find_table(OTF_FILE *otf, unsigned int tag); // - table_index or
+ // -1 on error
+
+int otf_action_copy(void *param, int csum, OUTPUT_FN output, void *context);
+int otf_action_replace(void *param, int csum, OUTPUT_FN output, void *context);
-int otf_action_copy(void *param,int csum,OUTPUT_FN output,void *context);
-int otf_action_replace(void *param,int csum,OUTPUT_FN output,void *context);
+// Note: don't use this directly. otf_write_sfnt will internally replace
+// otf_action_copy for head with this
+int otf_action_copy_head(void *param, int csum, OUTPUT_FN output,
+ void *context);
-// Note: don't use this directly. otf_write_sfnt will internally replace otf_action_copy for head with this
-int otf_action_copy_head(void *param,int csum,OUTPUT_FN output,void *context);
-struct _OTF_WRITE {
+struct _OTF_WRITE
+{
unsigned long tag;
- int (*action)(void *param,int length,OUTPUT_FN output,void *context); // -1 on error, num_bytes_written on success; if >output==NULL return checksum in (unsigned int *)context instead.
+ int (*action)(void *param, int length, OUTPUT_FN output, void *context);
+ // -1 on error, num_bytes_written on success; if >output == NULL
+ // return checksum in (unsigned int *)context instead.
void *param;
int length;
};
-int otf_write_sfnt(struct _OTF_WRITE *otw,unsigned int version,int numTables,OUTPUT_FN output,void *context);
+
+int otf_write_sfnt(struct _OTF_WRITE *otw, unsigned int version, int numTables,
+ OUTPUT_FN output, void *context);
/** from sfnt_subset.c: **/
-// otw {0,}-terminated, will be modified; returns numTables for otf_write_sfnt
-int otf_intersect_tables(OTF_FILE *otf,struct _OTF_WRITE *otw);
+// otw {0, }-terminated, will be modified; returns numTables for otf_write_sfnt
+int otf_intersect_tables(OTF_FILE *otf, struct _OTF_WRITE *otw);
-#endif
+#endif // !_FONTEMBED_SFNT_INT_H_
#include <string.h>
#include <errno.h>
-int otf_ttc_extract(OTF_FILE *otf,OUTPUT_FN output,void *context) // {{{
+
+int
+otf_ttc_extract(OTF_FILE *otf,
+ OUTPUT_FN output,
+ void *context) // {{{
{
DEBUG_assert(otf);
DEBUG_assert(output);
DEBUG_assert(otf->numTTC);
+
int iA;
struct _OTF_WRITE *otw;
- otw=malloc(sizeof(struct _OTF_WRITE)*otf->numTables);
- if (!otw) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- return -1;
+ otw = malloc(sizeof(struct _OTF_WRITE) * otf->numTables);
+ if (!otw)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
+ return (-1);
}
// just copy everything
- for (iA=0;iA<otf->numTables;iA++) {
- otw[iA].tag=otf->tables[iA].tag;
- otw[iA].action=otf_action_copy;
- otw[iA].param=otf;
- otw[iA].length=iA;
+ for (iA = 0; iA < otf->numTables; iA ++)
+ {
+ otw[iA].tag = otf->tables[iA].tag;
+ otw[iA].action = otf_action_copy;
+ otw[iA].param = otf;
+ otw[iA].length = iA;
}
- iA=otf_write_sfnt(otw,otf->version,otf->numTables,output,context);
+ iA = otf_write_sfnt(otw, otf->version, otf->numTables, output, context);
free(otw);
- return iA;
+ return (iA);
}
// }}}
-// otw {0,}-terminated, will be modified; returns numTables for otf_write_sfnt
-int otf_intersect_tables(OTF_FILE *otf,struct _OTF_WRITE *otw) // {{{
+// otw {0, }-terminated, will be modified; returns numTables for otf_write_sfnt
+int
+otf_intersect_tables(OTF_FILE *otf,
+ struct _OTF_WRITE *otw) // {{{
{
- int iA,iB,numTables=0;
- for (iA=0,iB=0;(iA<otf->numTables)&&(otw[iB].tag);) {
- if (otf->tables[iA].tag==otw[iB].tag) {
- if (otw[iB].action==otf_action_copy) {
- otw[iB].length=iA; // original table location found.
- }
- if (iB!=numTables) { // >, actually
- memmove(otw+numTables,otw+iB,sizeof(struct _OTF_WRITE));
+ int iA, iB, numTables = 0;
+
+ for (iA = 0, iB = 0; (iA < otf->numTables) && (otw[iB].tag);)
+ {
+ if (otf->tables[iA].tag == otw[iB].tag)
+ {
+ if (otw[iB].action == otf_action_copy)
+ otw[iB].length = iA; // original table location found.
+ if (iB != numTables) // >, actually
+ memmove(otw + numTables, otw + iB, sizeof(struct _OTF_WRITE));
+ iA ++;
+ iB ++;
+ numTables ++;
+ }
+ else if (otf->tables[iA].tag < otw[iB].tag)
+ iA ++;
+ else // not in otf->tables
+ {
+ if (otw[iB].action != otf_action_copy) // keep
+ {
+ if (iB != numTables) // >, actually
+ memmove(otw + numTables, otw + iB, sizeof(struct _OTF_WRITE));
+ numTables ++;
}
- iA++;
- iB++;
- numTables++;
- } else if (otf->tables[iA].tag<otw[iB].tag) {
- iA++;
- } else { // not in otf->tables
- if (otw[iB].action!=otf_action_copy) { // keep
- if (iB!=numTables) { // >, actually
- memmove(otw+numTables,otw+iB,sizeof(struct _OTF_WRITE));
- }
- numTables++;
- } // else delete
- iB++;
+ // else delete
+ iB ++;
}
}
- return numTables;
+ return (numTables);
}
// }}}
-// include components (set bit in >glyphs) of currently loaded compound glyph (with >curgid)
+// include components (set bit in >glyphs) of currently loaded compound glyph
+// (with >curgid)
// returns additional space requirements (when bits below >donegid are touched)
-static int otf_subset_glyf(OTF_FILE *otf,int curgid,int donegid,BITSET glyphs) // {{{
+
+static int
+otf_subset_glyf(OTF_FILE *otf,
+ int curgid,
+ int donegid,
+ BITSET glyphs) // {{{
{
- int ret=0;
- if (get_SHORT(otf->gly)>=0) { // not composite
- return ret; // done
- }
+ int ret = 0;
+ if (get_SHORT(otf->gly) >= 0) // not composite
+ return (ret); // done
- char *cur=otf->gly+10;
+ char *cur = otf->gly + 10;
unsigned short flags;
- do {
- flags=get_USHORT(cur);
- const unsigned short sub_gid=get_USHORT(cur+2);
- DEBUG_assert(sub_gid<otf->numGlyphs);
- if (!bit_check(glyphs,sub_gid)) {
+ do
+ {
+ flags = get_USHORT(cur);
+ const unsigned short sub_gid = get_USHORT(cur + 2);
+ DEBUG_assert(sub_gid < otf->numGlyphs);
+ if (!bit_check(glyphs, sub_gid))
+ {
// bad: temporarily load sub glyph
- const int len=otf_get_glyph(otf,sub_gid);
- DEBUG_assert(len>0);
- bit_set(glyphs,sub_gid);
- if (sub_gid<donegid) {
- ret+=len;
- ret+=otf_subset_glyf(otf,sub_gid,donegid,glyphs); // composite of composites?, e.g. in DejaVu
+ const int len = otf_get_glyph(otf, sub_gid);
+ DEBUG_assert(len > 0);
+ bit_set(glyphs, sub_gid);
+ if (sub_gid < donegid)
+ {
+ ret += len;
+ ret += otf_subset_glyf(otf, sub_gid, donegid, glyphs);
+ // composite of composites?, e.g. in DejaVu
}
#ifdef DEBUG
const int res =
#endif
- otf_get_glyph(otf,curgid); // reload current glyph
+ otf_get_glyph(otf, curgid); // reload current glyph
DEBUG_assert(res);
}
// skip parameters
- cur+=6;
- if (flags&0x01) {
- cur+=2;
- }
- if (flags&0x08) {
- cur+=2;
- } else if (flags&0x40) {
- cur+=4;
- } else if (flags&0x80) {
- cur+=8;
- }
- } while (flags&0x20); // more components
+ cur += 6;
+ if (flags & 0x01)
+ cur += 2;
+ if (flags & 0x08)
+ cur += 2;
+ else if (flags & 0x40)
+ cur += 4;
+ else if (flags & 0x80)
+ cur += 8;
+ }
+ while (flags & 0x20); // more components
- return ret;
+ return (ret);
}
// }}}
+
// TODO: cmap only required in non-CID context
-int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{{ - returns number of bytes written
+
+int
+otf_subset(OTF_FILE *otf,
+ BITSET glyphs,
+ OUTPUT_FN output,
+ void *context) // {{{ - returns number of bytes written
{
DEBUG_assert(otf);
DEBUG_assert(glyphs);
DEBUG_assert(output);
- int iA,b,c;
+ int iA, b, c;
// first pass: include all required glyphs
- bit_set(glyphs,0); // .notdef always required
- int glyfSize=0;
- for (iA=0,b=0,c=1;iA<otf->numGlyphs;iA++,c<<=1) {
- if (!c) {
- b++;
- c=1;
+ bit_set(glyphs, 0); // .notdef always required
+ int glyfSize = 0;
+ for (iA = 0, b = 0, c = 1; iA < otf->numGlyphs; iA ++, c <<= 1)
+ {
+ if (!c)
+ {
+ b ++;
+ c = 1;
}
- if (glyphs[b]&c) {
- int len=otf_get_glyph(otf,iA);
- if (len<0) {
+ if (glyphs[b] & c)
+ {
+ int len = otf_get_glyph(otf, iA);
+ if (len < 0)
+ {
DEBUG_assert(0);
- return -1;
- } else if (len>0) {
- glyfSize+=len;
- len=otf_subset_glyf(otf,iA,iA,glyphs);
- if (len<0) {
+ return (-1);
+ }
+ else if (len > 0)
+ {
+ glyfSize += len;
+ len = otf_subset_glyf(otf, iA, iA, glyphs);
+ if (len < 0)
+ {
DEBUG_assert(0);
- return -1;
+ return (-1);
}
- glyfSize+=len;
+ glyfSize += len;
}
}
}
// second pass: calculate new glyf and loca
- int locaSize=(otf->numGlyphs+1)*(otf->indexToLocFormat+1)*2;
+ int locaSize = (otf->numGlyphs + 1) * (otf->indexToLocFormat + 1) * 2;
- char *new_loca=malloc(locaSize);
- char *new_glyf=malloc(glyfSize);
- if ( (!new_loca)||(!new_glyf) ) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
+ char *new_loca = malloc(locaSize);
+ char *new_glyf = malloc(glyfSize);
+ if ((!new_loca) || (!new_glyf))
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
DEBUG_assert(0);
free(new_loca);
free(new_glyf);
- return -1;
+ return (-1);
}
- int offset=0;
- for (iA=0,b=0,c=1;iA<otf->numGlyphs;iA++,c<<=1) {
- if (!c) {
- b++;
- c=1;
- }
-
- DEBUG_assert(offset%2==0);
- // TODO? change format? if glyfSize<0x20000
- if (otf->indexToLocFormat==0) {
- set_USHORT(new_loca+iA*2,offset/2);
- } else { // ==1
- set_ULONG(new_loca+iA*4,offset);
+ int offset = 0;
+ for (iA = 0, b = 0, c = 1; iA < otf->numGlyphs; iA ++, c <<= 1)
+ {
+ if (!c)
+ {
+ b ++;
+ c = 1;
}
- if (glyphs[b]&c) {
- const int len=otf_get_glyph(otf,iA);
- DEBUG_assert(len>=0);
- memcpy(new_glyf+offset,otf->gly,len);
- offset+=len;
+ DEBUG_assert(offset % 2 == 0);
+ // TODO? change format? if glyfSize < 0x20000
+ if (otf->indexToLocFormat == 0)
+ set_USHORT(new_loca + iA * 2, offset / 2);
+ else // ==1
+ set_ULONG(new_loca + iA * 4, offset);
+
+ if (glyphs[b] & c)
+ {
+ const int len = otf_get_glyph(otf, iA);
+ DEBUG_assert(len >= 0);
+ memcpy(new_glyf + offset, otf->gly, len);
+ offset += len;
}
}
// last entry
- if (otf->indexToLocFormat==0) {
- set_USHORT(new_loca+otf->numGlyphs*2,offset/2);
- } else { // ==1
- set_ULONG(new_loca+otf->numGlyphs*4,offset);
- }
- DEBUG_assert(offset==glyfSize);
+ if (otf->indexToLocFormat == 0)
+ set_USHORT(new_loca + otf->numGlyphs * 2, offset / 2);
+ else // ==1
+ set_ULONG(new_loca + otf->numGlyphs * 4, offset);
+ DEBUG_assert(offset == glyfSize);
// determine new tables.
- struct _OTF_WRITE otw[]={ // sorted
+ struct _OTF_WRITE otw[] = // sorted
+ {
// TODO: cmap only required in non-CID context or always in CFF
- {OTF_TAG('c','m','a','p'),otf_action_copy,otf,},
- {OTF_TAG('c','v','t',' '),otf_action_copy,otf,},
- {OTF_TAG('f','p','g','m'),otf_action_copy,otf,},
- {OTF_TAG('g','l','y','f'),otf_action_replace,new_glyf,glyfSize},
- {OTF_TAG('h','e','a','d'),otf_action_copy,otf,}, // _copy_head
- {OTF_TAG('h','h','e','a'),otf_action_copy,otf,},
- {OTF_TAG('h','m','t','x'),otf_action_copy,otf,},
- {OTF_TAG('l','o','c','a'),otf_action_replace,new_loca,locaSize},
- {OTF_TAG('m','a','x','p'),otf_action_copy,otf,},
- {OTF_TAG('n','a','m','e'),otf_action_copy,otf,},
- {OTF_TAG('p','r','e','p'),otf_action_copy,otf,},
- // vhea vmtx (never used in PDF, but possible in PS>=3011)
- {0,0,0,0}};
+ {OTF_TAG('c', 'm', 'a', 'p'), otf_action_copy, otf, },
+ {OTF_TAG('c', 'v', 't', ' '), otf_action_copy, otf, },
+ {OTF_TAG('f', 'p', 'g', 'm'), otf_action_copy, otf, },
+ {OTF_TAG('g', 'l', 'y', 'f'), otf_action_replace, new_glyf, glyfSize},
+ {OTF_TAG('h', 'e', 'a', 'd'), otf_action_copy, otf, }, // _copy_head
+ {OTF_TAG('h', 'h', 'e', 'a'), otf_action_copy, otf, },
+ {OTF_TAG('h', 'm', 't', 'x'), otf_action_copy, otf, },
+ {OTF_TAG('l', 'o', 'c', 'a'), otf_action_replace, new_loca, locaSize},
+ {OTF_TAG('m', 'a', 'x', 'p'), otf_action_copy, otf, },
+ {OTF_TAG('n', 'a', 'm', 'e'), otf_action_copy, otf, },
+ {OTF_TAG('p', 'r', 'e', 'p'), otf_action_copy, otf, },
+ // vhea vmtx (never used in PDF, but possible in PS>=3011)
+ {0, 0, 0, 0}
+ };
// and write them
- int numTables=otf_intersect_tables(otf,otw);
- int ret=otf_write_sfnt(otw,otf->version,numTables,output,context);
+ int numTables = otf_intersect_tables(otf, otw);
+ int ret = otf_write_sfnt(otw, otf->version, numTables, output, context);
free(new_loca);
free(new_glyf);
- return ret;
+ return (ret);
//TODO ? reduce cmap [to (1,0) ;-)]
//TODO (cmap for non-cid)
}
// }}}
+
// TODO no subsetting actually done (for now)
-int otf_subset_cff(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context) // {{{ - returns number of bytes written
+
+int
+otf_subset_cff(OTF_FILE *otf,
+ BITSET glyphs,
+ OUTPUT_FN output,
+ void *context) // {{{ - returns number of bytes written
{
DEBUG_assert(otf);
DEBUG_assert(output);
-// TODO char *new_cff=cff_subset(...);
+ // TODO char *new_cff = cff_subset(...);
// determine new tables.
- struct _OTF_WRITE otw[]={
- {OTF_TAG('C','F','F',' '),otf_action_copy,otf,},
-// {OTF_TAG('C','F','F',' '),otf_action_replace,new_glyf,glyfSize},
- {OTF_TAG('c','m','a','p'),otf_action_copy,otf,},
+ struct _OTF_WRITE otw[] =
+ {
+ {OTF_TAG('C', 'F', 'F', ' '), otf_action_copy, otf, },
+// {OTF_TAG('C', 'F', 'F', ' '), otf_action_replace, new_glyf, glyfSize},
+ {OTF_TAG('c', 'm', 'a', 'p'), otf_action_copy, otf, },
#if 0 // not actually needed!
- {OTF_TAG('c','v','t',' '),otf_action_copy,otf,},
- {OTF_TAG('f','p','g','m'),otf_action_copy,otf,},
- {OTF_TAG('h','e','a','d'),otf_action_copy,otf,}, // _copy_head
- {OTF_TAG('h','h','e','a'),otf_action_copy,otf,},
- {OTF_TAG('h','m','t','x'),otf_action_copy,otf,},
- {OTF_TAG('m','a','x','p'),otf_action_copy,otf,},
- {OTF_TAG('n','a','m','e'),otf_action_copy,otf,},
- {OTF_TAG('p','r','e','p'),otf_action_copy,otf,},
-#endif
- {0,0,0,0}};
+ {OTF_TAG('c', 'v', 't', ' '), otf_action_copy, otf, },
+ {OTF_TAG('f', 'p', 'g', 'm'), otf_action_copy, otf, },
+ {OTF_TAG('h', 'e', 'a', 'd'), otf_action_copy, otf, }, // _copy_head
+ {OTF_TAG('h', 'h', 'e', 'a'), otf_action_copy, otf, },
+ {OTF_TAG('h', 'm', 't', 'x'), otf_action_copy, otf, },
+ {OTF_TAG('m', 'a', 'x', 'p'), otf_action_copy, otf, },
+ {OTF_TAG('n', 'a', 'm', 'e'), otf_action_copy, otf, },
+ {OTF_TAG('p', 'r', 'e', 'p'), otf_action_copy, otf, },
+#endif // 0
+ {0, 0, 0, 0}
+ };
// and write them
- int numTables=otf_intersect_tables(otf,otw);
- int ret=otf_write_sfnt(otw,otf->version,numTables,output,context);
+ int numTables = otf_intersect_tables(otf, otw);
+ int ret = otf_write_sfnt(otw, otf->version, numTables, output, context);
// free(new_cff);
- return ret;
+ return (ret);
}
// }}}
-//int copy_block(FILE *f,long pos,int length,OUTPUT_FN output,void *context); // copied bytes or -1 (also on premature EOF)
+//int copy_block(FILE *f, long pos, int length, OUTPUT_FN output,
+// void *context); // copied bytes or -1 (also on premature EOF)
-static int copy_block(FILE *f,long pos,int length,OUTPUT_FN output,void *context) // {{{
+static int
+copy_block(FILE *f,
+ long pos,
+ int length,
+ OUTPUT_FN output,
+ void *context) // {{{
{
DEBUG_assert(f);
DEBUG_assert(output);
char buf[4096];
- int iA,ret;
+ int iA, ret;
- ret=fseek(f,pos,SEEK_SET);
- if (ret==-1) {
- fprintf(stderr,"Seek failed: %s\n", strerror(errno));
- return -1;
+ ret = fseek(f, pos, SEEK_SET);
+ if (ret == -1)
+ {
+ fprintf(stderr, "Seek failed: %s\n", strerror(errno));
+ return (-1);
}
- ret=0;
- while (length>4096) {
- iA=fread(buf,1,4096,f);
- if (iA<4096) {
- return -1;
- }
- (*output)(buf,iA,context);
- ret+=iA;
- length-=iA;
- };
- iA=fread(buf,1,length,f);
- if (iA<length) {
- return -1;
+ ret = 0;
+ while (length > 4096)
+ {
+ iA = fread(buf, 1, 4096, f);
+ if (iA < 4096)
+ return (-1);
+ (*output)(buf, iA, context);
+ ret += iA;
+ length -= iA;
}
- (*output)(buf,iA,context);
- ret+=iA;
+ iA = fread(buf, 1, length, f);
+ if (iA < length)
+ return (-1);
+ (*output)(buf, iA, context);
+ ret += iA;
- return ret;
+ return (ret);
}
// }}}
-int otf_cff_extract(OTF_FILE *otf,OUTPUT_FN output,void *context) // {{{ - returns number of bytes written
+int
+otf_cff_extract(OTF_FILE *otf,
+ OUTPUT_FN output,
+ void *context) // {{{ - returns number of bytes written
{
DEBUG_assert(otf);
DEBUG_assert(output);
- int idx=otf_find_table(otf,OTF_TAG('C','F','F',' '));
- if (idx==-1) {
- return -1;
- }
- const OTF_DIRENT *table=otf->tables+idx;
+ int idx = otf_find_table(otf, OTF_TAG('C', 'F', 'F', ' '));
+ if (idx == -1)
+ return (-1);
+
+ const OTF_DIRENT *table = otf->tables + idx;
- return copy_block(otf->f,table->offset,table->length,output,context);
+ return (copy_block(otf->f, table->offset, table->length, output, context));
}
// }}}
+
// CFF *otf_get_cff(); // not load, but create by "substream"-in ctor
+
#if 0 // TODO elsewhere : char *cff_subset(...);
// first pass: include all required glyphs
- bit_set(glyphs,0); // .notdef always required
- int glyfSize=0;
- for (iA=0,b=0,c=1;iA<otf->numGlyphs;iA++,c<<=1) {
- if (!c) {
- b++;
- c=1;
+ bit_set(glyphs, 0); // .notdef always required
+ int glyfSize = 0;
+ for (iA = 0, b = 0, c = 1; iA < otf->numGlyphs; iA ++, c <<= 1)
+ {
+ if (!c)
+ {
+ b ++;
+ c = 1;
}
- if (glyphs[b]&c) {
-// TODO: cff_glyph
+ if (glyphs[b] & c)
+ {
+ // TODO: cff_glyph
}
}
// second pass: calculate new glyf and loca
- char *new_cff=malloc(cffSize);
- if (!new_cff) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
+ char *new_cff = malloc(cffSize);
+ if (!new_cff)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
DEBUG_assert(0);
- return -1;
+ return (-1);
}
- int offset=0;
- for (iA=0,b=0,c=1;iA<otf->numGlyphs;iA++,c<<=1) {
- if (!c) {
- b++;
- c=1;
+ int offset = 0;
+ for (iA = 0, b = 0, c = 1; iA < otf->numGlyphs; iA ++, c <<= 1)
+ {
+ if (!c)
+ {
+ b ++;
+ c = 1;
}
- if (glyphs[b]&c) {
-//...
+ if (glyphs[b] & c)
+ {
+ //...
}
}
- return new_cff;
-#endif
+ return (new_cff);
+#endif // 0
#include <string.h>
#include <errno.h>
+
// TODO?
-// get_SHORT(head+48) // fontDirectionHint
-/* reqd. Tables: cmap, head, hhea, hmtx, maxp, name, OS/2, post
- OTF: glyf,loca [cvt,fpgm,prep]
- */
-
-static void otf_bsearch_params(int num, // {{{
- int recordSize,
- int *searchRange,
- int *entrySelector,
- int *rangeShift)
+// get_SHORT(head + 48) // fontDirectionHint
+// reqd. Tables: cmap, head, hhea, hmtx, maxp, name, OS/2, post
+// OTF: glyf, loca [cvt, fpgm, prep]
+//
+
+static void
+otf_bsearch_params(int num, // {{{
+ int recordSize,
+ int *searchRange,
+ int *entrySelector,
+ int *rangeShift)
{
- DEBUG_assert(num>0);
+ DEBUG_assert(num > 0);
DEBUG_assert(searchRange);
DEBUG_assert(entrySelector);
DEBUG_assert(rangeShift);
- int iA,iB;
- for (iA=1,iB=0;iA<=num;iA<<=1,iB++) {}
+ int iA, iB;
+ for (iA = 1, iB = 0; iA <= num; iA <<= 1, iB ++);
- *searchRange=iA*recordSize/2;
- *entrySelector=iB-1;
- *rangeShift=num*recordSize-*searchRange;
+ *searchRange = iA * recordSize / 2;
+ *entrySelector = iB - 1;
+ *rangeShift = num * recordSize - *searchRange;
}
// }}}
-static char *otf_bsearch(char *table, // {{{
- const char *target,int len,
- int searchRange,
- int entrySelector,
- int rangeShift,
- int lower_bound) // return lower_bound, if !=0
-{
- char *ret=table+rangeShift;
- if (memcmp(target,ret,len)<0) {
- ret=table;
- }
- for (;entrySelector>0;entrySelector--) {
- searchRange>>=1;
- ret+=searchRange;
- if (memcmp(target,ret,len)<0) {
- ret-=searchRange;
- }
- }
- const int result=memcmp(target,ret,len);
- if (result==0) {
- return ret;
- } else if (lower_bound) {
- if (result>0) {
- return ret+searchRange;
- }
- return ret;
- }
- return NULL; // not found;
+static char *
+otf_bsearch(char *table, // {{{
+ const char *target,
+ int len,
+ int searchRange,
+ int entrySelector,
+ int rangeShift,
+ int lower_bound) // return lower_bound, if !=0
+{
+ char *ret = table + rangeShift;
+ if (memcmp(target, ret, len) < 0)
+ ret = table;
+
+ for (; entrySelector > 0; entrySelector --)
+ {
+ searchRange >>= 1;
+ ret += searchRange;
+ if (memcmp(target, ret, len) < 0)
+ ret -= searchRange;
+ }
+ const int result = memcmp(target, ret, len);
+ if (result == 0)
+ return (ret);
+ else if (lower_bound)
+ {
+ if (result > 0)
+ return (ret + searchRange);
+ return (ret);
+ }
+ return (NULL); // not found;
}
// }}}
-static OTF_FILE *otf_new(FILE *f) // {{{
+
+static OTF_FILE *
+otf_new(FILE *f) // {{{
{
DEBUG_assert(f);
OTF_FILE *ret;
- ret=calloc(1,sizeof(OTF_FILE));
- if (ret) {
- ret->f=f;
- ret->version=0x00010000;
+ ret = calloc(1, sizeof(OTF_FILE));
+ if (ret)
+ {
+ ret->f = f;
+ ret->version = 0x00010000;
}
- return ret;
+ return (ret);
}
// }}}
+
// will alloc, if >buf ==NULL, returns >buf, or NULL on error
// NOTE: you probably want otf_get_table()
-static char *otf_read(OTF_FILE *otf,char *buf,long pos,int length) // {{{
+
+static char *
+otf_read(OTF_FILE *otf,
+ char *buf,
+ long pos,
+ int length) // {{{
{
- char *ours=NULL;
+ char *ours = NULL;
- if (length==0) {
- return buf;
- } else if (length<0) {
+ if (length == 0)
+ return (buf);
+ else if (length < 0)
+ {
DEBUG_assert(0);
- return NULL;
+ return (NULL);
}
- int res=fseek(otf->f,pos,SEEK_SET);
- if (res==-1) {
- fprintf(stderr,"Seek failed: %s\n", strerror(errno));
- return NULL;
+ int res = fseek(otf->f, pos, SEEK_SET);
+ if (res == -1)
+ {
+ fprintf(stderr, "Seek failed: %s\n", strerror(errno));
+ return (NULL);
}
- // (+3)&~3 for checksum...
- const int pad_len=(length+3)&~3;
- if (!buf) {
- ours=buf=malloc(sizeof(char)*pad_len);
- if (!buf) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- return NULL;
+ // (+3) & ~3 for checksum...
+ const int pad_len = (length + 3) & ~3;
+ if (!buf)
+ {
+ ours = buf = malloc(sizeof(char) * pad_len);
+ if (!buf)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
+ return (NULL);
}
}
- res=fread(buf,1,pad_len,otf->f);
- if (res!=pad_len) {
- if (res==length) { // file size not multiple of 4, pad with zero
- memset(buf+res,0,pad_len-length);
- } else {
- fprintf(stderr,"Short read\n");
+ res = fread(buf, 1, pad_len, otf->f);
+ if (res != pad_len)
+ {
+ if (res == length) // file size not multiple of 4, pad with zero
+ memset(buf + res, 0, pad_len - length);
+ else {
+ fprintf(stderr, "Short read\n");
free(ours);
- return NULL;
+ return (NULL);
}
}
- return buf;
+ return (buf);
}
// }}}
-static int otf_get_ttc_start(OTF_FILE *otf,int use_ttc) // {{{
+static int
+otf_get_ttc_start(OTF_FILE *otf,
+ int use_ttc) // {{{
{
char buf[4];
- if (!otf->numTTC) { // >0 if TTC...
- return 0;
- }
+ if (!otf->numTTC) // > 0 if TTC...
+ return (0);
- int pos=0;
- if ( (use_ttc<0)||(use_ttc>=otf->numTTC)||
- (!otf_read(otf,buf,pos+12+4*use_ttc,4)) ) {
- fprintf(stderr,"Bad TTC subfont number\n");
- return -1;
+ int pos = 0;
+ if ((use_ttc < 0) || (use_ttc >= otf->numTTC) ||
+ (!otf_read(otf, buf, pos + 12 + 4 * use_ttc, 4)))
+ {
+ fprintf(stderr, "Bad TTC subfont number\n");
+ return (-1);
}
- return get_ULONG(buf);
+ return (get_ULONG(buf));
}
// }}}
-OTF_FILE *otf_do_load(OTF_FILE *otf,int pos) // {{{
+
+OTF_FILE *
+otf_do_load(OTF_FILE *otf,
+ int pos) // {{{
{
int iA;
char buf[16];
// {{{ read offset table
- if (otf_read(otf,buf,pos,12)) {
- otf->version=get_ULONG(buf);
- if (otf->version==0x00010000) { // 1.0 truetype
- } else if (otf->version==OTF_TAG('O','T','T','O')) { // OTF(CFF)
- otf->flags|=OTF_F_FMT_CFF;
- } else if (otf->version==OTF_TAG('t','r','u','e')) { // (old mac)
- } else if (otf->version==OTF_TAG('t','y','p','1')) { // sfnt wrapped type1
+ if (otf_read(otf, buf, pos, 12))
+ {
+ otf->version = get_ULONG(buf);
+ if (otf->version == 0x00010000) // 1.0 truetype
+ {
+ }
+ else if (otf->version == OTF_TAG('O', 'T', 'T', 'O')) // OTF(CFF)
+ otf->flags |= OTF_F_FMT_CFF;
+ else if (otf->version == OTF_TAG('t', 'r', 'u', 'e')) // (old mac)
+ {
+ }
+ else if (otf->version == OTF_TAG('t', 'y', 'p', '1')) // sfnt wrapped type1
+ {
// TODO: unsupported
- } else {
+ }
+ else
+ {
otf_close(otf);
- otf=NULL;
+ otf = NULL;
}
- pos+=12;
- } else {
+ pos += 12;
+ }
+ else
+ {
otf_close(otf);
- otf=NULL;
+ otf = NULL;
}
- if (!otf) {
- fprintf(stderr,"Not a ttf font\n");
- return NULL;
+ if (!otf)
+ {
+ fprintf(stderr, "Not a ttf font\n");
+ return (NULL);
}
- otf->numTables=get_USHORT(buf+4);
+ otf->numTables = get_USHORT(buf + 4);
// }}}
// {{{ read directory
- otf->tables=malloc(sizeof(OTF_DIRENT)*otf->numTables);
- if (!otf->tables) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
+ otf->tables = malloc(sizeof(OTF_DIRENT) * otf->numTables);
+ if (!otf->tables)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
otf_close(otf);
- return NULL;
+ return (NULL);
}
- for (iA=0;iA<otf->numTables;iA++) {
- if (!otf_read(otf,buf,pos,16)) {
+ for (iA = 0; iA < otf->numTables; iA ++)
+ {
+ if (!otf_read(otf, buf, pos, 16))
+ {
otf_close(otf);
- return NULL;
+ return (NULL);
}
- otf->tables[iA].tag=get_ULONG(buf);
- otf->tables[iA].checkSum=get_ULONG(buf+4);
- otf->tables[iA].offset=get_ULONG(buf+8);
- otf->tables[iA].length=get_ULONG(buf+12);
- if ( (otf->tables[iA].tag==OTF_TAG('C','F','F',' '))&&
- ((otf->flags&OTF_F_FMT_CFF)==0) ) {
- fprintf(stderr,"Wrong magic\n");
+ otf->tables[iA].tag = get_ULONG(buf);
+ otf->tables[iA].checkSum = get_ULONG(buf + 4);
+ otf->tables[iA].offset = get_ULONG(buf + 8);
+ otf->tables[iA].length = get_ULONG(buf + 12);
+ if ((otf->tables[iA].tag == OTF_TAG('C', 'F', 'F', ' ')) &&
+ ((otf->flags & OTF_F_FMT_CFF) == 0))
+ {
+ fprintf(stderr, "Wrong magic\n");
otf_close(otf);
- return NULL;
- } else if ( (otf->tables[iA].tag==OTF_TAG('g','l','y','p'))&&
- (otf->flags&OTF_F_FMT_CFF) ) {
- fprintf(stderr,"Wrong magic\n");
+ return (NULL);
+ }
+ else if ((otf->tables[iA].tag == OTF_TAG('g', 'l', 'y', 'p')) &&
+ (otf->flags & OTF_F_FMT_CFF))
+ {
+ fprintf(stderr, "Wrong magic\n");
otf_close(otf);
- return NULL;
+ return (NULL);
}
- pos+=16;
+ pos += 16;
}
// }}}
-// otf->flags|=OTF_F_DO_CHECKSUM;
+ //otf->flags |= OTF_F_DO_CHECKSUM;
// {{{ check head table
- int len=0;
- char *head=otf_get_table(otf,OTF_TAG('h','e','a','d'),&len);
- if ( (!head)||
- (get_ULONG(head+0)!=0x00010000)|| // version
- (len!=54)||
- (get_ULONG(head+12)!=0x5F0F3CF5)|| // magic
- (get_SHORT(head+52)!=0x0000) ) { // glyphDataFormat
- fprintf(stderr,"Unsupported OTF font / head table \n");
+ int len = 0;
+ char *head = otf_get_table(otf, OTF_TAG('h', 'e', 'a', 'd'), &len);
+ if ((!head) ||
+ (get_ULONG(head + 0) != 0x00010000) || // version
+ (len != 54) ||
+ (get_ULONG(head + 12) != 0x5F0F3CF5) || // magic
+ (get_SHORT(head + 52) != 0x0000)) // glyphDataFormat
+ {
+ fprintf(stderr, "Unsupported OTF font / head table \n");
free(head);
otf_close(otf);
- return NULL;
+ return (NULL);
}
// }}}
- otf->unitsPerEm=get_USHORT(head+18);
- otf->indexToLocFormat=get_SHORT(head+50);
+ otf->unitsPerEm = get_USHORT(head + 18);
+ otf->indexToLocFormat = get_SHORT(head + 50);
// {{{ checksum whole file
- if (otf->flags&OTF_F_DO_CHECKSUM) {
- unsigned int csum=0;
+ if (otf->flags & OTF_F_DO_CHECKSUM)
+ {
+ unsigned int csum = 0;
char tmp[1024];
rewind(otf->f);
- while (!feof(otf->f)) {
- len=fread(tmp,1,1024,otf->f);
- if (len&3) { // zero padding reqd.
- memset(tmp+len,0,4-(len&3));
- }
- csum+=otf_checksum(tmp,len);
+ while (!feof(otf->f))
+ {
+ len = fread(tmp, 1, 1024, otf->f);
+ if (len & 3) // zero padding reqd.
+ memset(tmp + len, 0, 4 - (len & 3));
+ csum += otf_checksum(tmp, len);
}
- if (csum!=0xb1b0afba) {
- fprintf(stderr,"Wrong global checksum\n");
+ if (csum != 0xb1b0afba)
+ {
+ fprintf(stderr, "Wrong global checksum\n");
free(head);
otf_close(otf);
- return NULL;
+ return (NULL);
}
}
// }}}
free(head);
// {{{ read maxp table / numGlyphs
- char *maxp=otf_get_table(otf,OTF_TAG('m','a','x','p'),&len);
- if (maxp) {
- const unsigned int maxp_version=get_ULONG(maxp);
- if ( (maxp_version==0x00005000)&&(len==6) ) { // version 0.5
- otf->numGlyphs=get_USHORT(maxp+4);
- if ( (otf->flags&OTF_F_FMT_CFF)==0) { // only CFF
+ char *maxp = otf_get_table(otf, OTF_TAG('m', 'a', 'x', 'p'), &len);
+ if (maxp)
+ {
+ const unsigned int maxp_version = get_ULONG(maxp);
+ if ((maxp_version == 0x00005000) && (len == 6)) // version 0.5
+ {
+ otf->numGlyphs = get_USHORT(maxp + 4);
+ if ((otf->flags & OTF_F_FMT_CFF) == 0) // only CFF
+ {
free(maxp);
- maxp=NULL;
+ maxp = NULL;
}
- } else if ( (maxp_version==0x00010000)&&(len==32) ) { // version 1.0
- otf->numGlyphs=get_USHORT(maxp+4);
- if (otf->flags&OTF_F_FMT_CFF) { // only TTF
+ }
+ else if ((maxp_version == 0x00010000) && (len == 32)) // version 1.0
+ {
+ otf->numGlyphs = get_USHORT(maxp + 4);
+ if (otf->flags&OTF_F_FMT_CFF) // only TTF
+ {
free(maxp);
- maxp=NULL;
+ maxp = NULL;
}
- } else {
+ }
+ else
+ {
free(maxp);
- maxp=NULL;
+ maxp = NULL;
}
}
- if (!maxp) {
- fprintf(stderr,"Unsupported OTF font / maxp table \n");
+ if (!maxp)
+ {
+ fprintf(stderr, "Unsupported OTF font / maxp table \n");
free(maxp);
otf_close(otf);
- return NULL;
+ return (NULL);
}
free(maxp);
// }}}
- return otf;
+ return (otf);
}
// }}}
-OTF_FILE *otf_load(const char *file) // {{{
+
+OTF_FILE *
+otf_load(const char *file) // {{{
{
FILE *f;
OTF_FILE *otf;
- int use_ttc=-1;
- if ((f=fopen(file,"rb"))==NULL) {
+ int use_ttc =- 1;
+ if ((f = fopen(file, "rb")) == NULL)
+ {
// check for TTC
- char *tmp=strrchr(file,'/'),*end;
- if (tmp) {
- use_ttc=strtoul(tmp+1,&end,10);
- if (!*end) {
- end=malloc((tmp-file+1)*sizeof(char));
- if (!end) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- return NULL;
+ char *tmp = strrchr(file, '/'), *end;
+ if (tmp)
+ {
+ use_ttc = strtoul(tmp + 1, &end, 10);
+ if (!*end)
+ {
+ end = malloc((tmp - file + 1) * sizeof(char));
+ if (!end)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
+ return (NULL);
}
- strncpy(end,file,tmp-file);
- end[tmp-file]=0;
- f=fopen(end,"rb");
+ strncpy(end, file, tmp - file);
+ end[tmp - file] = 0;
+ f = fopen(end, "rb");
free(end);
}
}
- if (!f) {
- fprintf(stderr,"Could not open \"%s\": %s\n", file, strerror(errno));
- return NULL;
+ if (!f)
+ {
+ fprintf(stderr, "Could not open \"%s\": %s\n", file, strerror(errno));
+ return (NULL);
}
}
- otf=otf_new(f);
- if (!otf) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
+ otf = otf_new(f);
+ if (!otf)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
fclose(f);
- return NULL;
+ return (NULL);
}
char buf[12];
- int pos=0;
+ int pos = 0;
// {{{ check for TTC
- if (otf_read(otf,buf,pos,12)) {
- const unsigned int version=get_ULONG(buf);
- if (version==OTF_TAG('t','t','c','f')) {
- const unsigned int ttc_version=get_ULONG(buf+4);
- if ( (ttc_version!=0x00010000)&&(ttc_version!=0x00020000) ) {
- fprintf(stderr,"Unsupported TTC version\n");
+ if (otf_read(otf, buf, pos, 12))
+ {
+ const unsigned int version = get_ULONG(buf);
+ if (version == OTF_TAG('t', 't', 'c', 'f'))
+ {
+ const unsigned int ttc_version = get_ULONG(buf + 4);
+ if ((ttc_version != 0x00010000) && (ttc_version != 0x00020000))
+ {
+ fprintf(stderr, "Unsupported TTC version\n");
otf_close(otf);
- return NULL;
+ return (NULL);
}
- otf->numTTC=get_ULONG(buf+8);
- otf->useTTC=use_ttc;
- pos=otf_get_ttc_start(otf,use_ttc);
- if (pos==-1) {
+ otf->numTTC = get_ULONG(buf + 8);
+ otf->useTTC = use_ttc;
+ pos = otf_get_ttc_start(otf, use_ttc);
+ if (pos == -1)
+ {
otf_close(otf);
- return NULL;
+ return (NULL);
}
}
- } else {
- fprintf(stderr,"Not a ttf font\n");
+ }
+ else
+ {
+ fprintf(stderr, "Not a ttf font\n");
otf_close(otf);
- return NULL;
+ return (NULL);
}
// }}}
- return otf_do_load(otf,pos);
+ return (otf_do_load(otf, pos));
}
// }}}
-void otf_close(OTF_FILE *otf) // {{{
+
+void
+otf_close(OTF_FILE *otf) // {{{
{
DEBUG_assert(otf);
- if (otf) {
+ if (otf)
+ {
free(otf->gly);
free(otf->cmap);
free(otf->name);
}
// }}}
-static int otf_dirent_compare(const void *a,const void *b) // {{{
+
+static int
+otf_dirent_compare(const void *a, const void *b) // {{{
{
- const unsigned int aa=((const OTF_DIRENT *)a)->tag;
- const unsigned int bb=((const OTF_DIRENT *)b)->tag;
- if (aa<bb) {
- return -1;
- } else if (aa>bb) {
- return 1;
- }
- return 0;
+ const unsigned int aa = ((const OTF_DIRENT *)a)->tag;
+ const unsigned int bb = ((const OTF_DIRENT *)b)->tag;
+ if (aa < bb)
+ return (-1);
+ else if (aa > bb)
+ return (1);
+ return (0);
}
// }}}
-int otf_find_table(OTF_FILE *otf,unsigned int tag) // {{{ - table_index or -1 on error
+
+int
+otf_find_table(OTF_FILE *otf,
+ unsigned int tag) // {{{ - table_index or -1 on error
{
#if 0
// binary search would require raw table
- int pos=0;
+ int pos = 0;
char buf[12];
- if (!otf_read(otf,buf,pos,12)) {
- return -1;
- }
- pos=12;
- const unsigned int numTables=get_USHORT(buf+4);
- char *tables=malloc(16*numTables);
- if (!tables) {
- return -1;
- }
- if (!otf_read(otf,tables,pos,16*numTables)) {
+ if (!otf_read(otf, buf, pos, 12))
+ return (-1);
+ pos = 12;
+ const unsigned int numTables = get_USHORT(buf + 4);
+ char *tables = malloc(16 * numTables);
+ if (!tables)
+ return (-1);
+ if (!otf_read(otf, tables, pos, 16 * numTables))
+ {
free(tables);
- return -1;
+ return (-1);
}
- char target[]={(tag>>24),(tag>>16),(tag>>8),tag};
+ char target[] = {(tag >> 24), (tag >> 16), (tag >> 8), tag};
// DEBUG_assert(get_USHORT(buf+6)+get_USHORT(buf+10)==16*numTables);
- char *result=otf_bsearch(tables,target,4,
- get_USHORT(buf+6),
- get_USHORT(buf+8),
- get_USHORT(buf+10),0);
+ char *result = otf_bsearch(tables, target, 4,
+ get_USHORT(buf + 6),
+ get_USHORT(buf + 8),
+ get_USHORT(buf + 10), 0);
free(tables);
- if (result) {
- return (result-tables)/16;
- }
+ if (result)
+ return (result - tables) / 16;
#elif 1
- OTF_DIRENT key={.tag=tag},*res;
- res=bsearch(&key,otf->tables,otf->numTables,sizeof(otf->tables[0]),otf_dirent_compare);
- if (res) {
+ OTF_DIRENT key = {.tag = tag}, *res;
+ res = bsearch(&key, otf->tables, otf->numTables, sizeof(otf->tables[0]),
+ otf_dirent_compare);
+ if (res)
return (res-otf->tables);
- }
#else
int iA;
- for (iA=0;iA<otf->numTables;iA++) {
- if (otf->tables[iA].tag==tag) {
- return iA;
- }
+ for (iA = 0; iA < otf->numTables; iA ++)
+ {
+ if (otf->tables[iA].tag == tag)
+ return (iA);
}
-#endif
- return -1;
+#endif // 1
+ return (-1);
}
// }}}
-char *otf_get_table(OTF_FILE *otf,unsigned int tag,int *ret_len) // {{{
+
+char *
+otf_get_table(OTF_FILE *otf,
+ unsigned int tag,
+ int *ret_len) // {{{
{
DEBUG_assert(otf);
DEBUG_assert(ret_len);
- const int idx=otf_find_table(otf,tag);
- if (idx==-1) {
- *ret_len=-1;
- return NULL;
- }
- const OTF_DIRENT *table=otf->tables+idx;
-
- char *ret=otf_read(otf,NULL,table->offset,table->length);
- if (!ret) {
- return NULL;
- }
- if (otf->flags&OTF_F_DO_CHECKSUM) {
- unsigned int csum=otf_checksum(ret,table->length);
- if (tag==OTF_TAG('h','e','a','d')) { // special case
- csum-=get_ULONG(ret+8);
- }
- if (csum!=table->checkSum) {
- fprintf(stderr,"Wrong checksum for %c%c%c%c\n",OTF_UNTAG(tag));
+ const int idx = otf_find_table(otf, tag);
+ if (idx == -1)
+ {
+ *ret_len =- 1;
+ return (NULL);
+ }
+ const OTF_DIRENT *table = otf->tables + idx;
+
+ char *ret = otf_read(otf, NULL, table->offset, table->length);
+ if (!ret)
+ return (NULL);
+ if (otf->flags & OTF_F_DO_CHECKSUM)
+ {
+ unsigned int csum = otf_checksum(ret, table->length);
+ if (tag==OTF_TAG('h', 'e', 'a', 'd')) // special case
+ csum -= get_ULONG(ret + 8);
+ if (csum != table->checkSum)
+ {
+ fprintf(stderr, "Wrong checksum for %c%c%c%c\n", OTF_UNTAG(tag));
free(ret);
- return NULL;
+ return (NULL);
}
}
- *ret_len=table->length;
- return ret;
+ *ret_len = table->length;
+ return (ret);
}
// }}}
-int otf_load_glyf(OTF_FILE *otf) // {{{ - 0 on success
+
+int
+otf_load_glyf(OTF_FILE *otf) // {{{ - 0 on success
{
- DEBUG_assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
- int iA,len;
+ DEBUG_assert((otf->flags & OTF_F_FMT_CFF) == 0); // not for CFF
+ int iA, len;
// {{{ find glyf table
- iA=otf_find_table(otf,OTF_TAG('g','l','y','f'));
- if (iA==-1) {
- fprintf(stderr,"Unsupported OTF font / glyf table \n");
- return -1;
+ iA = otf_find_table(otf, OTF_TAG('g', 'l', 'y', 'f'));
+ if (iA == -1)
+ {
+ fprintf(stderr, "Unsupported OTF font / glyf table \n");
+ return (-1);
}
- otf->glyfTable=otf->tables+iA;
+ otf->glyfTable = otf->tables + iA;
// }}}
// {{{ read loca table
- char *loca=otf_get_table(otf,OTF_TAG('l','o','c','a'),&len);
- if ( (!loca)||
- (otf->indexToLocFormat>=2)||
- (((len+3)&~3)!=((((otf->numGlyphs+1)*(otf->indexToLocFormat+1)*2)+3)&~3)) ) {
- fprintf(stderr,"Unsupported OTF font / loca table \n");
- return -1;
- }
- if (otf->glyphOffsets) {
+ char *loca = otf_get_table(otf, OTF_TAG('l', 'o', 'c', 'a'), &len);
+ if ((!loca) ||
+ (otf->indexToLocFormat >= 2) ||
+ (((len + 3) & ~3) != ((((otf->numGlyphs + 1) *
+ (otf->indexToLocFormat + 1) * 2) +3 ) & ~3)))
+ {
+ fprintf(stderr, "Unsupported OTF font / loca table \n");
+ return (-1);
+ }
+ if (otf->glyphOffsets)
+ {
free(otf->glyphOffsets);
DEBUG_assert(0);
}
- otf->glyphOffsets=malloc((otf->numGlyphs+1)*sizeof(unsigned int));
- if (!otf->glyphOffsets) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- return -1;
+ otf->glyphOffsets = malloc((otf->numGlyphs + 1) * sizeof(unsigned int));
+ if (!otf->glyphOffsets)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
+ return (-1);
}
- if (otf->indexToLocFormat==0) {
- for (iA=0;iA<=otf->numGlyphs;iA++) {
- otf->glyphOffsets[iA]=get_USHORT(loca+iA*2)*2;
- }
- } else { // indexToLocFormat==1
- for (iA=0;iA<=otf->numGlyphs;iA++) {
- otf->glyphOffsets[iA]=get_ULONG(loca+iA*4);
- }
+ if (otf->indexToLocFormat == 0)
+ {
+ for (iA = 0; iA <= otf->numGlyphs; iA ++)
+ otf->glyphOffsets[iA] = get_USHORT(loca + iA * 2) * 2;
+ }
+ else // indexToLocFormat == 1
+ {
+ for (iA = 0; iA <= otf->numGlyphs; iA ++)
+ otf->glyphOffsets[iA] = get_ULONG(loca + iA * 4);
}
free(loca);
- if (otf->glyphOffsets[otf->numGlyphs]>otf->glyfTable->length) {
- fprintf(stderr,"Bad loca table \n");
- return -1;
+ if (otf->glyphOffsets[otf->numGlyphs] > otf->glyfTable->length)
+ {
+ fprintf(stderr, "Bad loca table \n");
+ return (-1);
}
// }}}
// {{{ allocate otf->gly slot
- int maxGlyfLen=0; // no single glyf takes more space
- for (iA=1;iA<=otf->numGlyphs;iA++) {
- const int glyfLen=otf->glyphOffsets[iA]-otf->glyphOffsets[iA-1];
- if (glyfLen<0) {
- fprintf(stderr,"Bad loca table: glyph len %d\n",glyfLen);
- return -1;
- }
- if (maxGlyfLen<glyfLen) {
- maxGlyfLen=glyfLen;
+ int maxGlyfLen = 0; // no single glyf takes more space
+ for (iA = 1; iA <= otf->numGlyphs; iA ++)
+ {
+ const int glyfLen = otf->glyphOffsets[iA] - otf->glyphOffsets[iA - 1];
+ if (glyfLen < 0)
+ {
+ fprintf(stderr, "Bad loca table: glyph len %d\n", glyfLen);
+ return (-1);
}
+ if (maxGlyfLen < glyfLen)
+ maxGlyfLen = glyfLen;
}
- if (otf->gly) {
+ if (otf->gly)
+ {
free(otf->gly);
DEBUG_assert(0);
}
- otf->gly=malloc(maxGlyfLen*sizeof(char));
- if (!otf->gly) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
- return -1;
+ otf->gly=malloc(maxGlyfLen * sizeof(char));
+ if (!otf->gly)
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
+ return (-1);
}
// }}}
- return 0;
+ return (0);
}
// }}}
-int otf_load_more(OTF_FILE *otf) // {{{ - 0 on success => hhea,hmtx,name,[glyf]
+int
+otf_load_more(OTF_FILE *otf) // {{{ - 0 on success => hhea, hmtx, name, [glyf]
{
int iA;
-
int len;
- if ((otf->flags&OTF_F_FMT_CFF)==0) { // not for CFF
- if (otf_load_glyf(otf)==-1) {
- return -1;
- }
+
+ if ((otf->flags & OTF_F_FMT_CFF) == 0) // not for CFF
+ {
+ if (otf_load_glyf(otf) == -1)
+ return (-1);
}
// {{{ read hhea table
- char *hhea=otf_get_table(otf,OTF_TAG('h','h','e','a'),&len);
- if ( (!hhea)||
- (get_ULONG(hhea)!=0x00010000)|| // version
- (len!=36)||
- (get_SHORT(hhea+32)!=0) ) { // metric format
- fprintf(stderr,"Unsupported OTF font / hhea table \n");
- return -1;
- }
- otf->numberOfHMetrics=get_USHORT(hhea+34);
+ char *hhea = otf_get_table(otf, OTF_TAG('h', 'h', 'e', 'a'), &len);
+ if ((!hhea) ||
+ (get_ULONG(hhea) != 0x00010000) || // version
+ (len != 36) ||
+ (get_SHORT(hhea + 32) != 0)) // metric format
+ {
+ fprintf(stderr, "Unsupported OTF font / hhea table \n");
+ return (-1);
+ }
+ otf->numberOfHMetrics = get_USHORT(hhea + 34);
free(hhea);
// }}}
// {{{ read hmtx table
- char *hmtx=otf_get_table(otf,OTF_TAG('h','m','t','x'),&len);
- if ( (!hmtx)||
- (len!=otf->numberOfHMetrics*2+otf->numGlyphs*2) ) {
- fprintf(stderr,"Unsupported OTF font / hmtx table \n");
- return -1;
- }
- if (otf->hmtx) {
+ char *hmtx = otf_get_table(otf, OTF_TAG('h', 'm', 't', 'x'), &len);
+ if ((!hmtx) ||
+ (len != otf->numberOfHMetrics * 2 + otf->numGlyphs * 2))
+ {
+ fprintf(stderr, "Unsupported OTF font / hmtx table\n");
+ return (-1);
+ }
+ if (otf->hmtx)
+ {
free(otf->hmtx);
DEBUG_assert(0);
}
- otf->hmtx=hmtx;
+ otf->hmtx = hmtx;
// }}}
// {{{ read name table
- char *name=otf_get_table(otf,OTF_TAG('n','a','m','e'),&len);
- if ( (!name)||
- (get_USHORT(name)!=0x0000)|| // version
- (len<get_USHORT(name+2)*12+6)||
- (len<=get_USHORT(name+4)) ) {
- fprintf(stderr,"Unsupported OTF font / name table \n");
- return -1;
+ char *name = otf_get_table(otf, OTF_TAG('n', 'a', 'm', 'e'), &len);
+ if ((!name) ||
+ (get_USHORT(name) != 0x0000) || // version
+ (len < get_USHORT(name + 2) * 12 + 6) ||
+ (len <= get_USHORT(name + 4)))
+ {
+ fprintf(stderr, "Unsupported OTF font / name table\n");
+ return (-1);
}
+
// check bounds
- int name_count=get_USHORT(name+2);
- const char *nstore=name+get_USHORT(name+4);
- for (iA=0;iA<name_count;iA++) {
- const char *nrec=name+6+12*iA;
- if (nstore-name+get_USHORT(nrec+10)+get_USHORT(nrec+8)>len) {
- fprintf(stderr,"Bad name table \n");
+ int name_count = get_USHORT(name + 2);
+ const char *nstore = name + get_USHORT(name + 4);
+ for (iA = 0; iA < name_count; iA ++)
+ {
+ const char *nrec = name + 6 + 12 * iA;
+ if (nstore-name + get_USHORT(nrec + 10) + get_USHORT(nrec + 8) > len)
+ {
+ fprintf(stderr, "Bad name table\n");
free(name);
- return -1;
+ return (-1);
}
}
- if (otf->name) {
+ if (otf->name)
+ {
free(otf->name);
DEBUG_assert(0);
}
- otf->name=name;
+ otf->name = name;
// }}}
- return 0;
+ return (0);
}
// }}}
-int otf_load_cmap(OTF_FILE *otf) // {{{ - 0 on success
+
+int
+otf_load_cmap(OTF_FILE *otf) // {{{ - 0 on success
{
int iA;
int len;
- char *cmap=otf_get_table(otf,OTF_TAG('c','m','a','p'),&len);
- if ( (!cmap)||
- (get_USHORT(cmap)!=0x0000)|| // version
- (len<get_USHORT(cmap+2)*8+4) ) {
- fprintf(stderr,"Unsupported OTF font / cmap table \n");
+ char *cmap = otf_get_table(otf, OTF_TAG('c', 'm', 'a', 'p'), &len);
+ if ((!cmap) ||
+ (get_USHORT(cmap) != 0x0000) || // version
+ (len < get_USHORT(cmap + 2) * 8 + 4))
+ {
+ fprintf(stderr, "Unsupported OTF font / cmap table\n");
DEBUG_assert(0);
- return -1;
- }
- // check bounds, find (3,0) or (3,1) [TODO?]
- const int numTables=get_USHORT(cmap+2);
- for (iA=0;iA<numTables;iA++) {
- const char *nrec=cmap+4+8*iA;
- const unsigned int offset=get_ULONG(nrec+4);
- const char *ndata=cmap+offset;
- if ( (ndata<cmap+4+8*numTables)||
- (offset>=len)||
- (offset+get_USHORT(ndata+2)>len) ) {
- fprintf(stderr,"Bad cmap table \n");
+ return (-1);
+ }
+ // check bounds, find (3, 0) or (3, 1) [TODO?]
+ const int numTables = get_USHORT(cmap + 2);
+ for (iA = 0; iA < numTables; iA ++)
+ {
+ const char *nrec = cmap + 4 + 8 * iA;
+ const unsigned int offset = get_ULONG(nrec + 4);
+ const char *ndata = cmap + offset;
+ if ((ndata < cmap + 4 + 8 * numTables) ||
+ (offset >= len) ||
+ (offset + get_USHORT(ndata + 2) > len))
+ {
+ fprintf(stderr, "Bad cmap table\n");
free(cmap);
DEBUG_assert(0);
- return -1;
- }
- if ( (get_USHORT(nrec)==3)&&
- (get_USHORT(nrec+2)<=1)&&
- (get_USHORT(ndata)==4)&&
- (get_USHORT(ndata+4)==0) ) {
- otf->unimap=ndata;
+ return (-1);
}
- }
- if (otf->cmap) {
+ if ((get_USHORT(nrec) == 3) &&
+ (get_USHORT(nrec + 2) <= 1) &&
+ (get_USHORT(ndata) == 4) &&
+ (get_USHORT(ndata + 4) == 0))
+ otf->unimap = ndata;
+ }
+ if (otf->cmap)
+ {
free(otf->cmap);
DEBUG_assert(0);
}
- otf->cmap=cmap;
+ otf->cmap = cmap;
- return 0;
+ return (0);
}
// }}}
-int otf_get_width(OTF_FILE *otf,unsigned short gid) // {{{ -1 on error
+
+int
+otf_get_width(OTF_FILE *otf,
+ unsigned short gid) // {{{ -1 on error
{
DEBUG_assert(otf);
- if (gid>=otf->numGlyphs) {
- return -1;
- }
+ if (gid >= otf->numGlyphs)
+ return (-1);
// ensure hmtx is there
- if (!otf->hmtx) {
- if (otf_load_more(otf)!=0) {
- fprintf(stderr,"Unsupported OTF font / cmap table \n");
- return -1;
+ if (!otf->hmtx)
+ {
+ if (otf_load_more(otf) != 0)
+ {
+ fprintf(stderr, "Unsupported OTF font / cmap table\n");
+ return (-1);
}
}
- return get_width_fast(otf,gid);
+ return (get_width_fast(otf, gid));
#if 0
- if (gid>=otf->numberOfHMetrics) {
- return get_USHORT(otf->hmtx+(otf->numberOfHMetrics-1)*2);
- // TODO? lsb=get_SHORT(otf->hmtx+otf->numberOfHMetrics*2+gid*2); // lsb: left_side_bearing (also in table)
- }
- return get_USHORT(otf->hmtx+gid*4);
- // TODO? lsb=get_SHORT(otf->hmtx+gid*4+2);
+ if (gid >= otf->numberOfHMetrics)
+ {
+ return (get_USHORT(otf->hmtx + (otf->numberOfHMetrics - 1) * 2));
+ // TODO? lsb = get_SHORT(otf->hmtx + otf->numberOfHMetrics * 2 + gid * 2);
+ // lsb: left_side_bearing (also in table)
+ }
+ return (get_USHORT(otf->hmtx + gid * 4));
+ // TODO? lsb = get_SHORT(otf->hmtx + gid * 4 + 2);
#endif
}
// }}}
-static int otf_name_compare(const void *a,const void *b) // {{{
+
+static int
+otf_name_compare(const void *a,
+ const void *b) // {{{
{
- return memcmp(a,b,8);
+ return (memcmp(a, b, 8));
}
// }}}
-const char *otf_get_name(OTF_FILE *otf,int platformID,int encodingID,int languageID,int nameID,int *ret_len) // {{{
+
+const char *
+otf_get_name(OTF_FILE *otf,
+ int platformID,
+ int encodingID,
+ int languageID,
+ int nameID,
+ int *ret_len) // {{{
{
DEBUG_assert(otf);
DEBUG_assert(ret_len);
// ensure name is there
- if (!otf->name) {
- if (otf_load_more(otf)!=0) {
- *ret_len=-1;
+ if (!otf->name)
+ {
+ if (otf_load_more(otf) != 0)
+ {
+ *ret_len = -1;
DEBUG_assert(0);
- return NULL;
+ return (NULL);
}
}
char key[8];
- set_USHORT(key,platformID);
- set_USHORT(key+2,encodingID);
- set_USHORT(key+4,languageID);
- set_USHORT(key+6,nameID);
-
- char *res=bsearch(key,otf->name+6,get_USHORT(otf->name+2),12,otf_name_compare);
- if (res) {
- *ret_len=get_USHORT(res+8);
- int npos=get_USHORT(res+10);
- const char *nstore=otf->name+get_USHORT(otf->name+4);
- return nstore+npos;
- }
- *ret_len=0;
- return NULL;
+ set_USHORT(key, platformID);
+ set_USHORT(key + 2, encodingID);
+ set_USHORT(key + 4, languageID);
+ set_USHORT(key + 6, nameID);
+
+ char *res = bsearch(key, otf->name + 6, get_USHORT(otf->name + 2), 12,
+ otf_name_compare);
+ if (res)
+ {
+ *ret_len = get_USHORT(res + 8);
+ int npos = get_USHORT(res + 10);
+ const char *nstore = otf->name + get_USHORT(otf->name + 4);
+ return (nstore + npos);
+ }
+ *ret_len = 0;
+ return (NULL);
}
// }}}
-int otf_get_glyph(OTF_FILE *otf,unsigned short gid) // {{{ result in >otf->gly, returns length, -1 on error
+
+int
+otf_get_glyph(OTF_FILE *otf,
+ unsigned short gid) // {{{ result in >otf->gly, returns length,
+ // -1 on error
{
DEBUG_assert(otf);
- DEBUG_assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF
+ DEBUG_assert((otf->flags & OTF_F_FMT_CFF) == 0); // not for CFF
- if (gid>=otf->numGlyphs) {
- return -1;
- }
+ if (gid >= otf->numGlyphs)
+ return (-1);
// ensure >glyphOffsets and >gly is there
- if ( (!otf->gly)||(!otf->glyphOffsets) ) {
- if (otf_load_more(otf)!=0) {
+ if ((!otf->gly) || (!otf->glyphOffsets))
+ {
+ if (otf_load_more(otf) != 0)
+ {
DEBUG_assert(0);
- return -1;
+ return (-1);
}
}
- const int len=otf->glyphOffsets[gid+1]-otf->glyphOffsets[gid];
- if (len==0) {
- return 0;
- }
+ const int len = otf->glyphOffsets[gid + 1] - otf->glyphOffsets[gid];
+ if (len == 0)
+ return (0);
- DEBUG_assert(otf->glyfTable->length>=otf->glyphOffsets[gid+1]);
- if (!otf_read(otf,otf->gly,
- otf->glyfTable->offset+otf->glyphOffsets[gid],len)) {
- return -1;
- }
+ DEBUG_assert(otf->glyfTable->length >= otf->glyphOffsets[gid + 1]);
+ if (!otf_read(otf, otf->gly,
+ otf->glyfTable->offset + otf->glyphOffsets[gid], len))
+ return (-1);
- return len;
+ return (len);
}
// }}}
-unsigned short otf_from_unicode(OTF_FILE *otf,int unicode) // {{{ 0 = missing
+
+unsigned short
+otf_from_unicode(OTF_FILE *otf,
+ int unicode) // {{{ 0 = missing
{
DEBUG_assert(otf);
- DEBUG_assert( (unicode>=0)&&(unicode<65536) );
-// DEBUG_assert((otf->flags&OTF_F_FMT_CFF)==0); // not for CFF, other method!
+ DEBUG_assert((unicode >= 0) && (unicode < 65536));
+//DEBUG_assert((otf->flags & OTF_F_FMT_CFF) == 0); // not for CFF, other method!
// ensure >cmap and >unimap is there
- if (!otf->cmap) {
- if (otf_load_cmap(otf)!=0) {
+ if (!otf->cmap)
+ {
+ if (otf_load_cmap(otf) != 0)
+ {
DEBUG_assert(0);
- return 0; // TODO?
+ return (0); // TODO?
}
}
- if (!otf->unimap) {
- fprintf(stderr,"Unicode (3,1) cmap in format 4 not found\n");
- return 0;
+ if (!otf->unimap)
+ {
+ fprintf(stderr, "Unicode (3, 1) cmap in format 4 not found\n");
+ return (0);
}
#if 0
// linear search is cache friendly and should be quite fast
#else
- const unsigned short segCountX2=get_USHORT(otf->unimap+6);
- char target[]={unicode>>8,unicode}; // set_USHORT(target,unicode);
- char *result=otf_bsearch((char *)otf->unimap+14,target,2,
- get_USHORT(otf->unimap+8),
- get_USHORT(otf->unimap+10),
- get_USHORT(otf->unimap+12),1);
- if (result>=otf->unimap+14+segCountX2) { // outside of endCode[segCount]
+ const unsigned short segCountX2 = get_USHORT(otf->unimap + 6);
+ char target[] = {unicode >> 8, unicode}; // set_USHORT(target, unicode);
+ char *result = otf_bsearch((char *)otf->unimap + 14, target, 2,
+ get_USHORT(otf->unimap + 8),
+ get_USHORT(otf->unimap + 10),
+ get_USHORT(otf->unimap + 12), 1);
+ if (result >= otf->unimap + 14 + segCountX2) // outside of endCode[segCount]
+ {
DEBUG_assert(0); // bad font, no 0xffff sentinel
- return 0;
- }
-
- result+=2+segCountX2; // jump over padding into startCode[segCount]
- const unsigned short startCode=get_USHORT(result);
- if (startCode>unicode) {
- return 0;
- }
- result+=2*segCountX2;
- const unsigned short rangeOffset=get_USHORT(result);
- if (rangeOffset) {
- return get_USHORT(result+rangeOffset+2*(unicode-startCode)); // the so called "obscure indexing trick" into glyphIdArray[]
- // NOTE: this is according to apple spec; microsoft says we must add delta (probably incorrect; fonts probably have delta==0)
- } else {
- const short delta=get_SHORT(result-segCountX2);
- return (delta+unicode)&0xffff;
- }
-#endif
+ return (0);
+ }
+
+ result += 2 + segCountX2; // jump over padding into startCode[segCount]
+ const unsigned short startCode = get_USHORT(result);
+ if (startCode > unicode)
+ return (0);
+ result += 2 * segCountX2;
+ const unsigned short rangeOffset = get_USHORT(result);
+ if (rangeOffset)
+ {
+ return (get_USHORT(result + rangeOffset + 2 * (unicode-startCode)));
+ // the so called "obscure indexing trick" into glyphIdArray[]
+ // NOTE: this is according to apple spec; microsoft says we must add
+ // delta (probably incorrect; fonts probably have delta == 0)
+ }
+ else
+ {
+ const short delta = get_SHORT(result - segCountX2);
+ return (delta + unicode) & 0xffff;
+ }
+#endif // 0
}
// }}}
+
/** output stuff **/
-int otf_action_copy(void *param,int table_no,OUTPUT_FN output,void *context) // {{{
+int
+otf_action_copy(void *param,
+ int table_no,
+ OUTPUT_FN output,
+ void *context) // {{{
{
- OTF_FILE *otf=param;
- const OTF_DIRENT *table=otf->tables+table_no;
-
- if (!output) { // get checksum and unpadded length
- *(unsigned int *)context=table->checkSum;
- return table->length;
- }
-
-// TODO? copy_block(otf->f,table->offset,(table->length+3)&~3,output,context);
-// problem: PS currently depends on single-output. also checksum not possible
- char *data=otf_read(otf,NULL,table->offset,table->length);
- if (!data) {
- return -1;
- }
- int ret=(table->length+3)&~3;
- (*output)(data,ret,context);
+ OTF_FILE *otf = param;
+ const OTF_DIRENT *table = otf->tables + table_no;
+
+ if (!output) // get checksum and unpadded length
+ {
+ *(unsigned int *)context = table->checkSum;
+ return (table->length);
+ }
+
+ // TODO? copy_block(otf->f, table->offset, (table->length + 3) & ~3, output,
+ // context);
+ // problem: PS currently depends on single-output. Also checksum not possible
+ char *data = otf_read(otf, NULL, table->offset, table->length);
+ if (!data)
+ return (-1);
+ int ret = (table->length + 3) & ~3;
+ (*output)(data, ret, context);
free(data);
- return ret; // padded length
+ return (ret); // padded length
}
// }}}
+
// TODO? >modified time-stamp?
-// Note: don't use this directly. otf_write_sfnt will internally replace otf_action_copy for head with this
-int otf_action_copy_head(void *param,int csum,OUTPUT_FN output,void *context) // {{{
+// Note: don't use this directly. otf_write_sfnt will internally replace
+// otf_action_copy for head with this
+
+int
+otf_action_copy_head(void *param,
+ int csum,
+ OUTPUT_FN output,
+ void *context) // {{{
{
- OTF_FILE *otf=param;
- const int table_no=otf_find_table(otf,OTF_TAG('h','e','a','d')); // we can't have csum AND table_no ... never mind!
- DEBUG_assert(table_no!=-1);
- const OTF_DIRENT *table=otf->tables+table_no;
-
- if (!output) { // get checksum and unpadded length
- *(unsigned int *)context=table->checkSum;
- return table->length;
- }
-
- char *data=otf_read(otf,NULL,table->offset,table->length);
- if (!data) {
- return -1;
- }
- set_ULONG(data+8,0xb1b0afba-csum); // head. fix global checksum
- int ret=(table->length+3)&~3;
- (*output)(data,ret,context);
+ OTF_FILE *otf = param;
+ const int table_no = otf_find_table(otf, OTF_TAG('h', 'e', 'a', 'd'));
+ // we can't have csum AND table_no ... never mind!
+ DEBUG_assert(table_no != -1);
+ const OTF_DIRENT *table = otf->tables + table_no;
+
+ if (!output) // get checksum and unpadded length
+ {
+ *(unsigned int *)context = table->checkSum;
+ return (table->length);
+ }
+
+ char *data = otf_read(otf, NULL, table->offset, table->length);
+ if (!data)
+ return (-1);
+ set_ULONG(data + 8, 0xb1b0afba - csum); // head. fix global checksum
+ int ret = (table->length + 3) & ~3;
+ (*output)(data, ret, context);
free(data);
- return ret; // padded length
+ return (ret); // padded length
}
// }}}
-int otf_action_replace(void *param,int length,OUTPUT_FN output,void *context) // {{{
+
+int
+otf_action_replace(void *param,
+ int length,
+ OUTPUT_FN output,
+ void *context) // {{{
{
- char *data=param;
- char pad[4]={0,0,0,0};
-
- int ret=(length+3)&~3;
- if (!output) { // get checksum and unpadded length
- if (ret!=length) {
- unsigned int csum=otf_checksum(data,ret-4);
- memcpy(pad,data+ret-4,ret-length);
- csum+=get_ULONG(pad);
- *(unsigned int *)context=csum;
- } else {
- *(unsigned int *)context=otf_checksum(data,length);
+ char *data = param;
+ char pad[4] = {0, 0, 0, 0};
+
+ int ret = (length + 3) & ~3;
+ if (!output) // get checksum and unpadded length
+ {
+ if (ret != length)
+ {
+ unsigned int csum = otf_checksum(data, ret - 4);
+ memcpy(pad, data + ret - 4, ret - length);
+ csum += get_ULONG(pad);
+ *(unsigned int *)context = csum;
}
- return length;
+ else
+ *(unsigned int *)context = otf_checksum(data, length);
+ return (length);
}
- (*output)(data,length,context);
- if (ret!=length) {
- (*output)(pad,ret-length,context);
- }
+ (*output)(data, length, context);
+ if (ret != length)
+ (*output)(pad, ret - length, context);
- return ret; // padded length
+ return (ret); // padded length
}
// }}}
-/* windows "works best" with the following ordering:
- head, hhea, maxp, OS/2, hmtx, LTSH, VDMX, hdmx, cmap, fpgm, prep, cvt, loca, glyf, kern, name, post, gasp, PCLT, DSIG
-or for CFF:
- head, hhea, maxp, OS/2, name, cmap, post, CFF, (other tables, as convenient)
-*/
+//
+// windows "works best" with the following ordering:
+// head, hhea, maxp, OS/2, hmtx, LTSH, VDMX, hdmx, cmap, fpgm, prep, cvt,
+// loca, glyf, kern, name, post, gasp, PCLT, DSIG
+// or for CFF:
+// head, hhea, maxp, OS/2, name, cmap, post, CFF, (other tables, as
+// convenient)
+//
+
#define NUM_PRIO 20
-static const struct { int prio; unsigned int tag; } otf_tagorder_win[]={ // {{{
- {19,OTF_TAG('D','S','I','G')},
- { 5,OTF_TAG('L','T','S','H')},
- { 3,OTF_TAG('O','S','/','2')},
- {18,OTF_TAG('P','C','L','T')},
- { 6,OTF_TAG('V','D','M','X')},
- { 8,OTF_TAG('c','m','a','p')},
- {11,OTF_TAG('c','v','t',' ')},
- { 9,OTF_TAG('f','p','g','m')},
- {17,OTF_TAG('g','a','s','p')},
- {13,OTF_TAG('g','l','y','f')},
- { 7,OTF_TAG('h','d','m','x')},
- { 0,OTF_TAG('h','e','a','d')},
- { 1,OTF_TAG('h','h','e','a')},
- { 4,OTF_TAG('h','m','t','x')},
- {14,OTF_TAG('k','e','r','n')},
- {12,OTF_TAG('l','o','c','a')},
- { 2,OTF_TAG('m','a','x','p')},
- {15,OTF_TAG('n','a','m','e')},
- {16,OTF_TAG('p','o','s','t')},
- {10,OTF_TAG('p','r','e','p')}};
+static const struct
+{
+ int prio;
+ unsigned int tag;
+} otf_tagorder_win[] =
+{ // {{{
+ {19, OTF_TAG('D', 'S', 'I', 'G')},
+ { 5, OTF_TAG('L', 'T', 'S', 'H')},
+ { 3, OTF_TAG('O', 'S', '/', '2')},
+ {18, OTF_TAG('P', 'C', 'L', 'T')},
+ { 6, OTF_TAG('V', 'D', 'M', 'X')},
+ { 8, OTF_TAG('c', 'm', 'a', 'p')},
+ {11, OTF_TAG('c', 'v', 't', ' ')},
+ { 9, OTF_TAG('f', 'p', 'g', 'm')},
+ {17, OTF_TAG('g', 'a', 's', 'p')},
+ {13, OTF_TAG('g', 'l', 'y', 'f')},
+ { 7, OTF_TAG('h', 'd', 'm', 'x')},
+ { 0, OTF_TAG('h', 'e', 'a', 'd')},
+ { 1, OTF_TAG('h', 'h', 'e', 'a')},
+ { 4, OTF_TAG('h', 'm', 't', 'x')},
+ {14, OTF_TAG('k', 'e', 'r', 'n')},
+ {12, OTF_TAG('l', 'o', 'c', 'a')},
+ { 2, OTF_TAG('m', 'a', 'x', 'p')},
+ {15, OTF_TAG('n', 'a', 'm', 'e')},
+ {16, OTF_TAG('p', 'o', 's', 't')},
+ {10, OTF_TAG('p', 'r', 'e', 'p')}
+};
// }}}
-int otf_write_sfnt(struct _OTF_WRITE *otw,unsigned int version,int numTables,OUTPUT_FN output,void *context) // {{{
+
+int
+otf_write_sfnt(struct _OTF_WRITE *otw,
+ unsigned int version,
+ int numTables,
+ OUTPUT_FN output,
+ void *context) // {{{
{
int iA;
int ret;
- int *order=malloc(sizeof(int)*numTables); // temporary
- char *start=malloc(12+16*numTables);
- if ( (!order)||(!start) ) {
- fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
+ int *order = malloc(sizeof(int) * numTables); // temporary
+ char *start = malloc(12 + 16 * numTables);
+ if ((!order) || (!start))
+ {
+ fprintf(stderr, "Bad alloc: %s\n", strerror(errno));
free(order);
free(start);
- return -1;
+ return (-1);
}
- if (1) { // sort tables
- int priolist[NUM_PRIO]={0,};
+ if (1) // sort tables
+ {
+ int priolist[NUM_PRIO] = {0, };
// reverse intersection of both sorted arrays
- int iA=numTables-1,iB=sizeof(otf_tagorder_win)/sizeof(otf_tagorder_win[0])-1;
- int ret=numTables-1;
- while ( (iA>=0)&&(iB>=0) ) {
- if (otw[iA].tag==otf_tagorder_win[iB].tag) {
- priolist[otf_tagorder_win[iB--].prio]=1+iA--;
- } else if (otw[iA].tag>otf_tagorder_win[iB].tag) { // no order known: put unchanged at end of result
- order[ret--]=iA--;
- } else { // <
- iB--;
- }
+ int iA = numTables - 1,
+ iB = sizeof(otf_tagorder_win) / sizeof(otf_tagorder_win[0]) - 1;
+ int ret = numTables - 1;
+ while ((iA >= 0) && (iB >= 0))
+ {
+ if (otw[iA].tag == otf_tagorder_win[iB].tag)
+ priolist[otf_tagorder_win[iB--].prio] = 1 + iA--;
+ else if (otw[iA].tag > otf_tagorder_win[iB].tag)
+ // no order known: put unchanged at end of result
+ order[ret--] = iA--;
+ else // <
+ iB --;
}
- for (iA=NUM_PRIO-1;iA>=0;iA--) { // pick the matched tables up in sorted order (bucketsort principle)
- if (priolist[iA]) {
- order[ret--]=priolist[iA]-1;
- }
- }
- } else {
- for (iA=0;iA<numTables;iA++) {
- order[iA]=iA;
+ for (iA=NUM_PRIO - 1; iA >= 0; iA --)
+ {
+ // pick the matched tables up in sorted order (bucketsort principle)
+ if (priolist[iA])
+ order[ret--] = priolist[iA] - 1;
}
}
+ else
+ {
+ for (iA = 0; iA < numTables; iA ++)
+ order[iA] = iA;
+ }
// the header
- set_ULONG(start,version);
- set_USHORT(start+4,numTables);
- int a,b,c;
- otf_bsearch_params(numTables,16,&a,&b,&c);
- set_USHORT(start+6,a);
- set_USHORT(start+8,b);
- set_USHORT(start+10,c);
+ set_ULONG(start, version);
+ set_USHORT(start + 4, numTables);
+ int a, b, c;
+ otf_bsearch_params(numTables, 16, &a, &b, &c);
+ set_USHORT(start + 6, a);
+ set_USHORT(start + 8, b);
+ set_USHORT(start + 10, c);
// first pass: calculate table directory / offsets and checksums
- unsigned int globalSum=0,csum;
- int offset=12+16*numTables;
- int headAt=-1;
- for (iA=0;iA<numTables;iA++) {
- char *entry=start+12+16*order[iA];
- const int res=(*otw[order[iA]].action)(otw[order[iA]].param,otw[order[iA]].length,NULL,&csum);
- DEBUG_assert(res>=0);
- if (otw[order[iA]].tag==OTF_TAG('h','e','a','d')) {
- headAt=order[iA];
- }
- set_ULONG(entry,otw[order[iA]].tag);
- set_ULONG(entry+4,csum);
- set_ULONG(entry+8,offset);
- set_ULONG(entry+12,res);
- offset+=(res+3)&~3; // padding
- globalSum+=csum;
+ unsigned int globalSum = 0, csum;
+ int offset = 12 + 16 * numTables;
+ int headAt = -1;
+ for (iA = 0; iA < numTables; iA ++)
+ {
+ char *entry = start + 12 + 16 * order[iA];
+ const int res = (*otw[order[iA]].action)(otw[order[iA]].param,
+ otw[order[iA]].length, NULL,
+ &csum);
+ DEBUG_assert(res >= 0);
+ if (otw[order[iA]].tag == OTF_TAG('h', 'e', 'a', 'd'))
+ headAt = order[iA];
+ set_ULONG(entry, otw[order[iA]].tag);
+ set_ULONG(entry + 4, csum);
+ set_ULONG(entry + 8, offset);
+ set_ULONG(entry + 12, res);
+ offset += (res + 3) & ~3; // padding
+ globalSum += csum;
}
// second pass: write actual data
// write header + directory
- ret=12+16*numTables;
- (*output)(start,ret,context);
- globalSum+=otf_checksum(start,ret);
+ ret= 12 + 16 * numTables;
+ (*output)(start, ret, context);
+ globalSum += otf_checksum(start, ret);
// change head
- if ( (headAt!=-1)&&(otw[headAt].action==otf_action_copy) ) { // more needed?
- otw[headAt].action=otf_action_copy_head;
- otw[headAt].length=globalSum;
+ if ((headAt != -1) && (otw[headAt].action == otf_action_copy)) // more needed?
+ {
+ otw[headAt].action = otf_action_copy_head;
+ otw[headAt].length = globalSum;
}
// write tables
- for (iA=0;iA<numTables;iA++) {
- const int res=(*otw[order[iA]].action)(otw[order[iA]].param,otw[order[iA]].length,output,context);
- if (res<0) {
+ for (iA = 0; iA < numTables; iA ++)
+ {
+ const int res = (*otw[order[iA]].action)(otw[order[iA]].param,
+ otw[order[iA]].length,
+ output, context);
+ if (res < 0)
+ {
free(order);
free(start);
- return -1;
+ return (-1);
}
- DEBUG_assert(((res+3)&~3)==res); // correctly padded? (i.e. next line is just ret+=res;)
- ret+=(res+3)&~3;
+ DEBUG_assert(((res + 3) & ~3) == res);
+ // correctly padded? (i.e. next line is just ret += res;)
+ ret += (res + 3) & ~3;
}
- DEBUG_assert(offset==ret);
+ DEBUG_assert(offset == ret);
free(order);
free(start);
- return ret;
+ return (ret);
}
// }}}
-
-#ifndef _SFNT_H
-#define _SFNT_H
+#ifndef _FONTEMBED_SFNT_H_
+#define _FONTEMBED_SFNT_H_
#include <stdio.h>
-typedef struct {
+typedef struct
+{
unsigned int tag;
unsigned int checkSum;
unsigned int offset;
unsigned int length;
} OTF_DIRENT;
-typedef struct {
+typedef struct
+{
FILE *f;
- unsigned int numTTC,useTTC;
+ unsigned int numTTC, useTTC;
unsigned int version;
unsigned short numTables;
// optionally loaded data
unsigned int *glyphOffsets;
unsigned short numberOfHMetrics;
- char *hmtx,*name,*cmap;
+ char *hmtx, *name, *cmap;
const char *unimap; // ptr to (3,1) or (3,0) cmap start
// single glyf buffer, allocated large enough by otf_load_more()
OTF_DIRENT *glyfTable;
} OTF_FILE;
+
#define OTF_F_FMT_CFF 0x10000
#define OTF_F_DO_CHECKSUM 0x40000
OTF_FILE *otf_load(const char *file);
void otf_close(OTF_FILE *otf);
-#define OTF_TAG(a,b,c,d) (unsigned int)( ((a)<<24)|((b)<<16)|((c)<<8)|(d) )
-#define OTF_UNTAG(a) (((unsigned int)(a)>>24)&0xff),(((unsigned int)(a)>>16)&0xff),\
- (((unsigned int)(a)>>8)&0xff),(((unsigned int)(a))&0xff)
+#define OTF_TAG(a, b, c, d) (unsigned int)(((a) << 24) | ((b) << 16) | \
+ ((c) << 8) | (d))
+#define OTF_UNTAG(a) (((unsigned int)(a) >> 24) & 0xff), \
+ (((unsigned int)(a) >> 16) & 0xff), \
+ (((unsigned int)(a) >> 8) & 0xff), \
+ (((unsigned int)(a)) & 0xff)
-char *otf_get_table(OTF_FILE *otf,unsigned int tag,int *ret_len);
+char *otf_get_table(OTF_FILE *otf, unsigned int tag, int *ret_len);
-int otf_get_width(OTF_FILE *otf,unsigned short gid);
-const char *otf_get_name(OTF_FILE *otf,int platformID,int encodingID,int languageID,int nameID,int *ret_len);
-int otf_get_glyph(OTF_FILE *otf,unsigned short gid);
-unsigned short otf_from_unicode(OTF_FILE *otf,int unicode);
+int otf_get_width(OTF_FILE *otf, unsigned short gid);
+const char *otf_get_name(OTF_FILE *otf, int platformID, int encodingID,
+ int languageID, int nameID, int *ret_len);
+int otf_get_glyph(OTF_FILE *otf, unsigned short gid);
+unsigned short otf_from_unicode(OTF_FILE *otf, int unicode);
#include "bitset.h"
#include "iofn.h"
// TODO?! allow glyphs==NULL for non-subsetting table reduction?
-int otf_subset(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context);
-int otf_ttc_extract(OTF_FILE *otf,OUTPUT_FN output,void *context);
-int otf_subset_cff(OTF_FILE *otf,BITSET glyphs,OUTPUT_FN output,void *context);
-int otf_cff_extract(OTF_FILE *otf,OUTPUT_FN output,void *context);
+int otf_subset(OTF_FILE *otf, BITSET glyphs, OUTPUT_FN output, void *context);
+int otf_ttc_extract(OTF_FILE *otf, OUTPUT_FN output, void *context);
+int otf_subset_cff(OTF_FILE *otf, BITSET glyphs, OUTPUT_FN output,
+ void *context);
+int otf_cff_extract(OTF_FILE *otf, OUTPUT_FN output, void *context);
-#endif
+#endif // !_FONTEMBED_SFNT_H_
#include <stdio.h>
#include <stdlib.h>
-enum { WEIGHT_THIN=100,
- WEIGHT_EXTRALIGHT=200, WEIGHT_ULTRALIGHT=200,
- WEIGHT_LIGHT=300,
- WEIGHT_NORMAL=400, WEIGHT_REGULAR=400,
- WEIGHT_MEDIUM=500,
- WEIGHT_SEMIBOLD=600, // DEMI
- WEIGHT_BOLD=700,
- WEIGHT_EXTRABOLD=800, WEIGHT_ULTRABOLD=800,
- WEIGHT_BLACK=900, WEIGHT_HEAVY=900 };
-
-void show_post(OTF_FILE *otf) // {{{
+
+enum {
+ WEIGHT_THIN = 100,
+ WEIGHT_EXTRALIGHT = 200,
+ WEIGHT_ULTRALIGHT = 200,
+ WEIGHT_LIGHT = 300,
+ WEIGHT_NORMAL = 400,
+ WEIGHT_REGULAR = 400,
+ WEIGHT_MEDIUM = 500,
+ WEIGHT_SEMIBOLD = 600, // DEMI
+ WEIGHT_BOLD = 700,
+ WEIGHT_EXTRABOLD = 800,
+ WEIGHT_ULTRABOLD = 800,
+ WEIGHT_BLACK = 900,
+ WEIGHT_HEAVY=900
+};
+
+
+void
+show_post(OTF_FILE *otf) // {{{
{
DEBUG_assert(otf);
- int len=0;
+ int len = 0;
char *buf;
- buf=otf_get_table(otf,OTF_TAG('p','o','s','t'),&len);
- if (!buf) {
- DEBUG_assert(len==-1);
+ buf = otf_get_table(otf, OTF_TAG('p', 'o', 's', 't'), &len);
+ if (!buf)
+ {
+ DEBUG_assert(len == -1);
printf("No post table\n");
return;
}
" underlineThickness: %d\n"
" isFixedPitch: %d\n"
" vmType42: %d %d\n"
- " vmType1: %d %d\n",len,
+ " vmType1: %d %d\n",
+ len,
get_ULONG(buf),
- get_LONG(buf+4)>>16,get_ULONG(buf+4)&0xffff,
- get_SHORT(buf+8),
- get_SHORT(buf+10),
- get_ULONG(buf+12),
- get_ULONG(buf+16),get_ULONG(buf+20),
- get_ULONG(buf+24),get_ULONG(buf+38));
+ get_LONG(buf + 4) >> 16,
+ get_ULONG(buf + 4) & 0xffff,
+ get_SHORT(buf + 8),
+ get_SHORT(buf + 10),
+ get_ULONG(buf + 12),
+ get_ULONG(buf + 16),
+ get_ULONG(buf + 20),
+ get_ULONG(buf + 24),
+ get_ULONG(buf + 38));
free(buf);
}
// }}}
-void show_name(OTF_FILE *otf) // {{{
+
+void
+show_name(OTF_FILE *otf) // {{{
{
DEBUG_assert(otf);
- int iA,len=0;
+ int iA, len = 0;
char *buf;
- buf=otf_get_table(otf,OTF_TAG('n','a','m','e'),&len);
- if (!buf) {
- DEBUG_assert(len==-1);
+ buf = otf_get_table(otf, OTF_TAG('n', 'a', 'm', 'e'), &len);
+ if (!buf)
+ {
+ DEBUG_assert(len == -1);
printf("No name table\n");
return;
}
printf("NAME:\n");
- int name_count=get_USHORT(buf+2);
- const char *nstore=buf+get_USHORT(buf+4);
- for (iA=0;iA<name_count;iA++) {
- const char *nrec=buf+6+12*iA;
+ int name_count = get_USHORT(buf + 2);
+ const char *nstore = buf + get_USHORT(buf + 4);
+ for (iA = 0; iA < name_count; iA ++)
+ {
+ const char *nrec = buf + 6 + 12 * iA;
printf(" { platformID/encodingID/languageID/nameID: %d/%d/%d/%d\n"
" length: %d, offset: %d, data :",
get_USHORT(nrec),
- get_USHORT(nrec+2),
- get_USHORT(nrec+4),
- get_USHORT(nrec+6),
- get_USHORT(nrec+8),
- get_USHORT(nrec+10));
- if ( (get_USHORT(nrec)==0)||
- ( (get_USHORT(nrec)==3) ) ) { // WCHAR
- int nlen=get_USHORT(nrec+8);
- int npos=get_USHORT(nrec+10);
- for (;nlen>0;nlen-=2,npos+=2) {
- if (nstore[npos]!=0x00) {
+ get_USHORT(nrec + 2),
+ get_USHORT(nrec + 4),
+ get_USHORT(nrec + 6),
+ get_USHORT(nrec + 8),
+ get_USHORT(nrec + 10));
+ if ((get_USHORT(nrec) == 0) ||
+ (get_USHORT(nrec) == 3)) // WCHAR
+ {
+ int nlen = get_USHORT(nrec + 8);
+ int npos = get_USHORT(nrec + 10);
+ for (; nlen > 0; nlen -= 2, npos += 2)
+ {
+ if (nstore[npos] != 0x00)
printf("?");
- } else {
- printf("%c",nstore[npos+1]);
- }
+ else
+ printf("%c", nstore[npos + 1]);
}
printf(" }\n");
- } else {
- printf("%.*s }\n",
- get_USHORT(nrec+8),nstore+get_USHORT(nrec+10));
}
+ else
+ printf("%.*s }\n",
+ get_USHORT(nrec + 8), nstore + get_USHORT(nrec + 10));
}
free(buf);
}
// }}}
-void show_cmap(OTF_FILE *otf) // {{{
+
+void
+show_cmap(OTF_FILE *otf) // {{{
{
DEBUG_assert(otf);
- int iA,len=0;
+ int iA, len = 0;
- char *cmap=otf_get_table(otf,OTF_TAG('c','m','a','p'),&len);
- if (!cmap) {
- DEBUG_assert(len==-1);
+ char *cmap = otf_get_table(otf, OTF_TAG('c', 'm', 'a', 'p'), &len);
+ if (!cmap)
+ {
+ DEBUG_assert(len == -1);
printf("No cmap table\n");
return;
}
printf("cmap:\n");
- DEBUG_assert(get_USHORT(cmap)==0x0000); // version
- const int numTables=get_USHORT(cmap+2);
- printf(" numTables: %d\n",numTables);
- for (iA=0;iA<numTables;iA++) {
- const char *nrec=cmap+4+8*iA;
- const char *ndata=cmap+get_ULONG(nrec+4);
- DEBUG_assert(ndata>=cmap+4+8*numTables);
+ DEBUG_assert(get_USHORT(cmap) == 0x0000); // version
+ const int numTables = get_USHORT(cmap + 2);
+ printf(" numTables: %d\n", numTables);
+ for (iA = 0; iA < numTables; iA ++)
+ {
+ const char *nrec = cmap + 4 + 8 * iA;
+ const char *ndata = cmap + get_ULONG(nrec + 4);
+ DEBUG_assert(ndata >= cmap + 4 + 8 * numTables);
printf(" platformID/encodingID: %d/%d\n"
" offset: %d data (format: %d, length: %d, language: %d);\n",
- get_USHORT(nrec),get_USHORT(nrec+2),
- get_ULONG(nrec+4),
- get_USHORT(ndata),get_USHORT(ndata+2),get_USHORT(ndata+4));
+ get_USHORT(nrec), get_USHORT(nrec + 2),
+ get_ULONG(nrec + 4),
+ get_USHORT(ndata), get_USHORT(ndata + 2), get_USHORT(ndata + 4));
}
free(cmap);
}
// }}}
-void show_glyf(OTF_FILE *otf,int full) // {{{
+
+void
+show_glyf(OTF_FILE *otf,
+ int full) // {{{
{
DEBUG_assert(otf);
// ensure >glyphOffsets and >gly is there
- if ( (!otf->gly)||(!otf->glyphOffsets) ) {
- if (otf_load_glyf(otf)!=0) {
+ if ((!otf->gly) || (!otf->glyphOffsets))
+ {
+ if (otf_load_glyf(otf) != 0)
+ {
DEBUG_assert(0);
return;
}
}
int iA;
- int compGlyf=0,zeroGlyf=0;
+ int compGlyf = 0, zeroGlyf = 0;
// {{{ glyf
DEBUG_assert(otf->gly);
- for (iA=0;iA<otf->numGlyphs;iA++) {
- int len=otf_get_glyph(otf,iA);
- if (len==0) {
- zeroGlyf++;
- } else if (get_SHORT(otf->gly)==-1) {
- compGlyf++;
- }
- if (full) {
- printf("%d(%d) ",get_SHORT(otf->gly),len);
- }
+ for (iA = 0; iA < otf->numGlyphs; iA ++)
+ {
+ int len = otf_get_glyph(otf, iA);
+ if (len == 0)
+ zeroGlyf ++;
+ else if (get_SHORT(otf->gly) == -1)
+ compGlyf ++;
+ if (full)
+ printf("%d(%d) ", get_SHORT(otf->gly), len);
}
- if (full) {
+ if (full)
printf("\n");
- }
- printf("numGlyf(nonnull): %d(%d), composites: %d\n",otf->numGlyphs,otf->numGlyphs-zeroGlyf,compGlyf);
+ printf("numGlyf(nonnull): %d(%d), composites: %d\n", otf->numGlyphs,
+ otf->numGlyphs - zeroGlyf, compGlyf);
// }}}
}
// }}}
-void show_hmtx(OTF_FILE *otf) // {{{
+
+void
+show_hmtx(OTF_FILE *otf) // {{{
{
DEBUG_assert(otf);
int iA;
- otf_get_width(otf,0); // load table.
- if (!otf->hmtx) {
+ otf_get_width(otf, 0); // load table.
+ if (!otf->hmtx)
+ {
printf("NOTE: no hmtx table!\n");
return;
}
- printf("hmtx (%d):\n",otf->numberOfHMetrics);
- for (iA=0;iA<otf->numberOfHMetrics;iA++) {
+ printf("hmtx (%d):\n", otf->numberOfHMetrics);
+ for (iA = 0; iA < otf->numberOfHMetrics; iA ++)
+ {
printf("(%d,%d) ",
- get_USHORT(otf->hmtx+iA*4),
- get_SHORT(otf->hmtx+iA*4+2));
+ get_USHORT(otf->hmtx + iA * 4),
+ get_SHORT(otf->hmtx + iA * 4 + 2));
}
- printf(" (last is repeated for the remaining %d glyphs)\n",otf->numGlyphs-otf->numberOfHMetrics);
+ printf(" (last is repeated for the remaining %d glyphs)\n",
+ otf->numGlyphs - otf->numberOfHMetrics);
}
// }}}
-int main(int argc,char **argv)
+int
+main(int argc,
+ char **argv)
{
- const char *fn=TESTFONT;
- OTF_FILE *otf=NULL;
- if (argc==2) {
- fn=argv[1];
- }
- otf=otf_load(fn);
+ const char *fn = TESTFONT;
+ OTF_FILE *otf = NULL;
+ if (argc == 2)
+ fn = argv[1];
+ otf = otf_load(fn);
if (!otf)
{
printf("Font %s was not loaded, exiting.\n", TESTFONT);
- return 1;
+ return (1);
}
DEBUG_assert(otf);
- if (otf->numTTC) {
- printf("TTC has %d fonts, using %d\n",otf->numTTC,otf->useTTC);
- }
- if (otf->version==0x00010000) {
+ if (otf->numTTC)
+ printf("TTC has %d fonts, using %d\n", otf->numTTC, otf->useTTC);
+ if (otf->version == 0x00010000)
printf("Got TTF 1.0\n");
- } else if (otf->version==OTF_TAG('O','T','T','O')) {
+ else if (otf->version == OTF_TAG('O','T','T','O'))
printf("Got OTF(CFF)\n");
- } else if (otf->version==OTF_TAG('t','r','u','e')) {
+ else if (otf->version == OTF_TAG('t','r','u','e'))
printf("Got TTF (true)\n");
- } else if (otf->version==OTF_TAG('t','y','p','1')) {
+ else if (otf->version == OTF_TAG('t','y','p','1'))
printf("Got SFNT(Type1)\n");
- }
- printf("Has %d tables\n",otf->numTables);
+ printf("Has %d tables\n", otf->numTables);
int iA;
- for (iA=0;iA<otf->numTables;iA++) {
- printf("%c%c%c%c %d @%d\n",OTF_UNTAG(otf->tables[iA].tag),otf->tables[iA].length,otf->tables[iA].offset);
+ for (iA=0; iA < otf->numTables; iA ++)
+ {
+ printf("%c%c%c%c %d @%d\n", OTF_UNTAG(otf->tables[iA].tag),
+ otf->tables[iA].length, otf->tables[iA].offset);
}
printf("unitsPerEm: %d, indexToLocFormat: %d\n",
- otf->unitsPerEm,otf->indexToLocFormat);
- printf("num glyphs: %d\n",otf->numGlyphs);
- otf_get_width(otf,0); // load table.
- printf("numberOfHMetrics: %d\n",otf->numberOfHMetrics);
+ otf->unitsPerEm, otf->indexToLocFormat);
+ printf("num glyphs: %d\n", otf->numGlyphs);
+ otf_get_width(otf, 0); // load table.
+ printf("numberOfHMetrics: %d\n", otf->numberOfHMetrics);
- printf("Embedding rights: %x\n",emb_otf_get_rights(otf));
+ printf("Embedding rights: %x\n", emb_otf_get_rights(otf));
show_post(otf);
show_name(otf);
show_cmap(otf);
- // printf("%d %d\n",otf_from_unicode(otf,'A'),0);
+ // printf("%d %d\n", otf_from_unicode(otf, 'A'), 0);
- if (!(otf->flags&OTF_F_FMT_CFF)) {
- show_glyf(otf,1);
- }
+ if (!(otf->flags & OTF_F_FMT_CFF))
+ show_glyf(otf, 1);
show_hmtx(otf);
otf_close(otf);
- return 0;
+ return (0);
}
#include <stdio.h>
#include <stdlib.h>
-static void example_outfn(const char *buf,int len,void *context) // {{{
+
+static void
+example_outfn(const char *buf,
+ int len,
+ void *context) // {{{
{
- FILE *f=(FILE *)context;
- if (fwrite(buf,1,len,f)!=len) {
- fprintf(stderr,"Short write: %m\n");
+ FILE *f = (FILE *)context;
+ if (fwrite(buf, 1, len, f) != len)
+ {
+ fprintf(stderr, "Short write: %m\n");
DEBUG_assert(0);
return;
}
}
// }}}
+
#define OBJ \
- xref[xrefpos++]=ftell(f); \
- fprintf(f,"%d 0 obj\n",xrefpos);
+ xref[xrefpos++] = ftell(f); \
+ fprintf(f, "%d 0 obj\n", xrefpos);
#define ENDOBJ \
- fprintf(f,"endobj\n");
+ fprintf(f, "endobj\n");
#define STREAMDICT \
OBJ; \
- fprintf(f,"<<\n" \
- " /Length %d 0 R\n",xrefpos+1);
+ fprintf(f, "<<\n" \
+ " /Length %d 0 R\n", xrefpos + 1);
#define STREAMDATA \
- fprintf(f,">>\n" \
- "stream\n"); \
- stream_len=-ftell(f);
+ fprintf(f, ">>\n" \
+ "stream\n"); \
+ stream_len = -ftell(f);
#define STREAM \
STREAMDICT \
STREAMDATA
#define ENDSTREAM \
- stream_len+=ftell(f); \
- fprintf(f,"endstream\n" \
- "endobj\n"); \
+ stream_len += ftell(f); \
+ fprintf(f, "endstream\n" \
+ "endobj\n"); \
OBJ; \
- fprintf(f,"%d\n",stream_len); \
+ fprintf(f, "%d\n", stream_len); \
ENDOBJ;
-static inline void write_string(FILE *f,EMB_PARAMS *emb,const char *str) // {{{
+
+static inline void
+write_string(FILE *f,
+ EMB_PARAMS *emb,
+ const char *str) // {{{
{
DEBUG_assert(f);
DEBUG_assert(emb);
int iA;
- if (emb->plan&EMB_A_MULTIBYTE) {
- putc('<',f);
- for (iA=0;str[iA];iA++) {
- const unsigned short gid=emb_get(emb,(unsigned char)str[iA]);
- fprintf(f,"%04x",gid);
- }
- putc('>',f);
- } else {
- putc('(',f);
- for (iA=0;str[iA];iA++) {
- emb_get(emb,(unsigned char)str[iA]);
+ if (emb->plan & EMB_A_MULTIBYTE)
+ {
+ putc('<', f);
+ for (iA = 0; str[iA]; iA ++)
+ {
+ const unsigned short gid = emb_get(emb, (unsigned char)str[iA]);
+ fprintf(f, "%04x", gid);
}
- fprintf(f,"%s",str); // TODO
- putc(')',f);
+ putc('>', f);
+ }
+ else
+ {
+ putc('(', f);
+ for (iA = 0; str[iA]; iA ++)
+ emb_get(emb, (unsigned char)str[iA]);
+ fprintf(f, "%s", str); // TODO
+ putc(')', f);
}
}
// }}}
-int main(int argc,char **argv)
+
+int
+main(int argc,
+ char **argv)
{
- const char *fn=TESTFONT;
- OTF_FILE *otf=NULL;
- if (argc==2) {
- fn=argv[1];
- }
- otf=otf_load(fn);
+ const char *fn = TESTFONT;
+ OTF_FILE *otf = NULL;
+ if (argc == 2)
+ fn = argv[1];
+ otf = otf_load(fn);
if (!otf)
{
printf("Font %s was not loaded, exiting.\n", TESTFONT);
- return 1;
+ return (1);
}
DEBUG_assert(otf);
- FONTFILE *ff=fontfile_open_sfnt(otf);
- EMB_PARAMS *emb=emb_new(ff,
- EMB_DEST_PDF16,
- EMB_C_FORCE_MULTIBYTE|
- EMB_C_TAKE_FONTFILE);
+ FONTFILE *ff = fontfile_open_sfnt(otf);
+ EMB_PARAMS *emb = emb_new(ff,
+ EMB_DEST_PDF16,
+ EMB_C_FORCE_MULTIBYTE|
+ EMB_C_TAKE_FONTFILE);
- FILE *f=fopen("test.pdf","w");
+ FILE *f = fopen("test.pdf", "w");
DEBUG_assert(f);
- int xref[100],xrefpos=3;
+ int xref[100], xrefpos = 3;
int stream_len;
- fprintf(f,"%%PDF-1.3\n");
+ fprintf(f, "%%PDF-1.3\n");
// content
STREAM;
- fprintf(f,"BT\n" // content
- " 100 100 Td\n"
- " /F1 10 Tf\n");
- write_string(f,emb,"Hallo");
- fprintf(f," Tj\n"
- "ET\n");
+ fprintf(f, "BT\n" // content
+ " 100 100 Td\n"
+ " /F1 10 Tf\n");
+ write_string(f, emb, "Hallo");
+ fprintf(f, " Tj\n"
+ "ET\n");
ENDSTREAM;
- emb_get(emb,'a');
+ emb_get(emb, 'a');
// {{{ do font
- EMB_PDF_FONTDESCR *fdes=emb_pdf_fontdescr(emb);
+ EMB_PDF_FONTDESCR *fdes = emb_pdf_fontdescr(emb);
DEBUG_assert(fdes);
- EMB_PDF_FONTWIDTHS *fwid=emb_pdf_fontwidths(emb);
+ EMB_PDF_FONTWIDTHS *fwid = emb_pdf_fontwidths(emb);
DEBUG_assert(fwid);
STREAMDICT;
- int ff_ref=xrefpos;
- if (emb_pdf_get_fontfile_subtype(emb)) {
+ int ff_ref = xrefpos;
+ if (emb_pdf_get_fontfile_subtype(emb))
+ {
fprintf(f," /Subtype /%s\n",
- emb_pdf_get_fontfile_subtype(emb));
- }
- if (emb->outtype==EMB_FMT_T1) {
- fprintf(f," /Length1 ?\n"
- " /Length2 ?\n"
- " /Length3 ?\n");
- } else if (emb->outtype==EMB_FMT_TTF) {
- fprintf(f," /Length1 %d 0 R\n",xrefpos+2);
+ emb_pdf_get_fontfile_subtype(emb));
}
+ if (emb->outtype == EMB_FMT_T1)
+ fprintf(f, " /Length1 ?\n"
+ " /Length2 ?\n"
+ " /Length3 ?\n");
+ else if (emb->outtype == EMB_FMT_TTF)
+ fprintf(f, " /Length1 %d 0 R\n", xrefpos + 2);
STREAMDATA;
- const int outlen=emb_embed(emb,example_outfn,f);
+ const int outlen = emb_embed(emb, example_outfn, f);
ENDSTREAM;
- if (emb->outtype==EMB_FMT_TTF) {
+ if (emb->outtype == EMB_FMT_TTF)
+ {
OBJ;
- fprintf(f,"%d\n",outlen);
+ fprintf(f, "%d\n", outlen);
ENDOBJ;
}
OBJ;
- const int fd_ref=xrefpos;
- char *res=emb_pdf_simple_fontdescr(emb,fdes,ff_ref);
+ const int fd_ref = xrefpos;
+ char *res = emb_pdf_simple_fontdescr(emb, fdes, ff_ref);
DEBUG_assert(res);
- fputs(res,f);
+ fputs(res, f);
free(res);
ENDOBJ;
OBJ;
- int f_ref=xrefpos;
- res=emb_pdf_simple_font(emb,fdes,fwid,fd_ref);
+ int f_ref = xrefpos;
+ res = emb_pdf_simple_font(emb, fdes, fwid, fd_ref);
DEBUG_assert(res);
- fputs(res,f);
+ fputs(res, f);
free(res);
ENDOBJ;
- if (emb->plan&EMB_A_MULTIBYTE) {
+ if (emb->plan&EMB_A_MULTIBYTE)
+ {
OBJ;
- res=emb_pdf_simple_cidfont(emb,fdes->fontname,f_ref);
- f_ref=xrefpos;
+ res = emb_pdf_simple_cidfont(emb, fdes->fontname, f_ref);
+ f_ref = xrefpos;
DEBUG_assert(res);
- fputs(res,f);
+ fputs(res, f);
free(res);
ENDOBJ;
}
int iA;
- xref[2]=ftell(f);
- fprintf(f,"3 0 obj\n"
- "<</Type/Page\n"
- " /Parent 2 0 R\n"
- " /MediaBox [0 0 595 842]\n"
- " /Contents 4 0 R\n"
- " /Resources <<\n"
- " /Font <<\n"
- " /F1 %d 0 R\n"
- " >>\n"
- " >>\n"
- ">>\n"
- "endobj\n",
- f_ref);
- xref[1]=ftell(f);
- fprintf(f,"2 0 obj\n"
- "<</Type/Pages\n"
- " /Count 1\n"
- " /Kids [3 0 R]"
- ">>\n"
- "endobj\n");
- xref[0]=ftell(f);
- fprintf(f,"1 0 obj\n"
- "<</Type/Catalog\n"
- " /Pages 2 0 R\n"
- ">>\n"
- "endobj\n");
+ xref[2] = ftell(f);
+ fprintf(f, "3 0 obj\n"
+ "<</Type/Page\n"
+ " /Parent 2 0 R\n"
+ " /MediaBox [0 0 595 842]\n"
+ " /Contents 4 0 R\n"
+ " /Resources <<\n"
+ " /Font <<\n"
+ " /F1 %d 0 R\n"
+ " >>\n"
+ " >>\n"
+ ">>\n"
+ "endobj\n",
+ f_ref);
+ xref[1] = ftell(f);
+ fprintf(f, "2 0 obj\n"
+ "<</Type/Pages\n"
+ " /Count 1\n"
+ " /Kids [3 0 R]"
+ ">>\n"
+ "endobj\n");
+ xref[0] = ftell(f);
+ fprintf(f, "1 0 obj\n"
+ "<</Type/Catalog\n"
+ " /Pages 2 0 R\n"
+ ">>\n"
+ "endobj\n");
// {{{ pdf trailer
- int xref_start=ftell(f);
- fprintf(f,"xref\n"
- "0 %d\n"
- "%010d 65535 f \n",
- xrefpos+1,0);
- for (iA=0;iA<xrefpos;iA++) {
- fprintf(f,"%010d 00000 n \n",xref[iA]);
- }
- fprintf(f,"trailer\n"
- "<<\n"
- " /Size %d\n"
- " /Root 1 0 R\n"
- ">>\n"
- "startxref\n"
- "%d\n"
- "%%%%EOF\n",
- xrefpos+1,xref_start);
+ int xref_start = ftell(f);
+ fprintf(f, "xref\n"
+ "0 %d\n"
+ "%010d 65535 f \n",
+ xrefpos + 1,0);
+ for (iA = 0; iA < xrefpos; iA ++)
+ fprintf(f, "%010d 00000 n \n", xref[iA]);
+ fprintf(f, "trailer\n"
+ "<<\n"
+ " /Size %d\n"
+ " /Root 1 0 R\n"
+ ">>\n"
+ "startxref\n"
+ "%d\n"
+ "%%%%EOF\n",
+ xrefpos + 1, xref_start);
// }}}
fclose(f);
emb_close(emb);
- return 0;
+ return (0);
}
const char *emb_otf_get_fontname(OTF_FILE *otf); // TODO
-static void example_outfn(const char *buf,int len,void *context) // {{{
+
+static void
+example_outfn(const char *buf,
+ int len,
+ void *context) // {{{
{
- FILE *f=(FILE *)context;
- if (fwrite(buf,1,len,f)!=len) {
- fprintf(stderr,"Short write: %m\n");
+ FILE *f = (FILE *)context;
+ if (fwrite(buf, 1, len, f) != len)
+ {
+ fprintf(stderr, "Short write: %m\n");
DEBUG_assert(0);
return;
}
}
// }}}
-static inline void write_string(FILE *f,EMB_PARAMS *emb,const char *str) // {{{
+
+static inline void
+write_string(FILE *f,
+ EMB_PARAMS *emb,
+ const char *str) // {{{
{
DEBUG_assert(f);
DEBUG_assert(emb);
int iA;
- if (emb->plan&EMB_A_MULTIBYTE) {
- putc('<',f);
- for (iA=0;str[iA];iA++) {
- const unsigned short gid=emb_get(emb,(unsigned char)str[iA]);
- fprintf(f,"%04x",gid);
- }
- putc('>',f);
- } else {
- putc('(',f);
- for (iA=0;str[iA];iA++) {
- emb_get(emb,(unsigned char)str[iA]);
+ if (emb->plan & EMB_A_MULTIBYTE)
+ {
+ putc('<', f);
+ for (iA=0; str[iA] ;iA ++)
+ {
+ const unsigned short gid = emb_get(emb, (unsigned char)str[iA]);
+ fprintf(f, "%04x", gid);
}
- fprintf(f,"%s",str); // TODO
- putc(')',f);
+ putc('>', f);
+ }
+ else
+ {
+ putc('(', f);
+ for (iA = 0; str[iA]; iA ++)
+ emb_get(emb, (unsigned char)str[iA]);
+ fprintf(f, "%s", str); // TODO
+ putc(')', f);
}
}
// }}}
-int main(int argc,char **argv)
+
+int
+main(int argc,
+ char **argv)
{
- const char *fn=TESTFONT;
- OTF_FILE *otf=NULL;
- if (argc==2) {
- fn=argv[1];
- }
- otf=otf_load(fn);
+ const char *fn = TESTFONT;
+ OTF_FILE *otf = NULL;
+ if (argc == 2)
+ fn = argv[1];
+ otf = otf_load(fn);
if (!otf)
{
printf("Font %s was not loaded, exiting.\n", TESTFONT);
- return 1;
+ return (1);
}
DEBUG_assert(otf);
- FONTFILE *ff=fontfile_open_sfnt(otf);
- EMB_PARAMS *emb=emb_new(ff,
- EMB_DEST_PS,
+ FONTFILE *ff = fontfile_open_sfnt(otf);
+ EMB_PARAMS *emb = emb_new(ff,
+ EMB_DEST_PS,
// EMB_C_FORCE_MULTIBYTE| // not yet...
- EMB_C_TAKE_FONTFILE);
+ EMB_C_TAKE_FONTFILE);
- FILE *f=fopen("test.ps","w");
+ FILE *f = fopen("test.ps", "w");
DEBUG_assert(f);
- fprintf(f,"%%!PS-Adobe-2.0\n");
+ fprintf(f, "%%!PS-Adobe-2.0\n");
- char *str="Hallo";
+ char *str = "Hallo";
- emb_get(emb,'a');
+ emb_get(emb, 'a');
int iA;
- for (iA=0;str[iA];iA++) {
- emb_get(emb,(unsigned char)str[iA]);
- }
+ for (iA = 0; str[iA]; iA ++)
+ emb_get(emb, (unsigned char)str[iA]);
- emb_embed(emb,example_outfn,f);
+ emb_embed(emb, example_outfn, f);
// content
- fprintf(f," 100 100 moveto\n" // content
- " /%s findfont 10 scalefont setfont\n",emb_otf_get_fontname(emb->font->sfnt));
- write_string(f,emb,"Hallo");
-// Note that write_string sets subset bits, but it's too late
- fprintf(f," show\n"
- "showpage\n");
-
- fprintf(f,"%%%%EOF\n");
+ fprintf(f, " 100 100 moveto\n" // content
+ " /%s findfont 10 scalefont setfont\n",
+ emb_otf_get_fontname(emb->font->sfnt));
+ write_string(f, emb, "Hallo");
+ // Note that write_string sets subset bits, but it's too late
+ fprintf(f, " show\n"
+ "showpage\n");
+
+ fprintf(f, "%%%%EOF\n");
fclose(f);
emb_close(emb);
- return 0;
+ return (0);
}