gen.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // Copyright 2017 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build ignore
  5. package main
  6. import (
  7. "bytes"
  8. "fmt"
  9. "go/format"
  10. "io/ioutil"
  11. "log"
  12. )
  13. func main() {
  14. data, offsets := []byte(nil), []int{0}
  15. for _, name := range names {
  16. data = append(data, name...)
  17. offsets = append(offsets, len(data))
  18. }
  19. b := new(bytes.Buffer)
  20. fmt.Fprintf(b, "// generated by go run gen.go; DO NOT EDIT\n\n")
  21. fmt.Fprintf(b, "package sfnt\n\n")
  22. fmt.Fprintf(b, "const numBuiltInPostNames = %d\n\n", len(names))
  23. fmt.Fprintf(b, "const builtInPostNamesData = \"\" +\n")
  24. for s := data; ; {
  25. if len(s) <= 64 {
  26. fmt.Fprintf(b, "%q\n", s)
  27. break
  28. }
  29. fmt.Fprintf(b, "%q +\n", s[:64])
  30. s = s[64:]
  31. }
  32. fmt.Fprintf(b, "\n")
  33. fmt.Fprintf(b, "var builtInPostNamesOffsets = [...]uint16{\n")
  34. for i, o := range offsets {
  35. fmt.Fprintf(b, "%#04x,", o)
  36. if i%8 == 7 {
  37. fmt.Fprintf(b, "\n")
  38. }
  39. }
  40. fmt.Fprintf(b, "\n}\n")
  41. dstUnformatted := b.Bytes()
  42. dst, err := format.Source(dstUnformatted)
  43. if err != nil {
  44. log.Fatalf("format.Source: %v\n\n----\n%s\n----", err, dstUnformatted)
  45. }
  46. if err := ioutil.WriteFile("data.go", dst, 0666); err != nil {
  47. log.Fatalf("ioutil.WriteFile: %v", err)
  48. }
  49. }
  50. // names is the built-in post table names listed at
  51. // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6post.html
  52. var names = [258]string{
  53. ".notdef",
  54. ".null",
  55. "nonmarkingreturn",
  56. "space",
  57. "exclam",
  58. "quotedbl",
  59. "numbersign",
  60. "dollar",
  61. "percent",
  62. "ampersand",
  63. "quotesingle",
  64. "parenleft",
  65. "parenright",
  66. "asterisk",
  67. "plus",
  68. "comma",
  69. "hyphen",
  70. "period",
  71. "slash",
  72. "zero",
  73. "one",
  74. "two",
  75. "three",
  76. "four",
  77. "five",
  78. "six",
  79. "seven",
  80. "eight",
  81. "nine",
  82. "colon",
  83. "semicolon",
  84. "less",
  85. "equal",
  86. "greater",
  87. "question",
  88. "at",
  89. "A",
  90. "B",
  91. "C",
  92. "D",
  93. "E",
  94. "F",
  95. "G",
  96. "H",
  97. "I",
  98. "J",
  99. "K",
  100. "L",
  101. "M",
  102. "N",
  103. "O",
  104. "P",
  105. "Q",
  106. "R",
  107. "S",
  108. "T",
  109. "U",
  110. "V",
  111. "W",
  112. "X",
  113. "Y",
  114. "Z",
  115. "bracketleft",
  116. "backslash",
  117. "bracketright",
  118. "asciicircum",
  119. "underscore",
  120. "grave",
  121. "a",
  122. "b",
  123. "c",
  124. "d",
  125. "e",
  126. "f",
  127. "g",
  128. "h",
  129. "i",
  130. "j",
  131. "k",
  132. "l",
  133. "m",
  134. "n",
  135. "o",
  136. "p",
  137. "q",
  138. "r",
  139. "s",
  140. "t",
  141. "u",
  142. "v",
  143. "w",
  144. "x",
  145. "y",
  146. "z",
  147. "braceleft",
  148. "bar",
  149. "braceright",
  150. "asciitilde",
  151. "Adieresis",
  152. "Aring",
  153. "Ccedilla",
  154. "Eacute",
  155. "Ntilde",
  156. "Odieresis",
  157. "Udieresis",
  158. "aacute",
  159. "agrave",
  160. "acircumflex",
  161. "adieresis",
  162. "atilde",
  163. "aring",
  164. "ccedilla",
  165. "eacute",
  166. "egrave",
  167. "ecircumflex",
  168. "edieresis",
  169. "iacute",
  170. "igrave",
  171. "icircumflex",
  172. "idieresis",
  173. "ntilde",
  174. "oacute",
  175. "ograve",
  176. "ocircumflex",
  177. "odieresis",
  178. "otilde",
  179. "uacute",
  180. "ugrave",
  181. "ucircumflex",
  182. "udieresis",
  183. "dagger",
  184. "degree",
  185. "cent",
  186. "sterling",
  187. "section",
  188. "bullet",
  189. "paragraph",
  190. "germandbls",
  191. "registered",
  192. "copyright",
  193. "trademark",
  194. "acute",
  195. "dieresis",
  196. "notequal",
  197. "AE",
  198. "Oslash",
  199. "infinity",
  200. "plusminus",
  201. "lessequal",
  202. "greaterequal",
  203. "yen",
  204. "mu",
  205. "partialdiff",
  206. "summation",
  207. "product",
  208. "pi",
  209. "integral",
  210. "ordfeminine",
  211. "ordmasculine",
  212. "Omega",
  213. "ae",
  214. "oslash",
  215. "questiondown",
  216. "exclamdown",
  217. "logicalnot",
  218. "radical",
  219. "florin",
  220. "approxequal",
  221. "Delta",
  222. "guillemotleft",
  223. "guillemotright",
  224. "ellipsis",
  225. "nonbreakingspace",
  226. "Agrave",
  227. "Atilde",
  228. "Otilde",
  229. "OE",
  230. "oe",
  231. "endash",
  232. "emdash",
  233. "quotedblleft",
  234. "quotedblright",
  235. "quoteleft",
  236. "quoteright",
  237. "divide",
  238. "lozenge",
  239. "ydieresis",
  240. "Ydieresis",
  241. "fraction",
  242. "currency",
  243. "guilsinglleft",
  244. "guilsinglright",
  245. "fi",
  246. "fl",
  247. "daggerdbl",
  248. "periodcentered",
  249. "quotesinglbase",
  250. "quotedblbase",
  251. "perthousand",
  252. "Acircumflex",
  253. "Ecircumflex",
  254. "Aacute",
  255. "Edieresis",
  256. "Egrave",
  257. "Iacute",
  258. "Icircumflex",
  259. "Idieresis",
  260. "Igrave",
  261. "Oacute",
  262. "Ocircumflex",
  263. "apple",
  264. "Ograve",
  265. "Uacute",
  266. "Ucircumflex",
  267. "Ugrave",
  268. "dotlessi",
  269. "circumflex",
  270. "tilde",
  271. "macron",
  272. "breve",
  273. "dotaccent",
  274. "ring",
  275. "cedilla",
  276. "hungarumlaut",
  277. "ogonek",
  278. "caron",
  279. "Lslash",
  280. "lslash",
  281. "Scaron",
  282. "scaron",
  283. "Zcaron",
  284. "zcaron",
  285. "brokenbar",
  286. "Eth",
  287. "eth",
  288. "Yacute",
  289. "yacute",
  290. "Thorn",
  291. "thorn",
  292. "minus",
  293. "multiply",
  294. "onesuperior",
  295. "twosuperior",
  296. "threesuperior",
  297. "onehalf",
  298. "onequarter",
  299. "threequarters",
  300. "franc",
  301. "Gbreve",
  302. "gbreve",
  303. "Idotaccent",
  304. "Scedilla",
  305. "scedilla",
  306. "Cacute",
  307. "cacute",
  308. "Ccaron",
  309. "ccaron",
  310. "dcroat",
  311. }