Difference between revisions of "Fontfeaturefiles"

From Wiki
Jump to navigation Jump to search
(some color to the page :))
m
 
(3 intermediate revisions by 2 users not shown)
Line 8: Line 8:
  
 
<texcode>
 
<texcode>
\definefontfeature[thetimes][default][mode=node,featurefile=times_fl.fea]
+
\definefontfeature[thetimes][default][mode=node,featurefile=times_fl.fea]
\starttypescript [serif] [TimesNR] [name]
+
\starttypescript [serif] [TimesNR] [name]
    \setups[font:fallback:serif]
+
    \setups[font:fallback:serif]
    \definefontsynonym [Serif]          [file:Times New Roman.ttf]            [features=thetimes]
+
    \definefontsynonym [Serif]          [file:Times New Roman.ttf]            [features=thetimes]
    \definefontsynonym [SerifBold]      [file:Times New Roman Bold.ttf]      [features=thetimes]
+
    \definefontsynonym [SerifBold]      [file:Times New Roman Bold.ttf]      [features=thetimes]
    \definefontsynonym [SerifItalic]    [file:Times New Roman Italic.ttf]    [features=thetimes]
+
    \definefontsynonym [SerifItalic]    [file:Times New Roman Italic.ttf]    [features=thetimes]
    \definefontsynonym [SerifBoldItalic][file:Times New Roman Bold Italic.ttf][features=thetimes]
+
    \definefontsynonym [SerifBoldItalic][file:Times New Roman Bold Italic.ttf][features=thetimes]
\stoptypescript
+
\stoptypescript
 +
 
 +
\starttypescript[TimesNR]
 +
    \definetypeface [TimesNR] [rm] [serif] [TimesNR]  [default]
 +
\stoptypescript
 +
 
 +
\starttypescript[TheTimes]
 +
    \definetypeface [TheTimes] [rm] [serif] [TimesNR]  [default]
 +
\stoptypescript
 +
 
 +
\mainlanguage[de]
 +
\usetypescript[TheTimes]
 +
\setupbodyfont[TheTimes, 10pt]
 
   
 
   
\starttypescript[TimesNR]
+
\starttext
    \definetypeface [TimesNR] [rm] [serif] [TimesNR]  [default]
 
\stoptypescript
 
 
   
 
   
\starttypescript[TheTimes]
+
Hoffnung finden: fliegen
    \definetypeface [TheTimes] [rm] [serif] [TimesNR]  [default]
 
\stoptypescript
 
 
   
 
   
\mainlanguage[de]
+
\stoptext
\usetypescript[TheTimes]
 
\setupbodyfont[TheTimes, 10pt]
 
 
\starttext
 
 
  Hoffnung finden: fliegen
 
 
\stoptext
 
 
</texcode>
 
</texcode>
  
 
The feature file that is used "times_fl.fea" looks like this:
 
The feature file that is used "times_fl.fea" looks like this:
 
<pre>
 
<pre>
lookup fligatures {
+
lookup fligatures {
  lookupflag 0;
+
  lookupflag 0;
    sub \f \i by \fi;
+
    sub \f \i by \fi;
    sub \f \l by \fl;
+
    sub \f \l by \fl;
} fligatures;
+
} fligatures;
  
feature liga {
+
feature liga {
  script DFLT;
+
  script DFLT;
    language dflt;
+
    language dflt;
      lookup fligatures;
+
      lookup fligatures;
  script latn;
+
  script latn;
    language dflt;
+
      language dflt;
      lookup fligatures;
+
      lookup fligatures;
} liga;
+
} liga;
 
</pre>
 
</pre>
  
Line 57: Line 57:
  
 
<texcode>
 
<texcode>
\definefontfeature[thetimes][default][mode=node,featurefile=times_kern.fea]
+
\definefontfeature[thetimes][default][mode=node,featurefile=times_kern.fea]
\starttypescript [serif] [TimesNR] [name]
+
\starttypescript [serif] [TimesNR] [name]
    \setups[font:fallback:serif]
+
  \setups[font:fallback:serif]
    \definefontsynonym [Serif]          [file:Times New Roman.ttf]            [features=thetimes]
+
    \definefontsynonym [Serif]          [file:Times New Roman.ttf]            [features=thetimes]
    \definefontsynonym [SerifBold]      [file:Times New Roman Bold.ttf]      [features=thetimes]
+
    \definefontsynonym [SerifBold]      [file:Times New Roman Bold.ttf]      [features=thetimes]
    \definefontsynonym [SerifItalic]    [file:Times New Roman Italic.ttf]    [features=thetimes]
+
    \definefontsynonym [SerifItalic]    [file:Times New Roman Italic.ttf]    [features=thetimes]
    \definefontsynonym [SerifBoldItalic][file:Times New Roman Bold Italic.ttf][features=thetimes]
+
    \definefontsynonym [SerifBoldItalic][file:Times New Roman Bold Italic.ttf][features=thetimes]
\stoptypescript
+
\stoptypescript
 
   
 
   
\starttypescript[TimesNR]
+
\starttypescript[TimesNR]
    \definetypeface [TimesNR] [rm] [serif] [TimesNR]  [default]
+
    \definetypeface [TimesNR] [rm] [serif] [TimesNR]  [default]
\stoptypescript
+
\stoptypescript
 
   
 
   
\starttypescript[TheTimes]
+
\starttypescript[TheTimes]
    \definetypeface [TheTimes] [rm] [serif] [TimesNR]  [default]
+
    \definetypeface [TheTimes] [rm] [serif] [TimesNR]  [default]
\stoptypescript
+
\stoptypescript
 
   
 
   
\mainlanguage[de]
+
\mainlanguage[de]
\usetypescript[TheTimes]
+
\usetypescript[TheTimes]
\setupbodyfont[TheTimes, 10pt]
+
\setupbodyfont[TheTimes, 10pt]
 
   
 
   
\starttext
+
\starttext
 
   
 
   
„W
+
„W
 
   
 
   
\stoptext
+
\stoptext
 
</texcode>
 
</texcode>
  
Line 92: Line 92:
 
   
 
   
 
  feature kern {
 
  feature kern {
  script DFLT;
+
  script DFLT;
 
     language dflt ;
 
     language dflt ;
      lookup MyKerns;
+
    lookup MyKerns;
  script latn;
+
  script latn;
 
     language dflt ;
 
     language dflt ;
      lookup MyKerns;
+
    lookup MyKerns;
 
  } kern;
 
  } kern;
  
Line 115: Line 115:
  
 
"when you change the file or the name (or remove it) the font will be recached".
 
"when you change the file or the name (or remove it) the font will be recached".
 +
 +
 +
[[Category:Old_Content]]

Latest revision as of 14:19, 8 June 2020

(This page was written and tested under ConTeXt ver: 2010.08.20 00:00 MKIV)

Recently there was the question how to modify a font at runtime. For OpenType fonts Khaled recalled an article he wrote in fontspec manual (section 11) about font feature files: you just load the feature file with featurefile=foo in your font features definition.

This is an example on how missing ligatures can be used:

\definefontfeature[thetimes][default][mode=node,featurefile=times_fl.fea]
\starttypescript [serif] [TimesNR] [name]
    \setups[font:fallback:serif]
    \definefontsynonym [Serif]          [file:Times New Roman.ttf]            [features=thetimes]
    \definefontsynonym [SerifBold]      [file:Times New Roman Bold.ttf]       [features=thetimes]
    \definefontsynonym [SerifItalic]    [file:Times New Roman Italic.ttf]     [features=thetimes]
    \definefontsynonym [SerifBoldItalic][file:Times New Roman Bold Italic.ttf][features=thetimes]
\stoptypescript

\starttypescript[TimesNR]
    \definetypeface [TimesNR] [rm] [serif] [TimesNR]   [default]
\stoptypescript

\starttypescript[TheTimes]
    \definetypeface [TheTimes] [rm] [serif] [TimesNR]   [default]
\stoptypescript

\mainlanguage[de]
\usetypescript[TheTimes]
\setupbodyfont[TheTimes, 10pt]
 
\starttext
 
Hoffnung finden: fliegen
 
\stoptext

The feature file that is used "times_fl.fea" looks like this:

lookup fligatures {
  lookupflag 0;
    sub \f \i by \fi;
    sub \f \l by \fl;
} fligatures;

feature liga {
  script DFLT;
    language dflt;
      lookup fligatures;
  script latn;
      language dflt;
      lookup fligatures;
} liga;

This is another example showing how improved kerning can be added to the font via feature files:

\definefontfeature[thetimes][default][mode=node,featurefile=times_kern.fea]
\starttypescript [serif] [TimesNR] [name]
  \setups[font:fallback:serif]
    \definefontsynonym [Serif]          [file:Times New Roman.ttf]            [features=thetimes]
    \definefontsynonym [SerifBold]      [file:Times New Roman Bold.ttf]       [features=thetimes]
    \definefontsynonym [SerifItalic]    [file:Times New Roman Italic.ttf]     [features=thetimes]
    \definefontsynonym [SerifBoldItalic][file:Times New Roman Bold Italic.ttf][features=thetimes]
\stoptypescript
 
\starttypescript[TimesNR]
    \definetypeface [TimesNR] [rm] [serif] [TimesNR]   [default]
\stoptypescript
 
\starttypescript[TheTimes]
    \definetypeface [TheTimes] [rm] [serif] [TimesNR]   [default]
\stoptypescript
 
\mainlanguage[de]
\usetypescript[TheTimes]
\setupbodyfont[TheTimes, 10pt]
 
\starttext
 
„W
 
\stoptext

The feature file that is used here "times_kern.fea" looks like this:

lookup MyKerns {
 lookupflag 0;
    pos \quotedblbase \W -150;
} MyKerns;

feature kern {
  script DFLT;
    language dflt ;
    lookup MyKerns;
  script latn;
    language dflt ;
    lookup MyKerns;
} kern;


These font features are loaded in the font cache.

Thus, for experimenting and eg. changing the value "-150" one must clear the cache between two runs: mtxrun --script cache --erase

For example when running context minimal in Mac you just enter in Terminal:

source /Users/YourName/context/tex/setuptex /Users/YourName/context/tex
mtxrun --script cache --erase

Update

Today (1. Sept 2010.) Hans announced that with the next release this clearing isn't needed anymore:

"when you change the file or the name (or remove it) the font will be recached".