title: Show Unicode characters in PostScript
body: <p>How do I get my PostScript program to show G clef character from <a href="https://github.com/steinbergmedia/bravura" rel="nofollow noreferrer">Bravura</a> font? According to this <a href="http://www.smufl.org/files/smufl-0.9.pdf" rel="nofollow noreferrer">SMuFL</a> document the Unicode code point for a G (treble) clef in Bravura is U+E050 (see page 48 Clefs (U+E050–U+E07F)). The PostScript glyph name might be gClef (not sure).</p>
  
  <p>Here is my best attempt so far to get the unicode characters on page. I am using GhostScript 9.25 to produce a PDF. This is the output from GhostScript:</p>
  
  <pre><code>GPL Ghostscript 9.25 (2018-09-13)
  Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.
  This software comes with NO WARRANTY: see the file PUBLIC for details.
  Scanning C:/Windows/Fonts for fonts... 550 files, 358 scanned, 337 new fonts.
  Can't find (or can't open) font file %rom%Resource/Font/Calibri.
  Can't find (or can't open) font file Calibri.
  Loading Calibri font from C:/Windows/Fonts/calibri.ttf... 8525920 7081126 4118548 2767358 1 done.
  Can't find (or can't open) font file %rom%Resource/Font/BravuraText.
  Can't find (or can't open) font file BravuraText.
  Loading BravuraText font from C:/Windows/Fonts/BravuraText.otf... 9545496 7985907 8185868 6762307 1 done.
  GPL Ghostscript 9.25: Can't embed the complete font BravuraText as it is too large, embedding a subset.
  Main
  </code></pre>
  
  <p>And this is the minimal PostScript program:</p>
  
  <pre><code>%!PS-Adobe-3.0
  %%Title: unicode.ps
  %%LanguageLevel: 3
  %%EndComments
  
  
  %%BeginProlog
  
  userdict begin
  
  %%EndProlog
  
  
  %%BeginSetup
  
  /mm { 25.4 div 72 mul } bind def
  /A4Landscape [297 mm 210 mm] def
  /PageSize //A4Landscape def
  &lt;&lt; /PageSize PageSize &gt;&gt; setpagedevice
  
  
  % ‘‘ReEncodeSmall’’ generates a new re-encoded font. It
  % takes 3 arguments: the name of the font to be
  % re-encoded, a new name, and an array of new character
  % encoding and character name pairs (see the definition of
  % the ‘‘scandvec’’ array below for the format of this
  % array). This method has the advantage that it allows the
  % user to make changes to an existing encoding vector
  % without having to specify an entire new encoding
  % vector. It also saves space when the character encoding
  % and name pairs array is smaller than an entire encoding
  % vector.
  
  % Usage: /Times-Roman /Times-Roman-Scand scandvec new-font-encoding
  
  /new-font-encoding { &lt;&lt;&gt;&gt; begin
      /newcodesandnames exch def
      /newfontname exch def
      /basefontname exch def
  
      /basefontdict basefontname findfont def     % Get the font dictionary on which to base the re-encoded version.
      /newfont basefontdict maxlength dict def    % Create a dictionary to hold the description for the re-encoded font.
  
      basefontdict 
          { exch dup /FID ne      % Copy all the entries in the base font dictionary to the new dictionary except for the FID field.
              { dup /Encoding eq
                  { exch dup length array copy    % Make a copy of the Encoding field.
                      newfont 3 1 roll put }
                  { exch newfont 3 1 roll put }
                  ifelse
              }
              { pop pop }         % Ignore the FID pair.
              ifelse
          } forall
  
      newfont /FontName newfontname put   % Install the new name.
      newcodesandnames aload pop      % Modify the encoding vector. First load the new encoding and name pairs onto the operand stack.
      newcodesandnames length 2 idiv
          { newfont /Encoding get 3 1 roll put}
          repeat  % For each pair on the stack, put the new name into the designated position in the encoding vector. 
      newfontname newfont definefont pop      % Now make the re-encoded font description into a POSTSCRIPT font. Ignore the modified dictionary returned on the operand stack by the definefont operator.
  end} def
  
  
  /Calibri /TextFont [
      16#41   /Scaron     % A (/Scaron Š U+0160)
      16#42   /quarternote                % B U+2669
      16#43   /musicalnote                % C
      16#44   /eighthnotebeamed           % D
      16#45   /musicalnotedbl             % E
      16#46   /beamedsixteenthnotes       % F
      16#47   /musicflatsign              % G
      16#47   /musicsharpsign             % H U+266F
  ] new-font-encoding
  
  % https://github.com/steinbergmedia/bravura
  % The Unicode code point for a G (treble) clef in Bravura Text is U+E050
  % http://www.smufl.org/files/smufl-0.9.pdf
  % p48 Clefs (U+E050–U+E07F)
  % U+E050 (and U+1D11E) gClef G clef 
  % http://www.jdawiseman.com/papers/trivia/character-entities.html
  /Bravura /MusicFont [
      16#41   /gClef                      % A
      16#42   /quarternote                % B U+2669
      16#43   /musicalnote                % C
      16#44   /eighthnotebeamed           % D
      16#45   /musicalnotedbl             % E
      16#46   /beamedsixteenthnotes       % F
      16#47   /musicflatsign              % G
      16#47   /musicsharpsign             % H U+266F
  ] new-font-encoding
  
  /MusicFont findfont 48 scalefont setfont
  
  %%EndSetup
  
  
  %%BeginScript
  
  %% Main
  (Main\n) print
  &lt;&lt;&gt;&gt;begin
      /TextFont findfont 48 scalefont setfont
      0 setgray
      72 72 moveto
      (@ABCDEFGHIJKL) show
  
      0 72 translate
  
      /MusicFont findfont 48 scalefont setfont
      0 setgray
      72 72 moveto
      (@ABCDEFGHIJKL) show
  end
  showpage
  
  %%EndScript
  
  %%Trailer
  %%EOF
  </code></pre>