...

Source file src/golang.org/x/image/font/sfnt/gen.go

Documentation: golang.org/x/image/font/sfnt

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

View as plain text