Technical Article

PDF/UA Font Checks in Delphi: CID 0, Glyph Names and the (3,1) cmap

veraPDF fails a tagged quarterly report on ISO 14289-1 §7.21.8 because a single Tj operator shows the bytes <0000>, which under Identity-H means CID 0, the .notdef glyph. That clause and its neighbor §7.21.6, which limits the glyph names a TrueType /Differences array may use, surface in Delphi as separate flags in the result of PDFium Component's TPdf.ValidatePdfUa

Which text operators reference the .notdef glyph?

Every text-showing operator whose operand maps to glyph 0 does. In a simple font, .notdef is a glyph name. In a CID-keyed font the same role belongs to CID 0, and ISO 32000-2 §9.7.4.2 requires every CIDFont to contain a glyph description for CID 0 "analogous to the .notdef character name in simple fonts". With the usual Identity-H encoding, character code and CID are the same two bytes, so a content stream that shows <0000> with Tj, or inside a TJ array, is drawing CID 0. ISO 14289-1 §7.21.8 forbids any text-showing operator from doing that, and PDF/UA-2 states the same requirement in §8.4.5.9. The text rendering mode is irrelevant. Invisible text in mode 3, such as the OCR layer over a scanned page, counts too. On screen the result is usually an empty box a few points wide, or no mark at all, and neither tells a sighted proofreader that a character went missing

The usual source is a generator that met a character missing from its subset font and wrote code 0 where it should have switched to a fallback face. That makes the byte-level check pleasantly precise. Decode only the streams referenced by each page's /Contents, look for <0000> fed to Tj or TJ in a document that uses Type 0 fonts, and leave images, ICC profiles and CMaps compressed. One parsing detail decides whether you find the pages at all. ISO 32000-1 §7.3.5 ends a name token at the next delimiter, so /Type/Page with no space is a valid page dictionary, and a search for the spaced form /Type /Page skips it. Naming /.notdef inside a Differences array does not trip this rule by itself; only showing a code that lands on that slot does

Flow showing a 0000 operand under Identity-H reaching CID 0 and the .notdef glyph, with the ISO 14289 clause PDFium Component reports in Delphi
any text-showing operator that feeds code 0 to an Identity-H font draws CID 0, so the byte test reports it even when the text is invisible

Which /Differences glyph names count as Unicode compliant?

Names that appear in the Adobe Glyph List do, provided the embedded font program also contains a (3,1) cmap subtable. The background is ISO 32000-2 §9.6.5.4, which recommends that a non-symbolic TrueType font use MacRomanEncoding or WinAnsiEncoding with no Differences array; PDF/UA turns that advice into a requirement with one escape hatch. Both PDF/UA parts state the test in the same form veraPDF applies: the font is symbolic, or its encoding is MacRoman or WinAnsi and either has no /Differences array or every name in that array is Unicode compliant. The (3,1) condition follows from the glyph selection order that §9.6.5.4 prescribes when that subtable (Microsoft platform, Unicode BMP) is present. Character code goes to glyph name through the encoding, glyph name to Unicode through the Adobe Glyph List, and Unicode to glyph through the (3,1) subtable. A name outside the list breaks the middle step, and a font without the subtable never takes that path. The symbolic-font rule points the other way: a symbolic TrueType font must not carry an /Encoding entry at all

Glyph selection chain from character code through the Adobe Glyph List to a (3,1) cmap subtable, the TrueType test PDFium Component applies in Delphi
a Differences name only reaches a glyph when the encoding, the Adobe Glyph List and the (3,1) cmap subtable chain holds, which is where the PDF/UA name test in PDFium Component for Delphi fails
Font dictionaryResult
Non-symbolic, /Encoding /WinAnsiEncoding, no DifferencesPasses
Non-symbolic, WinAnsi base, Differences with /Euro /bullet /.notdef, font has a (3,1) cmapPasses
Non-symbolic, Differences containing /g123 or /glyph57Fails: names not in the glyph list
Non-symbolic, valid Differences, embedded font has only a (1,0) Mac cmapFails: no (3,1) subtable
Non-symbolic, WinAnsi base with Differences, no FontFile2 embeddedNot decided by this rule; the embedding rule (§7.21.4) fails it
Non-symbolic, no /Encoding entryFails
Symbolic, any /Encoding entryFails the symbolic rule

The second row is where self-built glyph lists go wrong. The list veraPDF ships with its font code, font/AdobeGlyphList.txt, has 4,282 entries, and its first line is .notdef 0000. Tables assembled by hand or taken from other sources often lack that entry, because .notdef stands for no real character. A checker built on such a table reports every font whose Differences array mentions /.notdef, a name that turns up regularly in subset fonts that fill unused slots with it. The match is by whole name. A substring search would accept /grav just because /grave is in the list. Fill unused Differences slots with .notdef freely; a checker that follows veraPDF accepts it

Font rules are judged on the bytes the producer wrote

A natural shortcut is to save a normalized copy of the document and scan that, since a rewritten file is easier to parse. For font rules, that fails. Any tool that re-serializes a PDF is free to rebuild font dictionaries: fold a Differences array into a fresh encoding, rename glyphs, renumber objects. An encoding rule therefore has to be checked against the bytes the producer wrote. TPdf.ValidatePdfUa runs its font tests on the file or memory buffer it loaded and decodes FontFile2 streams directly to reach the TrueType table directory. The character-level test (does a drawn character map to Unicode 0?) uses the text the page renders and skips content marked as an Artifact or covered by /ActualText; the CID 0 byte test makes no such exception. The findings arrive as separate values in the issue set, so a report can say which rule fired:

uses
  SysUtils, PDFium, FPdfPdfua;

procedure ReportFontFindings(const FileName: string);
const
  FontIssues: TPdfUaValidationIssues = [pvuaiPdfiumNotDefGlyph,
    pvuaiTrueTypeEncodingInvalid, pvuaiSymbolicTrueTypeEncoding,
    pvuaiFontNotEmbedded, pvuaiFontMissingToUnicode];
var
  Pdf: TPdf;
  Report: TPdfUaValidationResult;
  Found: TPdfUaValidationIssues;
  Coverage: TPdfUaUnicodeCoverageReport;
  I: Integer;
begin
  Pdf := TPdf.Create(nil);
  try
    Pdf.FileName := FileName;
    Pdf.Active := True;
    if not Pdf.Active then
      raise Exception.CreateFmt('Cannot open %s', [FileName]);
    Report := Pdf.ValidatePdfUa;
    Found := Report.Issues * FontIssues;
    if pvuaiPdfiumNotDefGlyph in Found then
    begin
      Writeln('Text references .notdef / CID 0 (7.21.8, 8.4.5.9)');
      // Locate rendered characters that map to no Unicode value
      Coverage := Pdf.InspectPdfUaUnicodeCoverage;
      for I := 0 to High(Coverage.Objects) do
        if Coverage.Objects[I].MissingUnicodeCharacterCount > 0 then
          Writeln(Format('  page %d, object %d: %d character(s)',
            [Coverage.Objects[I].PageNumber,
             Coverage.Objects[I].PageObjectIndex,
             Coverage.Objects[I].MissingUnicodeCharacterCount]));
    end;
    if pvuaiTrueTypeEncodingInvalid in Found then
      Writeln('Non-symbolic TrueType encoding or Differences (7.21.6, 8.4.5.7)');
    if pvuaiSymbolicTrueTypeEncoding in Found then
      Writeln('Symbolic TrueType font carries an /Encoding entry');
    if pvuaiFontNotEmbedded in Found then
      Writeln('A font program is not embedded (7.21.4)');
    if pvuaiFontMissingToUnicode in Found then
      Writeln('A font has no usable Unicode mapping (7.21.7)');
    if Found = [] then
      Writeln('No font findings');
    // Expected for a file whose only fault is /g123 in a Differences array:
    // the single 7.21.6 line
  finally
    Pdf.Free;
  end;
end;

Repairs belong in the program that wrote the file

Neither finding can be repaired safely afterwards by editing a dictionary. A CID 0 reference means a character had no glyph in the font that was used, so the generator needs a fallback font for that character. Rewriting <0000> to some other code would draw an arbitrary glyph and attach the wrong Unicode value to it. A Differences array with names such as /g123 usually comes from subsetting a font whose glyphs carry no standard names. The clean repair is to embed that face as a CID-keyed TrueType font, the setup used for CID Type 2 font embedding, with Identity-H and a /ToUnicode CMap. That takes the simple-font encoding rule out of play

Setting the Symbolic flag to make §7.21.6 go away is the wrong move. A symbolic TrueType font may not carry /Encoding at all. The Differences names that told a screen reader which character each code stands for disappear along with it, and every viewer then picks glyphs by raw code through the (3,0) or (1,0) subtable. The flag clears. The meaning of the text goes with it

Does the embedded font program have a (3,1) cmap?

Ask the font program directly, because the encoding flag covers both halves of the test and cannot say which one failed. When it fires and every Differences name is in the list, the program is the next suspect. A TrueType file starts with a 12-byte header whose bytes 4–5 hold the number of tables, followed by 16-byte table records (tag, checksum, offset, length). The cmap table begins with a version and a subtable count, followed by 8-byte records of platform ID, encoding ID and offset, all big-endian. No font library needed. TPdf.GetFontData returns the embedded program of the font used by a page object, so the helper can run over every text object on a page:

Byte walk through an embedded TrueType program: header, table records and cmap records that decide the (3,1) subtable, read by PDFium Component in Delphi
the (3,1) answer comes from the font program itself: table records locate the cmap, and its 8-byte platform and encoding records decide whether the Unicode path exists
function BE16(const B: TBytes; P: Integer): Integer;
begin
  Result := (B[P] shl 8) or B[P + 1];
end;

function BE32(const B: TBytes; P: Integer): Cardinal;
begin
  Result := (Cardinal(B[P]) shl 24) or (Cardinal(B[P + 1]) shl 16) or
    (Cardinal(B[P + 2]) shl 8) or B[P + 3];
end;

// True when a TrueType program has a cmap subtable for (Platform, Encoding)
function HasCmapSubtable(const Font: TBytes; Platform, Encoding: Integer): Boolean;
var
  Tables, I, Rec, CmapOfs, Count: Integer;
begin
  Result := False;
  if Length(Font) < 12 then
    Exit;
  Tables := BE16(Font, 4);
  CmapOfs := -1;
  for I := 0 to Tables - 1 do
  begin
    Rec := 12 + I * 16;
    if Rec + 16 > Length(Font) then
      Exit;
    if (Font[Rec] = Ord('c')) and (Font[Rec + 1] = Ord('m')) and
       (Font[Rec + 2] = Ord('a')) and (Font[Rec + 3] = Ord('p')) then
      CmapOfs := Integer(BE32(Font, Rec + 8));
  end;
  if (CmapOfs < 0) or (CmapOfs + 4 > Length(Font)) then
    Exit;
  Count := BE16(Font, CmapOfs + 2);
  for I := 0 to Count - 1 do
  begin
    Rec := CmapOfs + 4 + I * 8;
    if Rec + 8 > Length(Font) then
      Exit;
    if (BE16(Font, Rec) = Platform) and (BE16(Font, Rec + 2) = Encoding) then
      Exit(True);
  end;
end;

// A face with only a Mac Roman (1,0) cmap prints cmap(3,1)=False
procedure ListTextFonts(Pdf: TPdf; PageNo: Integer);
var
  I: Integer;
begin
  Pdf.PageNumber := PageNo;
  for I := 0 to Pdf.ObjectCount - 1 do
    if Pdf.ObjectType[I] = otText then
      Writeln(Format('%-32s embedded=%-5s cmap(3,1)=%s', [
        string(Pdf.GetFontBaseName(I)),
        BoolToStr(Pdf.GetFontIsEmbedded(I), True),
        BoolToStr(HasCmapSubtable(Pdf.GetFontData(I), 3, 1), True)]));
end;

Text objects that share a font print the same line repeatedly. That is harmless here. A bare CFF program (FontFile3 with /Type1C or /CIDFontType0C) has no table directory, so the helper answers False for it, and since the rule concerns TrueType fonts that answer never decides anything here. OpenType fonts with CFF outlines differ: they carry an sfnt directory under the OTTO tag and may include a cmap, which the same loop finds. While the program is in memory, its hmtx advance widths are worth comparing with the font dictionary's /Widths as well, because PDF/UA has a separate width-consistency rule, and auditing glyph widths, CharSet and CIDSet applies it from the PDFlibPas side

If HasCmapSubtable returns False for the face behind a §7.21.6 flag, no edit to its Differences array will clear the finding, and the generator needs to embed that face as a Type 0 font with a ToUnicode CMap. Run the PDFium Component for Delphi validation again on the regenerated file and expect pvuaiTrueTypeEncodingInvalid to be absent from Report.Issues