Simplify CFX_StandardFont standard font lookup [pdfium : main]

0 views
Skip to first unread message

Tom Sepez (Gerrit)

unread,
Jun 24, 2026, 3:34:07 PM (11 hours ago) Jun 24
to Lei Zhang, pdfium-...@googlegroups.com
Attention needed from Lei Zhang

Tom Sepez added 4 comments

File core/fpdfapi/font/cpdf_stockfontarray.cpp
Line 33, Patchset 5: return stock_fonts_[static_cast<size_t>(index)];
Tom Sepez . resolved

The commit message calls `CFX_StandardFont::ID` a "scoped enum", but it is actually unscoped (`enum ID : uint8_t`). Because of this, the `static_cast<size_t>` here isn't strictly necessary for array indexing (it would implicitly convert), though it is harmless and required for the `CHECK_LT` above.

File core/fxge/cfx_fontmapper.cpp
Line 543, Patchset 5: CFX_StandardFont::GetStandardFontName(&family);
Tom Sepez . resolved

This completely ignores the returned `std::optional<ID>` and only relies on the side effect of mutating `family` to the canonical name. This isn't a new bug (the old code did this too), but it highlights why the `GetStandardFontName` name is confusing.

File core/fxge/cfx_standardfont.h
Line 43, Patchset 5: static std::optional<ID> GetStandardFontIndex(const ByteString& name);
Tom Sepez . resolved

Since this returns `std::optional<ID>`, `GetStandardFontId` or `FindStandardFontId` might be a more accurate name than `...Index`.

Line 38, Patchset 5: static std::optional<ID> GetStandardFontName(ByteString* name);
Tom Sepez . resolved

Consider renaming this to something like `ResolveStandardFontAlias` or `CanonicalizeStandardFontName`. The current name implies a simple getter, but it actually takes an alias, mutates the string to the canonical name if found, and returns the ID.

Open in Gerrit

Related details

Attention is currently required from:
  • Lei Zhang
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: pdfium
Gerrit-Branch: main
Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
Gerrit-Change-Number: 150690
Gerrit-PatchSet: 14
Gerrit-Owner: Tom Sepez <tse...@chromium.org>
Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
Gerrit-Attention: Lei Zhang <the...@chromium.org>
Gerrit-Comment-Date: Wed, 24 Jun 2026 19:33:50 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Tom Sepez (Gerrit)

unread,
Jun 24, 2026, 5:04:51 PM (9 hours ago) Jun 24
to pdfium...@luci-project-accounts.iam.gserviceaccount.com, Lei Zhang, pdfium-...@googlegroups.com
Attention needed from Lei Zhang

New activity on the change

Open in Gerrit

Related details

Attention is currently required from:
  • Lei Zhang
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: pdfium
Gerrit-Branch: main
Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
Gerrit-Change-Number: 150690
Gerrit-PatchSet: 17
Gerrit-Owner: Tom Sepez <tse...@chromium.org>
Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
Gerrit-Attention: Lei Zhang <the...@chromium.org>
Gerrit-Comment-Date: Wed, 24 Jun 2026 21:04:48 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Lei Zhang (Gerrit)

unread,
Jun 24, 2026, 5:20:35 PM (9 hours ago) Jun 24
to Tom Sepez, pdfium...@luci-project-accounts.iam.gserviceaccount.com, Lei Zhang, pdfium-...@googlegroups.com
Attention needed from Tom Sepez

Lei Zhang added 1 comment

File core/fxge/cfx_standardfont.h
Line 17, Patchset 17 (Latest): enum Index : uint8_t {
Lei Zhang . unresolved

Can a separate CL first do this mass rename?

Open in Gerrit

Related details

Attention is currently required from:
  • Tom Sepez
Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: pdfium
    Gerrit-Branch: main
    Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
    Gerrit-Change-Number: 150690
    Gerrit-PatchSet: 17
    Gerrit-Owner: Tom Sepez <tse...@chromium.org>
    Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
    Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
    Gerrit-Attention: Tom Sepez <tse...@chromium.org>
    Gerrit-Comment-Date: Wed, 24 Jun 2026 21:20:32 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Tom Sepez (Gerrit)

    unread,
    Jun 24, 2026, 6:53:21 PM (8 hours ago) Jun 24
    to pdfium...@luci-project-accounts.iam.gserviceaccount.com, Lei Zhang, pdfium-...@googlegroups.com
    Attention needed from Lei Zhang

    Tom Sepez added 1 comment

    File core/fxge/cfx_standardfont.h
    Line 17, Patchset 17: enum Index : uint8_t {
    Lei Zhang . resolved

    Can a separate CL first do this mass rename?

    Tom Sepez

    mass rename as follow-up

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Lei Zhang
    Submit Requirements:
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: pdfium
      Gerrit-Branch: main
      Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
      Gerrit-Change-Number: 150690
      Gerrit-PatchSet: 19
      Gerrit-Attention: Lei Zhang <the...@chromium.org>
      Gerrit-Comment-Date: Wed, 24 Jun 2026 22:53:16 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Lei Zhang <the...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Lei Zhang (Gerrit)

      unread,
      Jun 24, 2026, 7:18:03 PM (7 hours ago) Jun 24
      to Tom Sepez, pdfium...@luci-project-accounts.iam.gserviceaccount.com, Lei Zhang, pdfium-...@googlegroups.com
      Attention needed from Tom Sepez

      Lei Zhang added 2 comments

      File core/fxge/cfx_fontmapper.h
      Line 53, Patchset 20 (Parent):
      Lei Zhang . unresolved

      Leave this alone.

      File core/fxge/cfx_standardfont.h
      Line 45, Patchset 20: static pdfium::span<const uint8_t> GetGenericSansFontData();
      Lei Zhang . resolved

      Wishing there was less churn here, but ok.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Tom Sepez
      Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: pdfium
        Gerrit-Branch: main
        Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
        Gerrit-Change-Number: 150690
        Gerrit-PatchSet: 21
        Gerrit-Attention: Tom Sepez <tse...@chromium.org>
        Gerrit-Comment-Date: Wed, 24 Jun 2026 23:17:59 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Lei Zhang (Gerrit)

        unread,
        Jun 24, 2026, 7:22:27 PM (7 hours ago) Jun 24
        to Tom Sepez, pdfium...@luci-project-accounts.iam.gserviceaccount.com, Lei Zhang, pdfium-...@googlegroups.com
        Attention needed from Tom Sepez

        Lei Zhang added 2 comments

        Commit Message
        Line 13, Patchset 21 (Latest):* Move kFoxitFonts to cfx_standardfont.cpp.
        Lei Zhang . unresolved

        No longer part of this CL.

        File core/fxge/cfx_standardfont.cpp
        Line 167, Patchset 20: return font == CFX_StandardFont::kSymbol ||
        Lei Zhang . unresolved

        Leave these as they were?

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Tom Sepez
        Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: pdfium
        Gerrit-Branch: main
        Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
        Gerrit-Change-Number: 150690
        Gerrit-PatchSet: 21
        Gerrit-Owner: Tom Sepez <tse...@chromium.org>
        Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
        Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
        Gerrit-Attention: Tom Sepez <tse...@chromium.org>
        Gerrit-Comment-Date: Wed, 24 Jun 2026 23:22:23 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Lei Zhang (Gerrit)

        unread,
        Jun 24, 2026, 7:26:46 PM (7 hours ago) Jun 24
        to Tom Sepez, pdfium...@luci-project-accounts.iam.gserviceaccount.com, Lei Zhang, pdfium-...@googlegroups.com
        Attention needed from Tom Sepez

        Lei Zhang added 2 comments

        File core/fpdfapi/font/cpdf_font.cpp
        Line 255, Patchset 20: return !subst_font->IsActualFontLoaded(base_font_name);
        Lei Zhang . unresolved

        Not GetCanonicalFontName() call before using `base_font_name` here? Or inline GetCanonicalFontName() call here.

        Line 286, Patchset 20: fontname = CFX_StandardFont::GetCanonicalFontName(font_id.value());
        Lei Zhang . unresolved

        Maybe merge into line 297?

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Tom Sepez
        Submit Requirements:
        • requirement satisfiedCode-Owners
        • requirement is not satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: pdfium
        Gerrit-Branch: main
        Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
        Gerrit-Change-Number: 150690
        Gerrit-PatchSet: 21
        Gerrit-Owner: Tom Sepez <tse...@chromium.org>
        Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
        Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
        Gerrit-Attention: Tom Sepez <tse...@chromium.org>
        Gerrit-Comment-Date: Wed, 24 Jun 2026 23:26:42 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Tom Sepez (Gerrit)

        unread,
        Jun 24, 2026, 8:14:43 PM (6 hours ago) Jun 24
        to pdfium...@luci-project-accounts.iam.gserviceaccount.com, Lei Zhang, pdfium-...@googlegroups.com
        Attention needed from Lei Zhang

        Tom Sepez added 6 comments

        Commit Message
        Line 13, Patchset 21:* Move kFoxitFonts to cfx_standardfont.cpp.
        Lei Zhang . resolved

        No longer part of this CL.

        Tom Sepez

        Done

        File core/fpdfapi/font/cpdf_font.cpp
        Line 255, Patchset 20: return !subst_font->IsActualFontLoaded(base_font_name);
        Lei Zhang . resolved

        Not GetCanonicalFontName() call before using `base_font_name` here? Or inline GetCanonicalFontName() call here.

        Tom Sepez

        Here is a place the split makes sense. If it is a standard font, the name is updated, but a value is returned, and we return out of here not using the name again at 247. Otherwise, it was not a standard font, and the name is not altered as a side-effect. In which case we use the non-adjusted name

        Line 286, Patchset 20: fontname = CFX_StandardFont::GetCanonicalFontName(font_id.value());
        Lei Zhang . resolved

        Maybe merge into line 297?

        Tom Sepez

        for the sake of update, and since I seemed to have lost one already, keep here.

        File core/fxge/cfx_fontmapper.h
        Lei Zhang . resolved

        Leave this alone.

        Tom Sepez

        jetski and blank lines.

        File core/fxge/cfx_standardfont.h
        Line 45, Patchset 20: static pdfium::span<const uint8_t> GetGenericSansFontData();
        Lei Zhang . resolved

        Wishing there was less churn here, but ok.

        Tom Sepez

        I put these in order of .cpp after trying to minimize .cpp diff.

        File core/fxge/cfx_standardfont.cpp
        Line 167, Patchset 20: return font == CFX_StandardFont::kSymbol ||
        Lei Zhang . resolved

        Leave these as they were?

        Tom Sepez

        Done

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Lei Zhang
        Submit Requirements:
          • requirement satisfiedCode-Owners
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedReview-Enforcement
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: pdfium
          Gerrit-Branch: main
          Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
          Gerrit-Change-Number: 150690
          Gerrit-PatchSet: 26
          Gerrit-Attention: Lei Zhang <the...@chromium.org>
          Gerrit-Comment-Date: Thu, 25 Jun 2026 00:14:40 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          Comment-In-Reply-To: Lei Zhang <the...@chromium.org>
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Lei Zhang (Gerrit)

          unread,
          Jun 24, 2026, 8:25:45 PM (6 hours ago) Jun 24
          to Tom Sepez, Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com
          Attention needed from Tom Sepez

          Lei Zhang voted and added 2 comments

          Votes added by Lei Zhang

          Code-Review+1

          2 comments

          File core/fpdfapi/font/cpdf_font.cpp
          Line 255, Patchset 20: return !subst_font->IsActualFontLoaded(base_font_name);
          Lei Zhang . resolved

          Not GetCanonicalFontName() call before using `base_font_name` here? Or inline GetCanonicalFontName() call here.

          Tom Sepez

          Here is a place the split makes sense. If it is a standard font, the name is updated, but a value is returned, and we return out of here not using the name again at 247. Otherwise, it was not a standard font, and the name is not altered as a side-effect. In which case we use the non-adjusted name

          Lei Zhang

          Oh, I read line 246 wrong. I was expected the opposite conditional there.

          File core/fpdfapi/font/cpdf_type1font.cpp
          Line 88, Patchset 26 (Latest): if (base14_font_.has_value()) {
          Lei Zhang . unresolved

          It turns out IsBase14Font() internally does this too. So this code expands out to:

          ```
          if (base14_font_.has_value()) {
          ... GetCanonicalFontName(base14_font_.value());
          }
          if (!base14_font_.has_value()) {
          return LoadCommon();
          }
          ```

          Maybe just switch out the IsBase14Font() call and keep the early return?

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Tom Sepez
          Submit Requirements:
          • requirement satisfiedCode-Owners
          • requirement satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement satisfiedReview-Enforcement
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: pdfium
          Gerrit-Branch: main
          Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
          Gerrit-Change-Number: 150690
          Gerrit-PatchSet: 26
          Gerrit-Owner: Tom Sepez <tse...@chromium.org>
          Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
          Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
          Gerrit-Attention: Tom Sepez <tse...@chromium.org>
          Gerrit-Comment-Date: Thu, 25 Jun 2026 00:25:41 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: Yes
          Comment-In-Reply-To: Lei Zhang <the...@chromium.org>
          Comment-In-Reply-To: Tom Sepez <tse...@chromium.org>
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Tom Sepez (Gerrit)

          unread,
          Jun 24, 2026, 8:31:14 PM (6 hours ago) Jun 24
          to Lei Zhang, pdfium...@luci-project-accounts.iam.gserviceaccount.com, pdfium-...@googlegroups.com

          Tom Sepez voted and added 1 comment

          Votes added by Tom Sepez

          Commit-Queue+2

          1 comment

          File core/fpdfapi/font/cpdf_type1font.cpp
          Line 88, Patchset 26: if (base14_font_.has_value()) {
          Lei Zhang . resolved

          It turns out IsBase14Font() internally does this too. So this code expands out to:

          ```
          if (base14_font_.has_value()) {
          ... GetCanonicalFontName(base14_font_.value());
          }
          if (!base14_font_.has_value()) {
          return LoadCommon();
          }
          ```

          Maybe just switch out the IsBase14Font() call and keep the early return?

          Tom Sepez

          Done

          Open in Gerrit

          Related details

          Attention set is empty
          Submit Requirements:
            • requirement satisfiedCode-Owners
            • requirement satisfiedCode-Review
            • requirement satisfiedReview-Enforcement
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: pdfium
            Gerrit-Branch: main
            Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
            Gerrit-Change-Number: 150690
            Gerrit-PatchSet: 27
            Gerrit-Comment-Date: Thu, 25 Jun 2026 00:31:07 +0000
            satisfied_requirement
            open
            diffy

            pdfium-scoped@luci-project-accounts.iam.gserviceaccount.com (Gerrit)

            unread,
            Jun 24, 2026, 9:04:07 PM (5 hours ago) Jun 24
            to Tom Sepez, Lei Zhang, pdfium-...@googlegroups.com

            pdfium...@luci-project-accounts.iam.gserviceaccount.com submitted the change with unreviewed changes

            Unreviewed changes

            26 is the latest approved patch-set.
            The change was submitted with unreviewed changes in the following files:

            ```
            The name of the file: core/fpdfapi/font/cpdf_type1font.cpp
            Insertions: 3, Deletions: 5.

            @@ -85,13 +85,11 @@

            bool CPDF_Type1Font::Load() {
            base14_font_ = CFX_StandardFont::GetStandardFontIndex(base_font_name_);
            - if (base14_font_.has_value()) {
            - base_font_name_ =
            - CFX_StandardFont::GetCanonicalFontName(base14_font_.value());
            - }
            - if (!IsBase14Font()) {
            + if (!base14_font_.has_value()) {
            return LoadCommon();
            }
            + base_font_name_ =
            + CFX_StandardFont::GetCanonicalFontName(base14_font_.value());

            RetainPtr<const CPDF_Dictionary> font_desc =
            font_dict_->GetDictFor("FontDescriptor");
            ```

            Change information

            Commit message:
            Simplify CFX_StandardFont standard font lookup

            * Replace GetStandardFontName(ByteString*), which mutated its input
            argument, with a non-mutating GetStandardFontIndex() method.
            * Callers that need the canonical standard font name must now explicitly
            call GetCanonicalFontName() rather than relying on a side-effect.
            * Update affected call sites across fpdfapi/ and fxge/.

            TAG=agy
            CONV=63532648-374f-4a87-acdf-e5aebbaa70a3
            Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
            Commit-Queue: Tom Sepez <tse...@chromium.org>
            Reviewed-by: Lei Zhang <the...@chromium.org>
            Files:
            • M core/fpdfapi/font/cpdf_font.cpp
            • M core/fpdfapi/font/cpdf_stockfontarray.cpp
            • M core/fpdfapi/font/cpdf_type1font.cpp
            • M core/fpdfapi/page/cpdf_docpagedata.cpp
            • M core/fxge/cfx_fontmapper.cpp
            • M core/fxge/cfx_standardfont.cpp
            • M core/fxge/cfx_standardfont.h
            • M core/fxge/cfx_standardfont_unittest.cpp
            Change size: M
            Delta: 8 files changed, 80 insertions(+), 91 deletions(-)
            Branch: refs/heads/main
            Submit Requirements:
            • requirement satisfiedCode-Review: +1 by Lei Zhang
            Open in Gerrit
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: merged
            Gerrit-Project: pdfium
            Gerrit-Branch: main
            Gerrit-Change-Id: I1b16bc598c4e9714eb2e6c6e4a20c18496be383b
            Gerrit-Change-Number: 150690
            Gerrit-PatchSet: 28
            Gerrit-Owner: Tom Sepez <tse...@chromium.org>
            Gerrit-Reviewer: Lei Zhang <the...@chromium.org>
            Gerrit-Reviewer: Tom Sepez <tse...@chromium.org>
            open
            diffy
            satisfied_requirement
            Reply all
            Reply to author
            Forward
            0 new messages