@@ -422,7 +422,7 @@ const PRIVATE_DICT_META_CFF2 = [
422
422
423
423
// https://learn.microsoft.com/en-us/typography/opentype/spec/cff2#table-10-font-dict-operator-entries
424
424
const FONT_DICT_META = [
425
- { name : 'private' , op : 18 , type : [ 'number' , 'offset ' ] , value : [ 0 , 0 ] }
425
+ { name : 'private' , op : 18 , type : [ 'number' , 'varoffset ' ] , value : [ 0 , 0 ] }
426
426
] ;
427
427
428
428
// Parse the CFF top dictionary. A CFF table can contain multiple fonts, each with their own top dictionary.
@@ -659,6 +659,8 @@ function parseCFFCharstring(font, glyph, code, version, coords) {
659
659
if ( glyph . blendDeltas && glyph . blendDeltas . length ) {
660
660
glyph . blendDeltas = [ ] ;
661
661
}
662
+ // @TODO : instead of re-parsing the path each time (which will not take into account any possible changes to the path),
663
+ // apply the stored (and possible modified) blend data
662
664
return parseCFFCharstring ( font , glyph , code , version , variationCoords ) ;
663
665
} ;
664
666
}
@@ -1806,6 +1808,7 @@ function glyphToOps(glyph, version, font) {
1806
1808
// candidates for sub routines and extracts them from the glyphs, replacing the actual commands
1807
1809
if ( glyph . subrs && glyph . gsubrs && glyph . subrs . length === glyph . gsubrs . length ) {
1808
1810
const cffTable = font . tables [ version < 2 ? 'cff' : 'cff2' ] ;
1811
+ if ( ! cffTable ) return ;
1809
1812
const fdIndex = cffTable . topDict . _fdSelect ? cffTable . topDict . _fdSelect [ glyph . index ] : 0 ;
1810
1813
const fdDict = cffTable . topDict . _fdArray [ fdIndex ] ;
1811
1814
for ( let i = 0 ; i < glyph . subrs . length ; i ++ ) {
@@ -1935,18 +1938,36 @@ function makeCharStringsIndex(glyphs, version) {
1935
1938
return t ;
1936
1939
}
1937
1940
1938
- function makePrivateDict ( attrs , strings , version ) {
1941
+ function makeFontDictIndex ( fontDicts ) {
1942
+ let dicts = [ ] ;
1943
+ for ( let i = 0 ; i < fontDicts . length ; i ++ ) {
1944
+ dicts . push ( { name : `fontDict_${ i } ` , type : 'TABLE' , value : fontDicts [ i ] } ) ;
1945
+ }
1946
+ const t = new table . Record ( 'Font DICT INDEX' , [
1947
+ { name : 'fontDicts' , type : 'INDEX32' , value : fontDicts }
1948
+ ] ) ;
1949
+ return t ;
1950
+ }
1951
+
1952
+ function makeFontDict ( attrs ) {
1953
+ const t = new table . Record ( 'Font DICT' , [
1954
+ { name : 'dict' , type : 'DICT' , value : { } }
1955
+ ] ) ;
1956
+ t . dict = makeDict ( FONT_DICT_META , attrs ) ;
1957
+ return t ;
1958
+ }
1959
+
1960
+ function makePrivateDict ( attrs , strings ) {
1939
1961
const t = new table . Record ( 'Private DICT' , [
1940
1962
{ name : 'dict' , type : 'DICT' , value : { } }
1941
1963
] ) ;
1942
- t . dict = makeDict ( version > 1 ? PRIVATE_DICT_META_CFF2 : PRIVATE_DICT_META , attrs , strings ) ;
1964
+ t . dict = makeDict ( FONT_DICT_META , attrs , strings ) ;
1943
1965
return t ;
1944
1966
}
1945
1967
1946
1968
function makeCFFTable ( glyphs , options , version ) {
1947
1969
const font = glyphs . font ;
1948
1970
const cffVersion = version || 1 ;
1949
- console . log ( font ) ;
1950
1971
const cffTable = font . tables [ cffVersion > 1 ? 'cff2' : 'cff' ] ;
1951
1972
1952
1973
const tableFields = cffVersion < 2 ? [
@@ -2009,7 +2030,8 @@ function makeCFFTable(glyphs, options, version) {
2009
2030
}
2010
2031
2011
2032
const strings = [ ] ;
2012
- const vstore = cffTable . topDict . _vstore ;
2033
+ const vstore = cffTable && cffTable . topDict . _vstore ;
2034
+ // @TODO : If we have a gvar table, make a vstore for the output font
2013
2035
2014
2036
t . header = makeHeader ( cffVersion ) ;
2015
2037
if ( cffVersion < 2 ) {
@@ -2067,10 +2089,24 @@ function makeCFFTable(glyphs, options, version) {
2067
2089
t . fields . push ( { name : 'charStringsIndex' , type : 'RECORD' } ) ;
2068
2090
}
2069
2091
2092
+ // @TODO : if there's more than one fontDict
2070
2093
// {name: 'FDSelect', type: 'RECORD'}
2071
2094
// t.FDSelect =
2072
- // {name: 'FontDICTIndex', type: 'RECORD'}
2073
- // t.FontDICTIndex =
2095
+
2096
+ t . fields . push ( { name : 'fontDictIndex' , type : 'RECORD' } ) ;
2097
+ let fontDicts = cffTable && cffTable . topDict . _fdArray ;
2098
+ if ( ! fontDicts ) {
2099
+ fontDicts = [ makeFontDict ( [ 0 , 0 ] ) ] ;
2100
+ } else {
2101
+ fontDicts = fontDicts . map ( d => {
2102
+ return makeFontDict ( [ 0 , 0 ] ) ;
2103
+ } ) ;
2104
+ }
2105
+ t . fontDictIndex = makeFontDictIndex ( fontDicts ) ;
2106
+
2107
+ console . log ( '#########################################' )
2108
+ console . log ( t . fontDictIndex )
2109
+
2074
2110
// {name: 'fdArray', type: 'RECORD'}
2075
2111
// t.fdArray =
2076
2112
// {name: 'privateDict', type: 'RECORD'}
0 commit comments