Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>A very short and simplified introduction</h3> <p>Fonts in PDF are <em>PDF objects</em> - <code>Font</code> dictionaries, containing numerous parameters and sub-dictionaries, necessary to select glyphs, show them and translate character codes to logical (Unicode) representation for content extraction. Fonts in layman terms -- as we see them as *.ttf or *.pfb files -- are called <em>font programs</em>, either embedded or external, and are referred to by one of sub-dictionaries of <code>Font</code> objects.</p> <p><code>Fonts</code> are divided into two groups:</p> <ul> <li>Simple fonts (Type1, Type3 or TrueType), in which glyphs are selected by single-byte character codes obtained from a string that is shown by the text-showing operators. The mapping from codes to glyphs is called the font’s <em>encoding</em>, it can be either built-in into font program or defined by <code>Font</code> object (by predefined name or explicitly) or, under special circumstances, constructed according to defined rules by viewer application. </li> </ul> <p>The file in question doesn't contain simple fonts, and we won't discuss them any further -- but, note, over-simplistic description doesn't even start to reflect any of real-life complexity.</p> <ul> <li>Composite fonts (Type0), used to show text in which character codes can have variable length (up to 4 bytes), and which, therefore, isn't restricted to 256 code-points. <em>Type0</em> font always has one <em>descendant</em> which is a <em>font-like object</em> called <code>CIDFont</code>, and, similar to encoding for simple fonts, a <code>CMap</code> object, that maps character codes to character selectors, which, in PDF, are always <code>CIDs</code> -- integers up to 65536.</li> </ul> <p>Now, character selector (<code>CID</code>) is not, in general, directly used to select glyphs from font program. For <code>CIDFont</code> of <code>CIDFontType2</code> type, its dictionary contains <code>CIDToGIDMap</code> entry, that, obviously, maps <code>CID</code> to glyph identifiers. Those <code>GIDs</code> are, at last, used to select glyphs from embedded <em>font program</em> (which, for <code>CIDFontType2</code> font, is a <em>TrueType</em> font program (do not confuse with <code>Font</code> object of <em>TrueType</em> <code>Subtype</code>)).</p> <p><code>Font</code> object can have <code>ToUnicode</code> resource, that maps CIDs to Unicode values for indexing, searching and extraction. It's called <code>ToUnicode Cmap</code> (as it follows similar syntax), but it should not to be confused with <code>CMap</code> object, mentioned above.</p> <p>In what I call a simple case (and, I think, sensible decision), <code>CMap</code> is predefined <strong>Identity-H</strong> name, <code>CIDToGIDMap</code> is a predefined <strong>Identity</strong> name, and, therefore, character codes extracted from a string (argument to text showing operator) are always 2-byte numbers that, effectively, directly select glyphs from embedded <em>TrueType</em> program. From my experience, it's most common scenario, and as it appears, that's the case, against which common software is tested.</p> <p>But, it's not the case with file in question.</p> <h3>(The end of a short and simplified introduction)</h3> <p>In our file, text showing operator, effectively, gets this string:</p> <pre><code>0x000a 0x000a 0x000a 0x20 0x0020 0x0020 0x0020 0x20 0x0025 0x0025 0x0025 </code></pre> <p>Of course there are no 'groups', they are here because I made them, based on <code>CMap</code> that contains 2 ranges:</p> <pre><code>&lt;20&gt; &lt;20&gt; &lt;0000&gt; &lt;19FF&gt; </code></pre> <p>To make a long story short, if we look up character codes in <code>CMap</code> and get CIDs, then look up CIDs in <code>CIDToGIDMap</code> and get GIDs, then look up GIDs in embedded <strong>David-Bold</strong> font and get Unicode values, here's the table</p> <pre><code>Code CID GID Unicode Name 0x000a 10 180 05EA tav 0x0020 32 159 05D5 vav 0x0025 37 154 05D0 alef 0x20 228 03 0020 space </code></pre> <p>Now we have enough information to speculate, what confuses viewer applications</p> <hr> <p>In my first attempt, I suggested it's <code>32</code> code (and <code>CID</code>) that's used for non-space character (see comment above). This assumption was based on a case, several years ago, when (older version of) Acrobat didn't show character with <code>0x20</code> code, when it's at the end of a string -- assuming it to be <code>space</code>, when in fact, according to encoding vector (of a simple font), it was another character.</p> <p>I changed this:</p> <ul> <li><code>0x0020</code> to <code>0x0004</code> in content stream; </li> <li>bytes 08 and 09 in <code>CIDToGIDMap</code> to GID=159; </li> <li>value in <code>Widths</code> array of CID=4 to 'vav' width; </li> <li><code>ToUnicode cmap</code> was adjusted accordingly. </li> <li>(+ later I tried to remove <code>&lt;0020&gt; 32</code> string from <code>CMAP</code> - not reflected in a file, linked in comment)</li> </ul> <p>Well, it did help, but unfortunately, some of viewers still rejected to comply to specification.</p> <hr> <p>Then I thought, that maybe variable character code width was the issue.</p> <p>I returned to the original file and changed this:</p> <ul> <li><code>0x20</code> to <code>0x00e4</code> in content stream;</li> <li><code>&lt;20&gt; 228</code> to <code>&lt;00e4&gt; 228</code> in <code>CMAP</code>;</li> <li><code>codespacerange</code> <code>&lt;20&gt; &lt;20&gt;</code> in <code>CMAP</code> deleted;</li> <li><code>codespacerange</code> <code>&lt;20&gt; &lt;20&gt;</code> in <code>ToUnicode Cmap</code> deleted.</li> </ul> <p><a href="https://www.dropbox.com/s/5myq23zd2w4w1k5/problematic_fixed.pdf" rel="noreferrer">This</a> file appears to open perfectly in all viewers, mentioned in original question and comments below. Miraculously, <code>0x0020</code> code and <code>32</code> <code>CID</code> do not interfere.</p> <hr> <p>The conclusion, I think, can be this: </p> <p>Given current state of affairs, PDF-creators are <strong>NOT</strong> advised to mix single and double byte codes in font encoding (<code>CMAP</code>).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload