freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master f107b3f 35/41: [ftinspect] Format `src/ftinspec


From: Werner Lemberg
Subject: [freetype2-demos] master f107b3f 35/41: [ftinspect] Format `src/ftinspect/engine/*`.
Date: Mon, 3 Oct 2022 11:27:04 -0400 (EDT)

branch: master
commit f107b3ff37af8ce66758c78033dcf73741817492
Author: Werner Lemberg <wl@gnu.org>
Commit: Werner Lemberg <wl@gnu.org>

    [ftinspect] Format `src/ftinspect/engine/*`.
---
 src/ftinspect/engine/charmap.cpp              |  27 ++--
 src/ftinspect/engine/charmap.hpp              |  21 +--
 src/ftinspect/engine/engine.cpp               | 138 ++++++++++--------
 src/ftinspect/engine/engine.hpp               | 114 ++++++++-------
 src/ftinspect/engine/fontfilemanager.cpp      |  28 ++--
 src/ftinspect/engine/fontfilemanager.hpp      |  16 +-
 src/ftinspect/engine/fontinfo.cpp             | 151 ++++++++++---------
 src/ftinspect/engine/fontinfo.hpp             | 182 ++++++++++++-----------
 src/ftinspect/engine/fontinfonamesmapping.cpp |  10 +-
 src/ftinspect/engine/mmgx.cpp                 |   5 +-
 src/ftinspect/engine/mmgx.hpp                 |  20 ++-
 src/ftinspect/engine/paletteinfo.cpp          |   6 +-
 src/ftinspect/engine/paletteinfo.hpp          |   7 +-
 src/ftinspect/engine/rendering.cpp            |  82 ++++++-----
 src/ftinspect/engine/rendering.hpp            |  34 +++--
 src/ftinspect/engine/stringrenderer.cpp       | 139 +++++++++---------
 src/ftinspect/engine/stringrenderer.hpp       | 201 +++++++++++++-------------
 17 files changed, 631 insertions(+), 550 deletions(-)

diff --git a/src/ftinspect/engine/charmap.cpp b/src/ftinspect/engine/charmap.cpp
index 680b6cd..0676fb7 100644
--- a/src/ftinspect/engine/charmap.cpp
+++ b/src/ftinspect/engine/charmap.cpp
@@ -5,16 +5,21 @@
 #include "charmap.hpp"
 
 #include <QHash>
+
 #include <freetype/freetype.h>
 #include <freetype/tttables.h>
 
+
 namespace
 {
 QHash<FT_Encoding, QString>& encodingNames();
 }
 
-CharMapInfo::CharMapInfo(int index, FT_CharMap cmap)
-: index(index), ptr(cmap),
+
+CharMapInfo::CharMapInfo(int index,
+                         FT_CharMap cmap)
+: index(index),
+  ptr(cmap),
   encoding(cmap->encoding),
   platformID(cmap->platform_id),
   encodingID(cmap->encoding_id),
@@ -35,7 +40,8 @@ CharMapInfo::CharMapInfo(int index, FT_CharMap cmap)
 
 
 QString
-CharMapInfo::stringifyIndex(int code, int idx)
+CharMapInfo::stringifyIndex(int code,
+                            int idx)
 {
   return QString("CharCode: %1 (glyph idx %2)")
            .arg(stringifyIndexShort(code))
@@ -69,15 +75,16 @@ CharMapInfo::computeMaxIndex()
     result = 0x100;
     break;
 
-  /* some fonts use range 0x00-0x100, others have 0xF000-0xF0FF */
   case FT_ENCODING_MS_SYMBOL:
+    // Some fonts use range 0x00-0x100, others have 0xF000-0xF0FF.
     result = maxIndexForFaceAndCharMap(ptr, 0x10000) + 1;
     break;
 
   default:
-    // Some encodings can reach > 0x10000, e.g. GB 18030.
+    // Some encodings can reach > 0x10000, for example GB 18030.
     result = maxIndexForFaceAndCharMap(ptr, 0x110000) + 1;
   }
+
   return result;
 }
 
@@ -86,9 +93,10 @@ int
 CharMapInfo::maxIndexForFaceAndCharMap(FT_CharMap charMap,
                                        unsigned maxIn)
 {
-  // code adopted from `ftcommon.c`
+  // Code adopted from `ftcommon.c`.
   // This never overflows since no format here exceeds INT_MAX...
-  FT_ULong min = 0, max = maxIn;
+  FT_ULong min = 0;
+  FT_ULong max = maxIn;
   FT_UInt glyphIndex;
   FT_Face face = charMap->face;
 
@@ -106,7 +114,7 @@ CharMapInfo::maxIndexForFaceAndCharMap(FT_CharMap charMap,
     {
       max = mid;
 
-      // once moved, it helps to advance min through sparse regions
+      // Once moved, it helps to advance `min` through sparse regions.
       if (min)
       {
         res = FT_Get_Next_Char(face, min, &glyphIndex);
@@ -114,7 +122,7 @@ CharMapInfo::maxIndexForFaceAndCharMap(FT_CharMap charMap,
         if (glyphIndex)
           min = res;
         else
-          max = min; // found it
+          max = min; // Found it.
       }
     }
   } while (max > min);
@@ -127,6 +135,7 @@ namespace
 {
 // Mapping for `FT_Encoding` is placed here since it's only for the charmap.
 QHash<FT_Encoding, QString> encodingNamesCache;
+
 QHash<FT_Encoding, QString>&
 encodingNames()
 {
diff --git a/src/ftinspect/engine/charmap.hpp b/src/ftinspect/engine/charmap.hpp
index 8b73470..2379b5c 100644
--- a/src/ftinspect/engine/charmap.hpp
+++ b/src/ftinspect/engine/charmap.hpp
@@ -9,6 +9,7 @@
 #include <ft2build.h>
 #include <freetype/freetype.h>
 
+
 class Engine;
 
 #define FT_ENCODING_OTHER 0xFFFE
@@ -26,16 +27,18 @@ struct CharMapInfo
   // Actually this shouldn't go here, but for convenience...
   int maxIndex;
 
-  CharMapInfo(int index, FT_CharMap cmap);
+  CharMapInfo(int index,
+              FT_CharMap cmap);
 
-  QString stringifyIndex(int code, int idx);
+  QString stringifyIndex(int code,
+                         int idx);
   QString stringifyIndexShort(int code);
 
-
   friend bool
-  operator==(const CharMapInfo& lhs, const CharMapInfo& rhs)
+  operator==(const CharMapInfo& lhs,
+             const CharMapInfo& rhs)
   {
-    // omitting `ptr` by design!
+    // Omitting `ptr` by design!
     return lhs.index == rhs.index
            && lhs.encoding == rhs.encoding
            && lhs.platformID == rhs.platformID
@@ -44,17 +47,17 @@ struct CharMapInfo
            && lhs.languageID == rhs.languageID;
   }
 
-
   friend bool
-  operator!=(const CharMapInfo& lhs, const CharMapInfo& rhs)
+  operator!=(const CharMapInfo& lhs,
+             const CharMapInfo& rhs)
   {
     return !(lhs == rhs);
   }
 
-
 private:
   int computeMaxIndex();
-  static int maxIndexForFaceAndCharMap(FT_CharMap charMap, unsigned max);
+  static int maxIndexForFaceAndCharMap(FT_CharMap charMap,
+                                       unsigned max);
 };
 
 
diff --git a/src/ftinspect/engine/engine.cpp b/src/ftinspect/engine/engine.cpp
index a4bfd8f..7497e65 100644
--- a/src/ftinspect/engine/engine.cpp
+++ b/src/ftinspect/engine/engine.cpp
@@ -8,10 +8,10 @@
 #include <stdexcept>
 #include <stdint.h>
 
-#include <freetype/ftmodapi.h>
 #include <freetype/ftdriver.h>
 #include <freetype/ftlcdfil.h>
 #include <freetype/ftmm.h>
+#include <freetype/ftmodapi.h>
 
 
 /////////////////////////////////////////////////////////////////////////////
@@ -63,12 +63,12 @@ FaceID::operator<(const FaceID& other) const
 
 
 // The face requester is a function provided by the client application to
-// the cache manager to translate an `abstract' face ID into a real
+// the cache manager to translate an 'abstract' face ID into a real
 // `FT_Face' object.
 //
-// We use a map: `faceID' is the value, and its associated key gives the
+// We use a map: `faceID` is the value, and its associated key gives the
 // font, face, and named instance indices.  Getting a key from a value is
-// slow, but this must be done only once, since `faceRequester' is only
+// slow, but this must be done only once, since `faceRequester` is only
 // called if the font is not yet in the cache.
 
 FT_Error
@@ -78,11 +78,11 @@ faceRequester(FTC_FaceID ftcFaceID,
               FT_Face* faceP)
 {
   Engine* engine = static_cast<Engine*>(requestData);
-  // `ftcFaceID' is actually an integer
-  // -> first convert pointer to same-width integer, then discard superfluous
-  //    bits (e.g., on x86_64 where pointers are wider than int)
+  // `ftcFaceID` is actually an integer
+  // -> First convert pointer to same-width integer, then discard superfluous
+  //    bits (e.g., on x86_64 where pointers are wider than `int`).
   int val = static_cast<int>(reinterpret_cast<intptr_t>(ftcFaceID));
-  // make sure this does not cause information loss
+  // Make sure this does not cause information loss.
   Q_ASSERT_X(sizeof(void*) >= sizeof(int),
              "faceRequester",
              "Pointer size must be at least the size of int"
@@ -90,9 +90,9 @@ faceRequester(FTC_FaceID ftcFaceID,
 
   const FaceID& faceID = engine->faceIDMap_.key(val);
 
-  // this is the only place where we have to check the validity of the font
+  // This is the only place where we have to check the validity of the font
   // index; note that the validity of both the face and named instance index
-  // is checked by FreeType itself
+  // is checked by FreeType itself.
   if (faceID.fontIndex < 0
       || faceID.fontIndex >= engine->numberOfOpenedFonts())
     return FT_Err_Invalid_Argument;
@@ -122,7 +122,7 @@ Engine::Engine()
 {
   ftSize_ = NULL;
   ftFallbackFace_ = NULL;
-  // we reserve value 0 for the `invalid face ID'
+  // We reserve value 0 for the 'invalid face ID'.
   faceCounter_ = 1;
 
   FT_Error error;
@@ -157,7 +157,7 @@ Engine::Engine()
   {
     // XXX error handling
   }
-  
+
   queryEngine();
   renderingEngine_
     = std::unique_ptr<RenderingEngine>(new RenderingEngine(this));
@@ -173,24 +173,25 @@ Engine::~Engine()
 
 template <class Func>
 void
-Engine::withFace(FaceID id, Func func)
+Engine::withFace(FaceID id,
+                 Func func)
 {
   FT_Face face;
-  // search triplet (fontIndex, faceIndex, namedInstanceIndex)
+  // Search triplet (fontIndex, faceIndex, namedInstanceIndex).
   auto numId = reinterpret_cast<FTC_FaceID>(faceIDMap_.value(id));
   if (numId)
   {
-    // found
+    // Found.
     if (!FTC_Manager_LookupFace(cacheManager_, numId, &face))
       func(face);
   }
   else if (id.fontIndex >= 0)
   {
-    if (faceCounter_ >= INT_MAX) // prevent overflowing
+    if (faceCounter_ >= INT_MAX) // Prevent overflow.
       return;
 
-    // not found; try to load triplet
-    // (fontIndex, faceIndex, namedInstanceIndex)
+    // Not found; try to load triplet
+    // (fontIndex, faceIndex, namedInstanceIndex).
     numId = reinterpret_cast<FTC_FaceID>(faceCounter_);
     faceIDMap_.insert(id, faceCounter_++);
 
@@ -213,7 +214,7 @@ Engine::numberOfFaces(int fontIndex)
   if (fontIndex < 0)
     return -1;
 
-  // search triplet (fontIndex, 0, 0)
+  // Search triplet (fontIndex, 0, 0).
   withFace(FaceID(fontIndex, 0, 0),
            [&](FT_Face face) { numFaces = face->num_faces; });
 
@@ -225,13 +226,13 @@ int
 Engine::numberOfNamedInstances(int fontIndex,
                                long faceIndex)
 {
-  // we return `n' named instances plus one;
-  // instance index 0 represents a face without a named instance selected
+  // We return `n` named instances plus one;
+  // instance index 0 represents a face without a named instance selected.
   int numNamedInstances = -1;
   if (fontIndex < 0)
     return -1;
 
-  withFace(FaceID(fontIndex, faceIndex, 0), 
+  withFace(FaceID(fontIndex, faceIndex, 0),
            [&](FT_Face face)
            {
              numNamedInstances
@@ -243,14 +244,17 @@ Engine::numberOfNamedInstances(int fontIndex,
 
 
 QString
-Engine::namedInstanceName(int fontIndex, long faceIndex, int index)
+Engine::namedInstanceName(int fontIndex,
+                          long faceIndex,
+                          int index)
 {
   if (fontIndex < 0)
     return {};
 
   QString name;
   withFace(FaceID(fontIndex, faceIndex, index),
-           [&](FT_Face face) {
+           [&](FT_Face face)
+           {
              name = QString("%1 %2")
                       .arg(face->family_name)
                       .arg(face->style_name);
@@ -282,11 +286,11 @@ Engine::loadFont(int fontIndex,
   curFontIndex_ = fontIndex;
   auto id = FaceID(fontIndex, faceIndex, namedInstanceIndex);
 
-  // search triplet (fontIndex, faceIndex, namedInstanceIndex)
+  // Search triplet (fontIndex, faceIndex, namedInstanceIndex).
   scaler_.face_id = reinterpret_cast<FTC_FaceID>(faceIDMap_.value(id));
   if (scaler_.face_id)
   {
-    // found
+    // Found.
     if (!FTC_Manager_LookupFace(cacheManager_, scaler_.face_id,
                                &ftFallbackFace_))
     {
@@ -302,11 +306,11 @@ Engine::loadFont(int fontIndex,
   }
   else if (fontIndex >= 0)
   {
-    if (faceCounter_ >= INT_MAX) // prevent overflowing
+    if (faceCounter_ >= INT_MAX) // Prevent overflow.
       return -1;
 
-    // not found; try to load triplet
-    // (fontIndex, faceIndex, namedInstanceIndex)
+    // Not found; try to load triplet
+    // (fontIndex, faceIndex, namedInstanceIndex).
     scaler_.face_id = reinterpret_cast<FTC_FaceID>(faceCounter_);
     faceIDMap_.insert(id, faceCounter_++);
 
@@ -377,8 +381,10 @@ Engine::reloadFont()
   if (!scaler_.face_id)
     return;
   imageType_.face_id = scaler_.face_id;
-  
-  if (FTC_Manager_LookupFace(cacheManager_, scaler_.face_id, &ftFallbackFace_))
+
+  if (FTC_Manager_LookupFace(cacheManager_,
+                             scaler_.face_id,
+                             &ftFallbackFace_))
   {
     ftFallbackFace_ = NULL;
     ftSize_ = NULL;
@@ -401,7 +407,7 @@ Engine::loadPalette()
   if (!ftSize_)
     return;
 
-  FT_Palette_Select(ftSize_->face, 
+  FT_Palette_Select(ftSize_->face,
                     static_cast<FT_UShort>(paletteIndex_),
                     &palette_);
   // XXX error handling
@@ -409,10 +415,11 @@ Engine::loadPalette()
 
 
 void
-Engine::removeFont(int fontIndex, bool closeFile)
+Engine::removeFont(int fontIndex,
+                   bool closeFile)
 {
-  // we iterate over all triplets that contain the given font index
-  // and remove them
+  // We iterate over all triplets that contain the given font index
+  // and remove them.
   QMap<FaceID, FTC_IDType>::iterator iter
     = faceIDMap_.lowerBound(FaceID(fontIndex, 0, 0));
 
@@ -475,13 +482,16 @@ Engine::currentFontHasGlyphName()
 std::vector<int>
 Engine::currentFontFixedSizes()
 {
-  if (!ftFallbackFace_ || !FT_HAS_FIXED_SIZES(ftFallbackFace_)
+  if (!ftFallbackFace_
+      || !FT_HAS_FIXED_SIZES(ftFallbackFace_)
       || !ftFallbackFace_->available_sizes)
     return {};
+
   std::vector<int> result;
   result.resize(ftFallbackFace_->num_fixed_sizes);
+  // `x_ppem` is given in 26.6 fractional pixels.
   for (int i = 0; i < ftFallbackFace_->num_fixed_sizes; i++)
-    result[i] = ftFallbackFace_->available_sizes[i].x_ppem >> 6; // XXX: ????
+    result[i] = ftFallbackFace_->available_sizes[i].x_ppem >> 6;
   return result;
 }
 
@@ -533,11 +543,15 @@ Engine::currentFontFirstUnicodeCharMap()
 
 
 unsigned
-Engine::glyphIndexFromCharCode(int code, int charMapIndex)
+Engine::glyphIndexFromCharCode(int code,
+                               int charMapIndex)
 {
   if (charMapIndex < 0)
     return code;
-  return FTC_CMapCache_Lookup(cmapCache_, scaler_.face_id, charMapIndex, code);
+  return FTC_CMapCache_Lookup(cmapCache_,
+                              scaler_.face_id,
+                              charMapIndex,
+                              code);
 }
 
 
@@ -548,9 +562,9 @@ Engine::currentFontTrackingKerning(int degree)
     return 0;
 
   FT_Pos result;
-  // this function needs and returns points, not pixels
+  // This function needs and returns points, not pixels.
   if (!FT_Get_Track_Kerning(ftSize_->face,
-                            static_cast<FT_Fixed>(scaler_.width) << 10, 
+                            static_cast<FT_Fixed>(scaler_.width) << 10,
                             -degree,
                             &result))
   {
@@ -566,8 +580,8 @@ Engine::currentFontKerning(int glyphIndex,
                            int prevIndex)
 {
   FT_Vector kern = {0, 0};
-  FT_Get_Kerning(ftSize_->face, 
-                 prevIndex, glyphIndex, 
+  FT_Get_Kerning(ftSize_->face,
+                 prevIndex, glyphIndex,
                  FT_KERNING_UNFITTED, &kern);
   return kern;
 }
@@ -636,8 +650,8 @@ Engine::loadGlyph(int glyphIndex)
 
   FT_Glyph glyph;
 
-  // the `scaler' object is set up by the
-  // `update' and `loadFont' methods
+  // The `scaler` object is set up by the
+  // `update` and `loadFont` methods.
   if (FTC_ImageCache_LookupScaler(imageCache_,
                                   &scaler_,
                                   loadFlags_,
@@ -664,11 +678,11 @@ Engine::loadGlyphIntoSlotWithoutCache(int glyphIndex,
 }
 
 
-// When continuous rendering, we don't need to call `update`
-// This is currently unused since the cache API don't support obtaining glyph
-// metrics. See `StringRenderer::loadSingleContext`
+// When continuous rendering, we don't need to call `update`.
+// This is currently unused since the cache API doesn't support obtaining
+// glyph metrics.  See `StringRenderer::loadSingleContext`.
 FT_Glyph
-Engine::loadGlyphWithoutUpdate(int glyphIndex, 
+Engine::loadGlyphWithoutUpdate(int glyphIndex,
                                FTC_Node* outNode,
                                bool forceRender)
 {
@@ -734,6 +748,7 @@ Engine::setSizeByPixel(double pixelSize)
   usingPixelSize_ = true;
 }
 
+
 void
 Engine::setSizeByPoint(double pointSize)
 {
@@ -807,7 +822,8 @@ Engine::applyMMGXDesignCoords(FT_Fixed* coords,
   if (count >= UINT_MAX)
     count = UINT_MAX - 1;
   FT_Set_Var_Design_Coordinates(ftSize_->face,
-                                static_cast<unsigned>(count), coords);
+                                static_cast<unsigned>(count),
+                                coords);
 }
 
 
@@ -828,7 +844,7 @@ Engine::update()
   else
   {
     loadFlags_ |= FT_LOAD_NO_HINTING;
-    // When the user disables hinting for tricky fonts,
+    // When users disable hinting for tricky fonts,
     // we assume that they *really* want to disable it.
     if (currentFontTricky())
       loadFlags_ |= FT_LOAD_NO_AUTOHINT;
@@ -839,7 +855,7 @@ Engine::update()
 
   // XXX handle color fonts also
 
-  scaler_.pixel = 0; // use 26.6 format
+  scaler_.pixel = 0; // Use 26.6 format.
 
   if (usingPixelSize_)
   {
@@ -865,7 +881,7 @@ Engine::update()
 void
 Engine::resetCache()
 {
-  // reset the cache
+  // Reset the cache.
   FTC_Manager_Reset(cacheManager_);
   ftFallbackFace_ = NULL;
   ftSize_ = NULL;
@@ -911,7 +927,7 @@ Engine::queryEngine()
 {
   FT_Error error;
 
-  // query engines and check for alternatives
+  // Query engines and check for alternatives.
 
   // CFF
   error = FT_Property_Get(library_,
@@ -920,7 +936,7 @@ Engine::queryEngine()
                           &engineDefaults_.cffHintingEngineDefault);
   if (error)
   {
-    // no CFF engine
+    // No CFF engine.
     engineDefaults_.cffHintingEngineDefault = -1;
     engineDefaults_.cffHintingEngineOther = -1;
   }
@@ -946,7 +962,7 @@ Engine::queryEngine()
     if (error)
       engineDefaults_.cffHintingEngineOther = -1;
 
-    // reset
+    // Reset.
     FT_Property_Set(library_,
                     "cff",
                     "hinting-engine",
@@ -960,7 +976,7 @@ Engine::queryEngine()
                           &engineDefaults_.ttInterpreterVersionDefault);
   if (error)
   {
-    // no TrueType engine
+    // No TrueType engine.
     engineDefaults_.ttInterpreterVersionDefault = -1;
     engineDefaults_.ttInterpreterVersionOther = -1;
     engineDefaults_.ttInterpreterVersionOther1 = -1;
@@ -997,7 +1013,7 @@ Engine::queryEngine()
     if (error)
       engineDefaults_.ttInterpreterVersionOther1 = -1;
 
-    // reset
+    // Reset.
     FT_Property_Set(library_,
                     "truetype",
                     "interpreter-version",
@@ -1018,10 +1034,12 @@ Engine::loadPaletteInfos()
     return;
   }
 
-  // size never exceeds max val of ushort.
+  // The size never exceeds the maximum value of `unsigned short`.
   curPaletteInfos_.reserve(paletteData_.num_palettes);
   for (int i = 0; i < paletteData_.num_palettes; ++i)
-    curPaletteInfos_.emplace_back(ftFallbackFace_, paletteData_, i,
+    curPaletteInfos_.emplace_back(ftFallbackFace_,
+                                  paletteData_,
+                                  i,
                                   &curSFNTNames_);
 }
 
diff --git a/src/ftinspect/engine/engine.hpp b/src/ftinspect/engine/engine.hpp
index 266599c..c2034e8 100644
--- a/src/ftinspect/engine/engine.hpp
+++ b/src/ftinspect/engine/engine.hpp
@@ -5,32 +5,33 @@
 
 #pragma once
 
-#include "fontfilemanager.hpp"
-#include "paletteinfo.hpp"
+#include "charmap.hpp"
 #include "fontinfo.hpp"
+#include "fontfilemanager.hpp"
 #include "mmgx.hpp"
+#include "paletteinfo.hpp"
 #include "rendering.hpp"
-#include "charmap.hpp"
 
-#include <vector>
 #include <memory>
 #include <utility>
+#include <vector>
+
 #include <QString>
 #include <QMap>
 
 #include <ft2build.h>
 #include <freetype/freetype.h>
-#include <freetype/ftoutln.h>
 #include <freetype/ftcache.h>
-#include <freetype/ftlcdfil.h>
 #include <freetype/ftcolor.h>
+#include <freetype/ftlcdfil.h>
+#include <freetype/ftoutln.h>
 
 
 // This structure maps the (font, face, instance) index triplet to abstract
-// IDs (generated by a running number stored in MainGUI's `faceCounter'
+// IDs (generated by a running number stored in MainGUI's `faceCounter`
 // member).
 //
-// Qt's `QMap' class needs an implementation of the `<' operator.
+// Qt's `QMap` class needs an implementation of the `<` operator.
 
 struct FaceID
 {
@@ -45,12 +46,13 @@ struct FaceID
   bool operator<(const FaceID& other) const;
 };
 
-// FreeType specific data.
+
+// FreeType-specific data.
 
 class Engine
 {
 public:
-  //////// Nested definitions (forward decl)
+  //////// Nested definitions (forward declarations).
   enum FontType : int;
 
   struct EngineDefaultValues
@@ -68,7 +70,7 @@ public:
   Engine();
   ~Engine();
 
-  // Disable copying
+  // Disable copying.
   Engine(const Engine& other) = delete;
   Engine& operator=(const Engine& other) = delete;
 
@@ -76,23 +78,25 @@ public:
 
   int loadFont(int fontIndex,
                long faceIndex,
-               int namedInstanceIndex); // return number of glyphs
+               int namedInstanceIndex); // Return number of glyphs.
   FT_Glyph loadGlyph(int glyphIndex);
-  int loadGlyphIntoSlotWithoutCache(int glyphIndex, bool noScale = false);
+  int loadGlyphIntoSlotWithoutCache(int glyphIndex,
+                                    bool noScale = false);
 
-  // Sometimes the engine is already updated, and we want to be faster
+  // Sometimes the engine is already updated, and we want to be faster.
   FT_Glyph loadGlyphWithoutUpdate(int glyphIndex,
                                   FTC_Node* outNode = NULL,
                                   bool forceRender = false);
 
-  // reload current triplet, but with updated settings, useful for updating
-  // `ftSize_` and `ftFallbackFace_` only - more convenient than `loadFont`
+  // Reload current triplet, but with updated settings, useful for updating
+  // `ftSize_` and `ftFallbackFace_` only - more convenient than `loadFont`.
   void reloadFont();
   void loadPalette();
 
   void openFonts(QStringList const& fontFileNames);
-  void removeFont(int fontIndex, bool closeFile = true);
-  
+  void removeFont(int fontIndex,
+                  bool closeFile = true);
+
   void update();
   void resetCache();
   void loadDefaults();
@@ -116,15 +120,16 @@ public:
   FT_Size_Metrics const& currentFontMetrics();
   FT_GlyphSlot currentFaceSlot();
 
-  bool renderReady(); // Can we render bitmaps? (implys `fontValid`)
-  bool fontValid(); // Is the current font valid (valid font may be unavailable
-                    // to render, such as non-scalable font with invalid sizes)
+  bool renderReady(); // Can we render bitmaps (implies `fontValid`)?
+  bool fontValid(); // Is the current font valid (valid font may be
+                    // unavailable to render, such as non-scalable font with
+                    // invalid sizes)?
 
   int currentFontType() const { return fontType_; }
   const QString& currentFamilyName() { return curFamilyName_; }
   const QString& currentStyleName() { return curStyleName_; }
   int currentFontNumberOfGlyphs() { return curNumGlyphs_; }
-  
+
   std::vector<PaletteInfo>& currentFontPalettes() { return curPaletteInfos_; }
   FT_Color* currentPalette() { return palette_; }
   FT_Palette_Data& currentFontPaletteData() { return paletteData_; }
@@ -137,24 +142,28 @@ public:
   long numberOfFaces(int fontIndex);
   int numberOfNamedInstances(int fontIndex,
                              long faceIndex);
-  QString namedInstanceName(int fontIndex, long faceIndex, int index);
+  QString namedInstanceName(int fontIndex,
+                            long faceIndex,
+                            int index);
 
   bool currentFontTricky();
   bool currentFontBitmapOnly();
   bool currentFontHasEmbeddedBitmap();
   bool currentFontHasColorLayers();
   bool currentFontHasGlyphName();
-  
+
   std::vector<int> currentFontFixedSizes();
   bool currentFontPSInfo(PS_FontInfoRec& outInfo);
   bool currentFontPSPrivateInfo(PS_PrivateRec& outInfo);
   std::vector<SFNTTableInfo>& currentFontSFNTTableInfo();
 
   int currentFontFirstUnicodeCharMap();
-  // Note: the current font face must be properly set
-  unsigned glyphIndexFromCharCode(int code, int charMapIndex);
+  // Note: the current font face must be properly set.
+  unsigned glyphIndexFromCharCode(int code,
+                                  int charMapIndex);
   FT_Pos currentFontTrackingKerning(int degree);
-  FT_Vector currentFontKerning(int glyphIndex, int prevIndex);
+  FT_Vector currentFontKerning(int glyphIndex,
+                               int prevIndex);
   std::pair<int, int> currentSizeAscDescPx();
 
   // (settings)
@@ -167,12 +176,8 @@ public:
   bool lcdUsingSubPixelPositioning() { return lcdSubPixelPositioning_; }
   bool useColorLayer() { return useColorLayer_; }
   int paletteIndex() { return paletteIndex_; }
-  FT_Render_Mode
-  renderMode()
-  {
-    return static_cast<FT_Render_Mode>(renderMode_);
-  }
-
+  FT_Render_Mode renderMode()
+                   { return static_cast<FT_Render_Mode>(renderMode_); }
 
   //////// Setters (direct or indirect)
 
@@ -182,37 +187,33 @@ public:
   void setHinting(bool hinting) { doHinting_ = hinting; }
   void setAutoHinting(bool autoHinting) { doAutoHinting_ = autoHinting; }
   void setHorizontalHinting(bool horHinting)
-  {
-    doHorizontalHinting_ = horHinting;
-  }
+         { doHorizontalHinting_ = horHinting; }
   void setVerticalHinting(bool verticalHinting)
-  {
-    doVerticalHinting_ = verticalHinting;
-  }
+         { doVerticalHinting_ = verticalHinting; }
   void setBlueZoneHinting(bool blueZoneHinting)
-  {
-    doBlueZoneHinting_ = blueZoneHinting;
-  }
+         { doBlueZoneHinting_ = blueZoneHinting; }
   void setShowSegments(bool showSegments) { showSegments_ = showSegments; }
   void setAntiAliasingTarget(int target) { antiAliasingTarget_ = target; }
   void setRenderMode(int mode) { renderMode_ = mode; }
-  void setAntiAliasingEnabled(bool enabled) { antiAliasingEnabled_ = enabled; }
+  void setAntiAliasingEnabled(bool enabled)
+         { antiAliasingEnabled_ = enabled; }
   void setEmbeddedBitmapEnabled(bool enabled) { embeddedBitmap_ = enabled; }
   void setUseColorLayer(bool colorLayer) { useColorLayer_ = colorLayer; }
   void setPaletteIndex(int index) { paletteIndex_ = index; }
   void setLCDSubPixelPositioning(bool sp) { lcdSubPixelPositioning_ = sp; }
-  
+
   // (settings without backing fields)
-  // Note: These 3 functions now takes actual mode/version from FreeType,
-  // instead of values from enum in MainGUI!
+  // Note: These 3 functions now take the actual mode/version from FreeType
+  // instead of values from the enum in MainGUI!
   void setLcdFilter(FT_LcdFilter filter);
   void setCFFHintingMode(int mode);
   void setTTInterpreterVersion(int version);
 
   void setStemDarkening(bool darkening);
-  void applyMMGXDesignCoords(FT_Fixed* coords, size_t count);
+  void applyMMGXDesignCoords(FT_Fixed* coords,
+                             size_t count);
 
-  //////// Misc
+  //////// Miscellaneous
 
   friend FT_Error faceRequester(FTC_FaceID,
                                 FT_Library,
@@ -221,7 +222,7 @@ public:
 
 private:
   using FTC_IDType = uintptr_t;
-  FTC_IDType faceCounter_; // a running number used to initialize `faceIDMap'
+  FTC_IDType faceCounter_; // A running number to initialize `faceIDMap`.
   QMap<FaceID, FTC_IDType> faceIDMap_;
 
   FontFileManager fontFileManager_;
@@ -251,10 +252,10 @@ private:
 
   // settings
   FTC_ScalerRec scaler_ = {};
-  FTC_ImageTypeRec imageType_; // for `loadGlyphWithoutUpdate`
-  // Sometimes the font may be valid (i.e. a face object can be retrieved), but
-  // the size may be invalid (e.g. non-scalable fonts).
-  // Therefore, we use a fallback face for all non-rendering work.
+  FTC_ImageTypeRec imageType_; // For `loadGlyphWithoutUpdate`.
+  // Sometimes the font may be valid (i.e., a face object can be retrieved),
+  // but the size is invalid (e.g., non-scalable fonts).  Therefore, we use a
+  // fallback face for all non-rendering work.
   FT_Face ftFallbackFace_ = NULL; // Never perform rendering or write to this!
   FT_Size ftSize_ = NULL;
   FT_Palette_Data paletteData_ = {};
@@ -277,7 +278,7 @@ private:
   int paletteIndex_ = -1;
   int antiAliasingTarget_ = 0;
   bool lcdSubPixelPositioning_ = false;
-  int renderMode_ = 0; 
+  int renderMode_ = 0;
 
   unsigned long loadFlags_ = FT_LOAD_DEFAULT;
 
@@ -286,9 +287,10 @@ private:
   void queryEngine();
   void loadPaletteInfos();
 
-  // Safe to put the impl to the cpp.
+  // It is safe to put the implementation into the corresponding cpp file.
   template <class Func>
-  void withFace(FaceID id, Func func);
+  void withFace(FaceID id,
+                Func func);
 
 public:
 
diff --git a/src/ftinspect/engine/fontfilemanager.cpp 
b/src/ftinspect/engine/fontfilemanager.cpp
index f058dc2..6dbe78d 100644
--- a/src/ftinspect/engine/fontfilemanager.cpp
+++ b/src/ftinspect/engine/fontfilemanager.cpp
@@ -3,20 +3,19 @@
 // Copyright (C) 2022 by Charlie Jiang.
 
 
+#include "engine.hpp"
 #include "fontfilemanager.hpp"
 
 #include <QCoreApplication>
 #include <QGridLayout>
 #include <QMessageBox>
 
-#include "engine.hpp"
-
 
 FontFileManager::FontFileManager(Engine* engine)
 : engine_(engine)
 {
   fontWatcher_ = new QFileSystemWatcher(this);
-  // if the current input file is invalid we retry once a second to load it
+  // if the current input file is invalid we retry once a second to load it.
   watchTimer_ = new QTimer;
   watchTimer_->setInterval(1000);
 
@@ -35,7 +34,8 @@ FontFileManager::size()
 
 
 void
-FontFileManager::append(QStringList const& newFileNames, bool alertNotExist)
+FontFileManager::append(QStringList const& newFileNames,
+                        bool alertNotExist)
 {
   QStringList failedFiles;
   for (auto& name : newFileNames)
@@ -43,7 +43,7 @@ FontFileManager::append(QStringList const& newFileNames, bool 
alertNotExist)
     auto info = QFileInfo(name);
     info.setCaching(false);
 
-    // Filter non-file elements
+    // Filter out non-file elements.
     if (!info.isFile())
     {
       if (alertNotExist)
@@ -70,7 +70,7 @@ FontFileManager::append(QStringList const& newFileNames, bool 
alertNotExist)
       continue;
     }
 
-    // Uniquify elements
+    // Uniquify elements.
     auto absPath = info.absoluteFilePath();
     auto existing = false;
     for (auto& existingName : fontFileNameList_)
@@ -83,7 +83,7 @@ FontFileManager::append(QStringList const& newFileNames, bool 
alertNotExist)
       continue;
 
     if (info.size() >= INT_MAX)
-      return; // Prevent overflowing
+      return; // Prevent overflow.
     fontFileNameList_.append(info);
   }
 
@@ -95,14 +95,16 @@ FontFileManager::append(QStringList const& newFileNames, 
bool alertNotExist)
     if (failedFiles.size() == 1)
     {
       msg->setWindowTitle(tr("Failed to load file"));
-      msg->setText(tr("File failed to load:\n%1").arg(failedFiles.join("\n")));
+      msg->setText(tr("File failed to load:\n%1")
+                   .arg(failedFiles.join("\n")));
     }
     else
     {
       msg->setWindowTitle(tr("Failed to load some files"));
-      msg->setText(tr("Files failed to 
load:\n%1").arg(failedFiles.join("\n")));
+      msg->setText(tr("Files failed to load:\n%1")
+                   .arg(failedFiles.join("\n")));
     }
-    
+
     msg->setIcon(QMessageBox::Warning);
     msg->setModal(false);
     msg->open();
@@ -138,7 +140,7 @@ FontFileManager::updateWatching(int index)
     fontWatcher_->removePaths(watching);
 
   // Qt's file watcher doesn't handle symlinks;
-  // we thus fall back to polling
+  // we thus fall back to polling.
   if (fileInfo.isSymLink() || !fileInfo.exists())
     watchTimer_->start();
   else
@@ -156,8 +158,8 @@ FontFileManager::timerStart()
 void
 FontFileManager::loadFromCommandLine()
 {
-  // TODO: To support more complicated command line, we need to move this away
-  // and use `QCommandLineParser`
+  // TODO: To support more complicated command line, we need to move this
+  //       away and use `QCommandLineParser`
   auto args = QCoreApplication::arguments();
   if (!args.empty())
     args.removeFirst();
diff --git a/src/ftinspect/engine/fontfilemanager.hpp 
b/src/ftinspect/engine/fontfilemanager.hpp
index 0874fd0..1df7da3 100644
--- a/src/ftinspect/engine/fontfilemanager.hpp
+++ b/src/ftinspect/engine/fontfilemanager.hpp
@@ -4,19 +4,20 @@
 
 #pragma once
 
-#include <QObject>
-#include <QList>
+#include <QFileInfo>
 #include <QFileSystemWatcher>
+#include <QList>
+#include <QObject>
 #include <QTimer>
-#include <QFileInfo>
 
 #include <freetype/freetype.h>
 
 
 // Class to manage all opened font files, as well as monitoring local file
-// change.
+// changes.
 
 class Engine;
+
 class FontFileManager
 : public QObject
 {
@@ -26,7 +27,8 @@ public:
   ~FontFileManager() override = default;
 
   int size();
-  void append(QStringList const& newFileNames, bool alertNotExist = false);
+  void append(QStringList const& newFileNames,
+              bool alertNotExist = false);
   void remove(int index);
 
   QFileInfo& operator[](int index);
@@ -34,8 +36,8 @@ public:
   void timerStart();
   void loadFromCommandLine();
 
-  // If this is true, then the current font reloading is due to a periodic
-  // reloading for symbolic font files. Use this if you want to omit some
+  // If this is true, the current font reloading is due to a periodic
+  // reloading for symbolic font files.  Use this if you want to omit some
   // updating for periodic reloading.
   bool currentReloadDueToPeriodicUpdate() { return periodicUpdating_; }
 
diff --git a/src/ftinspect/engine/fontinfo.cpp 
b/src/ftinspect/engine/fontinfo.cpp
index e99dcb6..8a848a8 100644
--- a/src/ftinspect/engine/fontinfo.cpp
+++ b/src/ftinspect/engine/fontinfo.cpp
@@ -2,29 +2,30 @@
 
 // Copyright (C) 2022 by Charlie Jiang.
 
-#include "fontinfo.hpp"
-
 #include "engine.hpp"
+#include "fontinfo.hpp"
 
 #include <map>
-#include <unordered_map>
 #include <memory>
+#include <unordered_map>
 #include <utility>
+
 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
-#include <QTextCodec>
+# include <QTextCodec>
 #else
-#include <QStringConverter>
-#include <QByteArrayView>
+# include <QByteArrayView>
+# include <QStringConverter>
 #endif
+
 #include <freetype/ftmodapi.h>
 #include <freetype/ttnameid.h>
 #include <freetype/tttables.h>
 #include <freetype/tttags.h>
 
-#ifdef _MSC_VER // To use intrin
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-#include <intrin.h>
+#ifdef _MSC_VER // To use `intrin.h`.
+# define WIN32_LEAN_AND_MEAN
+# include <Windows.h>
+# include <intrin.h>
 #endif
 
 
@@ -38,7 +39,7 @@ SFNTName::get(Engine* engine,
     list.clear();
     return;
   }
-  
+
   auto newSize = FT_Get_Sfnt_Name_Count(face);
   if (list.size() != static_cast<size_t>(newSize))
     list.resize(newSize);
@@ -57,7 +58,7 @@ SFNTName::get(Engine* engine,
     auto len = sfntName.string_len >= INT_MAX
                  ? INT_MAX - 1
                  : sfntName.string_len;
-    obj.strBuf = QByteArray(reinterpret_cast<const char*>(sfntName.string), 
+    obj.strBuf = QByteArray(reinterpret_cast<const char*>(sfntName.string),
                             len);
     obj.str = sfntNameToQString(sfntName, &obj.strValid);
 
@@ -65,18 +66,20 @@ SFNTName::get(Engine* engine,
     {
       auto err = FT_Get_Sfnt_LangTag(face, obj.languageID, &langTag);
       if (!err)
-        obj.langTag = utf16BEToQString(reinterpret_cast<char*>(langTag.string),
-                                       langTag.string_len);
+        obj.langTag = utf16BEToQString(
+                        reinterpret_cast<char*>(langTag.string),
+                        langTag.string_len);
     }
   }
 }
 
 
 QString
-SFNTName::sfntNameToQString(FT_SfntName const& sfntName, 
+SFNTName::sfntNameToQString(FT_SfntName const& sfntName,
                             bool* outSuccess)
 {
-  return sfntNameToQString(sfntName.platform_id, sfntName.encoding_id,
+  return sfntNameToQString(sfntName.platform_id,
+                           sfntName.encoding_id,
                            reinterpret_cast<char const*>(sfntName.string),
                            sfntName.string_len,
                            outSuccess);
@@ -84,10 +87,13 @@ SFNTName::sfntNameToQString(FT_SfntName const& sfntName,
 
 
 QString
-SFNTName::sfntNameToQString(SFNTName const& sfntName, bool* outSuccess)
+SFNTName::sfntNameToQString(SFNTName const& sfntName,
+                            bool* outSuccess)
 {
-  return sfntNameToQString(sfntName.platformID, sfntName.encodingID,
-                           sfntName.strBuf.data(), sfntName.strBuf.size(),
+  return sfntNameToQString(sfntName.platformID,
+                           sfntName.encodingID,
+                           sfntName.strBuf.data(),
+                           sfntName.strBuf.size(),
                            outSuccess);
 }
 
@@ -111,6 +117,7 @@ SFNTName::sfntNameToQString(unsigned short platformID,
   case TT_PLATFORM_APPLE_UNICODE:
     // All UTF-16BE.
     return utf16BEToQString(str, size);
+
   case TT_PLATFORM_MACINTOSH:
     if (encodingID == TT_MAC_ID_ROMAN)
       return QString::fromLatin1(str, static_cast<int>(size));
@@ -118,6 +125,7 @@ SFNTName::sfntNameToQString(unsigned short platformID,
     if (outSuccess)
       *outSuccess = false;
     return "<encoding unsupported>";
+
   case TT_PLATFORM_ISO:
     switch (encodingID)
     {
@@ -131,13 +139,14 @@ SFNTName::sfntNameToQString(unsigned short platformID,
         *outSuccess = false;
       return "<encoding unsupported>";
     }
+
   case TT_PLATFORM_MICROSOFT:
     switch (encodingID)
     {
-      /* TT_MS_ID_SYMBOL_CS is Unicode, similar to PID/EID=3/1 */
+      // TT_MS_ID_SYMBOL_CS is Unicode, similar to PID/EID=3/1.
     case TT_MS_ID_SYMBOL_CS:
     case TT_MS_ID_UNICODE_CS:
-    case TT_MS_ID_UCS_4: // This is UTF-16LE as well, according to MS doc
+    case TT_MS_ID_UCS_4: // This is UTF-16LE as well, according to MS doc.
       return utf16BEToQString(str, size);
 
     default:
@@ -203,7 +212,7 @@ FontBasicInfo::get(Engine* engine)
       = head->Created[1] | static_cast<uint64_t>(head->Created[0]) << 32;
     uint64_t modifiedTimestamp
       = head->Modified[1] | static_cast<uint64_t>(head->Modified[0]) << 32;
-    
+
     result.createdTime
       = QDateTime::fromSecsSinceEpoch(createdTimestamp, Qt::OffsetFromUTC)
           .addSecs(-2082844800);
@@ -229,7 +238,7 @@ FontTypeEntries::get(Engine* engine)
   auto face = engine->currentFallbackFtFace();
   if (!face)
     return {};
-  
+
   FontTypeEntries result = {};
   result.driverName = QString(FT_FACE_DRIVER_NAME(face));
   result.sfnt = FT_IS_SFNT(face);
@@ -300,7 +309,7 @@ operator==(const PS_PrivateRec& lhs,
          && lhs.blue_scale == rhs.blue_scale
          && lhs.blue_shift == rhs.blue_shift
          && lhs.blue_fuzz == rhs.blue_fuzz
-         && std::equal(std::begin(lhs.standard_width), 
+         && std::equal(std::begin(lhs.standard_width),
                        std::end(lhs.standard_width),
                        std::begin(rhs.standard_width))
          && std::equal(std::begin(lhs.standard_height),
@@ -338,7 +347,7 @@ FontFixedSize::get(Engine* engine,
     list.clear();
     return true;
   }
-  
+
   auto changed = false;
   if (list.size() != static_cast<size_t>(face->num_fixed_sizes))
   {
@@ -352,19 +361,18 @@ FontFixedSize::get(Engine* engine,
     FontFixedSize ffs = {};
     auto bSize = face->available_sizes + i;
     ffs.height = bSize->height;
-    ffs.width  = bSize->width;
-    ffs.size   = bSize->size / 64.0;
-    ffs.xPpem  = bSize->x_ppem / 64.0;
-    ffs.yPpem  = bSize->y_ppem / 64.0;
+    ffs.width = bSize->width;
+    ffs.size = bSize->size / 64.0;
+    ffs.xPpem = bSize->x_ppem / 64.0;
+    ffs.yPpem = bSize->y_ppem / 64.0;
     if (ffs != list[i])
     {
-      
       if (!changed)
       {
         onUpdateNeeded();
         changed = true;
       }
-      
+
       list[i] = ffs;
     }
   }
@@ -386,7 +394,7 @@ struct SFNTHeaderRec
 {
   uint32_t formatTag;
   uint16_t numTables;
-  // There'll be some padding, but it doesn't matter.
+  // There will be some padding, but it doesn't matter.
 };
 
 
@@ -403,11 +411,11 @@ uint32_t
 bigEndianToNative(uint32_t n)
 {
 #ifdef _MSC_VER
-  #if REG_DWORD == REG_DWORD_LITTLE_ENDIAN
-    return _byteswap_ulong(n);
-  #else
-    return n;
-  #endif
+# if REG_DWORD == REG_DWORD_LITTLE_ENDIAN
+  return _byteswap_ulong(n);
+# else
+  return n;
+# endif
 #else
   auto np = reinterpret_cast<unsigned char*>(&n);
 
@@ -423,11 +431,11 @@ uint16_t
 bigEndianToNative(uint16_t n)
 {
 #ifdef _MSC_VER
-#if REG_DWORD == REG_DWORD_LITTLE_ENDIAN
+# if REG_DWORD == REG_DWORD_LITTLE_ENDIAN
   return _byteswap_ushort(n);
-#else
+# else
   return n;
-#endif
+# endif
 #else
   auto np = reinterpret_cast<unsigned char*>(&n);
 
@@ -441,13 +449,14 @@ void readSingleFace(QFile& file,
                     uint32_t offset,
                     unsigned faceIndex,
                     std::vector<TTTableRec>& tempTables,
-                    std::map<unsigned long, SFNTTableInfo>& result)
+                    std::map<unsigned long,
+                    SFNTTableInfo>& result)
 {
   if (!file.seek(offset))
     return;
 
   SFNTHeaderRec sfntHeader = {};
-  if (file.read(reinterpret_cast<char*>(&sfntHeader), 
+  if (file.read(reinterpret_cast<char*>(&sfntHeader),
                 sizeof(SFNTHeaderRec))
       != sizeof(SFNTHeaderRec))
     return;
@@ -455,7 +464,7 @@ void readSingleFace(QFile& file,
   sfntHeader.numTables = bigEndianToNative(sfntHeader.numTables);
 
   unsigned short validEntries = sfntHeader.numTables;
-  
+
   if (sfntHeader.formatTag != TTAG_OTTO)
   {
     // TODO check SFNT Header
@@ -467,7 +476,8 @@ void readSingleFace(QFile& file,
 
   tempTables.resize(validEntries);
   auto desiredLen = static_cast<long long>(validEntries * sizeof(TTTableRec));
-  auto readLen = file.read(reinterpret_cast<char*>(tempTables.data()), 
desiredLen);
+  auto readLen = file.read(reinterpret_cast<char*>(tempTables.data()),
+                           desiredLen);
   if (readLen != desiredLen)
     return;
 
@@ -541,17 +551,17 @@ SFNTTableInfo::getForAll(Engine* engine,
   if (ttcHeader.ttcTag == TTAG_ttcf
       && (ttcHeader.majorVersion == 2 || ttcHeader.majorVersion == 1))
   {
-    // Valid TTC file
+    // Valid TTC file.
     std::unique_ptr<unsigned> offsets(new unsigned[ttcHeader.numFonts]);
     auto desiredLen = static_cast<long long>(ttcHeader.numFonts
                                              * sizeof(unsigned));
     readLen = file.read(reinterpret_cast<char*>(offsets.get()), desiredLen);
     if (readLen != desiredLen)
       return;
-    
-    for (unsigned faceIndex = 0; 
-        faceIndex < ttcHeader.numFonts; 
-        faceIndex++)
+
+    for (unsigned faceIndex = 0;
+         faceIndex < ttcHeader.numFonts;
+         faceIndex++)
     {
       auto offset = bigEndianToNative(offsets.get()[faceIndex]);
       readSingleFace(file, offset, faceIndex, tables, result);
@@ -559,7 +569,7 @@ SFNTTableInfo::getForAll(Engine* engine,
   }
   else
   {
-    // Not TTC file, try single SFNT
+    // Not TTC file, try single SFNT.
     if (!file.seek(0))
       return;
     readSingleFace(file, 0, 0, tables, result);
@@ -571,7 +581,6 @@ SFNTTableInfo::getForAll(Engine* engine,
 }
 
 
-
 FT_UInt16
 readUInt16(void* ptr)
 {
@@ -587,7 +596,7 @@ readF2Dot14(void* ptr)
 
 
 void
-CompositeGlyphInfo::get(Engine* engine, 
+CompositeGlyphInfo::get(Engine* engine,
                         std::vector<CompositeGlyphInfo>& list)
 {
   list.clear();
@@ -599,8 +608,8 @@ CompositeGlyphInfo::get(Engine* engine,
       return;
   }
 
-  // We're not using the FreeType's subglyph APIs, but directly reading from
-  // the `glyf` table since it's faster
+  // We are not using FreeType's subglyph APIs but directly reading from
+  // the 'glyf' table since it is faster.
   auto head = static_cast<TT_Header*>(FT_Get_Sfnt_Table(face, FT_SFNT_HEAD));
   auto maxp
     = static_cast<TT_MaxProfile*>(FT_Get_Sfnt_Table(face, FT_SFNT_MAXP));
@@ -630,24 +639,26 @@ CompositeGlyphInfo::get(Engine* engine,
 
   for (size_t i = 0; i < maxp->numGlyphs; i++)
   {
-    FT_UInt32  loc, end;
+    FT_UInt32 loc;
+    FT_UInt32 end;
+
     if (head->Index_To_Loc_Format)
     {
-      loc = static_cast<FT_UInt32>(offset[4 * i    ]) << 24 |
-            static_cast<FT_UInt32>(offset[4 * i + 1]) << 16 |
-            static_cast<FT_UInt32>(offset[4 * i + 2]) << 8  |
-            static_cast<FT_UInt32>(offset[4 * i + 3])       ;
-      end = static_cast<FT_UInt32>(offset[4 * i + 4]) << 24 |
-            static_cast<FT_UInt32>(offset[4 * i + 5]) << 16 |
-            static_cast<FT_UInt32>(offset[4 * i + 6]) << 8  |
-            static_cast<FT_UInt32>(offset[4 * i + 7])       ;
+      loc = static_cast<FT_UInt32>(offset[4 * i]) << 24
+            | static_cast<FT_UInt32>(offset[4 * i + 1]) << 16
+            | static_cast<FT_UInt32>(offset[4 * i + 2]) << 8
+            | static_cast<FT_UInt32>(offset[4 * i + 3]);
+      end = static_cast<FT_UInt32>(offset[4 * i + 4]) << 24
+            | static_cast<FT_UInt32>(offset[4 * i + 5]) << 16
+            | static_cast<FT_UInt32>(offset[4 * i + 6]) << 8
+            | static_cast<FT_UInt32>(offset[4 * i + 7]);
     }
     else
     {
-      loc = static_cast<FT_UInt32>(offset[2 * i    ]) << 9 |
-            static_cast<FT_UInt32>(offset[2 * i + 1]) << 1 ;
-      end = static_cast<FT_UInt32>(offset[2 * i + 2]) << 9 |
-            static_cast<FT_UInt32>(offset[2 * i + 3]) << 1 ;
+      loc = static_cast<FT_UInt32>(offset[2 * i]) << 9
+            | static_cast<FT_UInt32>(offset[2 * i + 1]) << 1;
+      end = static_cast<FT_UInt32>(offset[2 * i + 2]) << 9
+            | static_cast<FT_UInt32>(offset[2 * i + 3]) << 1;
     }
 
     if (end > glyfLength)
@@ -657,8 +668,8 @@ CompositeGlyphInfo::get(Engine* engine,
       continue;
 
     auto len = static_cast<FT_Int16>(readUInt16(buffer + loc));
-    loc += 10;  // skip header
-    if (len >= 0) // not a composite one
+    loc += 10;  // Skip header.
+    if (len >= 0) // Not a composite one.
       continue;
 
     std::vector<SubGlyph> subglyphs;
@@ -694,7 +705,7 @@ CompositeGlyphInfo::get(Engine* engine,
                              std::pair<short, short>(arg1, arg2),
                              (flags & 0x0800) != 0);
       // TODO: Use "Default behavior" when neither SCALED_COMPONENT_OFFSET
-      //       and UNSCALED_COMPONENT_OFFSET are set.
+      //       nor UNSCALED_COMPONENT_OFFSET are set.
 
       auto& glyph = subglyphs.back();
       if (flags & 0x0008)
diff --git a/src/ftinspect/engine/fontinfo.hpp 
b/src/ftinspect/engine/fontinfo.hpp
index 5a5fb1b..f1cc456 100644
--- a/src/ftinspect/engine/fontinfo.hpp
+++ b/src/ftinspect/engine/fontinfo.hpp
@@ -4,15 +4,18 @@
 
 #pragma once
 
-#include <set>
 #include <cstring>
-#include <QDateTime>
+#include <set>
+
 #include <QByteArray>
+#include <QDateTime>
 #include <QString>
+
 #include <freetype/freetype.h>
 #include <freetype/ftsnames.h>
 #include <freetype/t1tables.h>
 
+
 class Engine;
 
 struct SFNTTableInfo
@@ -23,7 +26,8 @@ struct SFNTTableInfo
   bool valid = false;
   std::set<unsigned long> sharedFaces;
 
-  static void getForAll(Engine* engine, std::vector<SFNTTableInfo>& infos);
+  static void getForAll(Engine* engine,
+                        std::vector<SFNTTableInfo>& infos);
 
 
   friend bool
@@ -31,10 +35,10 @@ struct SFNTTableInfo
              const SFNTTableInfo& rhs)
   {
     return lhs.tag == rhs.tag
-      && lhs.offset == rhs.offset
-      && lhs.length == rhs.length
-      && lhs.valid == rhs.valid
-      && lhs.sharedFaces == rhs.sharedFaces;
+           && lhs.offset == rhs.offset
+           && lhs.length == rhs.length
+           && lhs.valid == rhs.valid
+           && lhs.sharedFaces == rhs.sharedFaces;
   }
 
 
@@ -65,7 +69,7 @@ struct SFNTName
   static QString sfntNameToQString(SFNTName const& sfntName,
                                    bool* outSuccess = NULL);
   static QString sfntNameToQString(unsigned short platformID,
-                                   unsigned short encodingID, 
+                                   unsigned short encodingID,
                                    char const* str, size_t size,
                                    bool* outSuccess = NULL);
   static QString utf16BEToQString(char const* str, size_t size);
@@ -76,11 +80,11 @@ struct SFNTName
              const SFNTName& rhs)
   {
     return lhs.nameID == rhs.nameID
-      && lhs.platformID == rhs.platformID
-      && lhs.encodingID == rhs.encodingID
-      && lhs.languageID == rhs.languageID
-      && lhs.strBuf == rhs.strBuf
-      && lhs.langTag == rhs.langTag;
+           && lhs.platformID == rhs.platformID
+           && lhs.encodingID == rhs.encodingID
+           && lhs.languageID == rhs.languageID
+           && lhs.strBuf == rhs.strBuf
+           && lhs.langTag == rhs.langTag;
   }
 
 
@@ -109,21 +113,21 @@ struct FontBasicInfo
   static FontBasicInfo get(Engine* engine);
 
 
-  // Oh, we have no C++20 :(
+  // No C++20 (yet).
   friend bool
   operator==(const FontBasicInfo& lhs,
              const FontBasicInfo& rhs)
   {
     return lhs.numFaces == rhs.numFaces
-      && lhs.familyName == rhs.familyName
-      && lhs.styleName == rhs.styleName
-      && lhs.postscriptName == rhs.postscriptName
-      && lhs.createdTime == rhs.createdTime
-      && lhs.modifiedTime == rhs.modifiedTime
-      && lhs.revision == rhs.revision
-      && lhs.copyright == rhs.copyright
-      && lhs.trademark == rhs.trademark
-      && lhs.manufacturer == rhs.manufacturer;
+           && lhs.familyName == rhs.familyName
+           && lhs.styleName == rhs.styleName
+           && lhs.postscriptName == rhs.postscriptName
+           && lhs.createdTime == rhs.createdTime
+           && lhs.modifiedTime == rhs.modifiedTime
+           && lhs.revision == rhs.revision
+           && lhs.copyright == rhs.copyright
+           && lhs.trademark == rhs.trademark
+           && lhs.manufacturer == rhs.manufacturer;
   }
 
 
@@ -139,14 +143,14 @@ struct FontBasicInfo
 struct FontTypeEntries
 {
   QString driverName;
-  bool sfnt          : 1;
-  bool scalable      : 1;
-  bool mmgx          : 1;
-  bool fixedSizes    : 1;
+  bool sfnt : 1;
+  bool scalable : 1;
+  bool mmgx : 1;
+  bool fixedSizes : 1;
   bool hasHorizontal : 1;
-  bool hasVertical   : 1;
-  bool fixedWidth    : 1;
-  bool glyphNames    : 1;
+  bool hasVertical : 1;
+  bool fixedWidth : 1;
+  bool glyphNames : 1;
 
   int emSize;
   FT_BBox globalBBox;
@@ -161,32 +165,32 @@ struct FontTypeEntries
   static FontTypeEntries get(Engine* engine);
 
 
-  // Oh, we have no C++20 :(
+  // No C++20 (yet).
   friend bool
   operator==(const FontTypeEntries& lhs,
              const FontTypeEntries& rhs)
   {
     return lhs.driverName == rhs.driverName
-      && lhs.sfnt == rhs.sfnt
-      && lhs.scalable == rhs.scalable
-      && lhs.mmgx == rhs.mmgx
-      && lhs.fixedSizes == rhs.fixedSizes
-      && lhs.hasHorizontal == rhs.hasHorizontal
-      && lhs.hasVertical == rhs.hasVertical
-      && lhs.fixedWidth == rhs.fixedWidth
-      && lhs.glyphNames == rhs.glyphNames
-      && lhs.emSize == rhs.emSize
-      && lhs.globalBBox.xMax == rhs.globalBBox.xMax
-      && lhs.globalBBox.xMin == rhs.globalBBox.xMin
-      && lhs.globalBBox.yMax == rhs.globalBBox.yMax
-      && lhs.globalBBox.yMin == rhs.globalBBox.yMin
-      && lhs.ascender == rhs.ascender
-      && lhs.descender == rhs.descender
-      && lhs.height == rhs.height
-      && lhs.maxAdvanceWidth == rhs.maxAdvanceWidth
-      && lhs.maxAdvanceHeight == rhs.maxAdvanceHeight
-      && lhs.underlinePos == rhs.underlinePos
-      && lhs.underlineThickness == rhs.underlineThickness;
+           && lhs.sfnt == rhs.sfnt
+           && lhs.scalable == rhs.scalable
+           && lhs.mmgx == rhs.mmgx
+           && lhs.fixedSizes == rhs.fixedSizes
+           && lhs.hasHorizontal == rhs.hasHorizontal
+           && lhs.hasVertical == rhs.hasVertical
+           && lhs.fixedWidth == rhs.fixedWidth
+           && lhs.glyphNames == rhs.glyphNames
+           && lhs.emSize == rhs.emSize
+           && lhs.globalBBox.xMax == rhs.globalBBox.xMax
+           && lhs.globalBBox.xMin == rhs.globalBBox.xMin
+           && lhs.globalBBox.yMax == rhs.globalBBox.yMax
+           && lhs.globalBBox.yMin == rhs.globalBBox.yMin
+           && lhs.ascender == rhs.ascender
+           && lhs.descender == rhs.descender
+           && lhs.height == rhs.height
+           && lhs.maxAdvanceWidth == rhs.maxAdvanceWidth
+           && lhs.maxAdvanceHeight == rhs.maxAdvanceHeight
+           && lhs.underlinePos == rhs.underlinePos
+           && lhs.underlineThickness == rhs.underlineThickness;
   }
 
 
@@ -199,12 +203,16 @@ struct FontTypeEntries
 };
 
 
-// For PostScript `PS_FontInfoRec` and `PS_PrivateRec`, we don't create our own
-// structs but direct use the ones provided by FreeType.
-// But we still need to provided `operator==`
-// No operator== for PS_FontInfoRec since there's little point to deep-copy it
-// bool operator==(const PS_FontInfoRec& lhs, const PS_FontInfoRec& rhs);
-bool operator==(const PS_PrivateRec& lhs, const PS_PrivateRec& rhs);
+// We directly use FreeType's `PS_FontInfoRec` and `PS_PrivateRec`
+// structures.  However, we still need to provide `operator==`.
+//
+// On the other hand, we omit `operator==` for `PS_FontInfoRec` since
+// there's little point to deep-copy it.
+//
+// bool operator==(const PS_FontInfoRec& lhs,
+//                   const PS_FontInfoRec& rhs);
+bool operator==(const PS_PrivateRec& lhs,
+                const PS_PrivateRec& rhs);
 
 
 struct FontFixedSize
@@ -215,10 +223,9 @@ struct FontFixedSize
   double xPpem;
   double yPpem;
 
-
-  // Returns that if the list is updated
-  // Using a callback because Qt needs `beginResetModel` to be called 
**before**
-  // the internal storage updates.
+  // Returns that if the list is updated.  WL: ???
+  // We use a callback because Qt needs `beginResetModel` to be called
+  // *before* the internal storage updates.
   static bool get(Engine* engine,
                   std::vector<FontFixedSize>& list,
                   const std::function<void()>& onUpdateNeeded);
@@ -229,10 +236,10 @@ struct FontFixedSize
              const FontFixedSize& rhs)
   {
     return lhs.height == rhs.height
-      && lhs.width == rhs.width
-      && lhs.size == rhs.size
-      && lhs.xPpem == rhs.xPpem
-      && lhs.yPpem == rhs.yPpem;
+           && lhs.width == rhs.width
+           && lhs.size == rhs.size
+           && lhs.xPpem == rhs.xPpem
+           && lhs.yPpem == rhs.yPpem;
   }
 
 
@@ -251,27 +258,28 @@ struct CompositeGlyphInfo
   {
     enum PositionType : uint8_t
     {
-      PT_Offset, // Child's points are added with a xy-offset
-      PT_Align // One point of the child is aligned with one point of the 
parent
+      PT_Offset, // Child's points are added with an xy-offset.
+      PT_Align // A point of the child is aligned with a point of the parent.
     };
     enum TransformationType : uint8_t
     {
-      TT_UniformScale, // uniform scale for x- and y-axis
-      TT_XYScale, // separate scale for x- and y-axis
-      TT_Matrix // 2x2 matrix
+      TT_UniformScale, // Uniform scale for x- and y-axis.
+      TT_XYScale, // Separate scales for x- and y-axis.
+      TT_Matrix // 2x2 matrix.
     };
     unsigned short index;
     unsigned short flag;
     PositionType positionType;
-    // For PT_Offset: <deltaX, deltaY>
-    // For PT_Align:  <childPoint, parentPoint>
+      // For PT_Offset: <deltaX, deltaY>.
+      // For PT_Align: <childPoint, parentPoint>.
     std::pair<short, short> position;
     bool positionScaled;
     TransformationType transformationType;
-    // For TT_UniformScale: transformation[0] is the scale
-    // For TT_XYScale: transformation[0]: x-scale; transformation[1]: y-scale
-    // For TT_Matrix: transformation is layouted as
-    //                [xscale, scale01, scale10, yscale]
+      // For TT_UniformScale: `transformation[0]` is the scale.
+      // For TT_XYScale: `transformation[0]`: x-scale;
+      //                 `transformation[1]`: y-scale.
+      // For TT_Matrix: `transformation` has the layout
+      //                `[xscale, scale01, scale10, yscale]`.
     double transformation[4];
 
 
@@ -294,13 +302,13 @@ struct CompositeGlyphInfo
                const SubGlyph& rhs)
     {
       return lhs.index == rhs.index
-        && lhs.flag == rhs.flag
-        && lhs.positionType == rhs.positionType
-        && lhs.position == rhs.position
-        && lhs.positionScaled == rhs.positionScaled
-        && lhs.transformationType == rhs.transformationType
-        && !std::memcmp(lhs.transformation, rhs.transformation,
-                        4 * sizeof(double));
+             && lhs.flag == rhs.flag
+             && lhs.positionType == rhs.positionType
+             && lhs.position == rhs.position
+             && lhs.positionScaled == rhs.positionScaled
+             && lhs.transformationType == rhs.transformationType
+             && !std::memcmp(lhs.transformation, rhs.transformation,
+                             4 * sizeof(double));
     }
 
 
@@ -321,7 +329,8 @@ struct CompositeGlyphInfo
                      std::vector<SubGlyph> subglyphs)
   : index(index),
     subglyphs(std::move(subglyphs))
-  { }
+  {
+  }
 
 
   friend bool
@@ -329,7 +338,7 @@ struct CompositeGlyphInfo
              const CompositeGlyphInfo& rhs)
   {
     return lhs.index == rhs.index
-      && lhs.subglyphs == rhs.subglyphs;
+           && lhs.subglyphs == rhs.subglyphs;
   }
 
 
@@ -342,7 +351,8 @@ struct CompositeGlyphInfo
 
 
   // expensive
-  static void get(Engine* engine, std::vector<CompositeGlyphInfo>& list);
+  static void get(Engine* engine,
+                  std::vector<CompositeGlyphInfo>& list);
 };
 
 
diff --git a/src/ftinspect/engine/fontinfonamesmapping.cpp 
b/src/ftinspect/engine/fontinfonamesmapping.cpp
index e764ff0..af09b6c 100644
--- a/src/ftinspect/engine/fontinfonamesmapping.cpp
+++ b/src/ftinspect/engine/fontinfonamesmapping.cpp
@@ -5,8 +5,10 @@
 #include "fontinfo.hpp"
 
 #include <unordered_map>
+
 #include <freetype/ttnameid.h>
 
+
 #define FTI_UnknownID 0xFFFE
 
 // No more Qt containers since there's no any apparent advantage.
@@ -23,6 +25,7 @@ TableType ttEncodingAdobeNames;
 TableType ttLanguageMacNames;
 TableType ttLanguageWindowsNames;
 
+
 QString*
 mapSFNTNameIDToName(unsigned short nameID)
 {
@@ -62,13 +65,14 @@ mapSFNTNameIDToName(unsigned short nameID)
   return &it->second;
 }
 
+
 QString*
 mapTTPlatformIDToName(unsigned short platformID)
 {
   if (ttPlatformNames.empty())
   {
     ttPlatformNames[FTI_UnknownID] = "Unknown Platform";
-    // Unicode codepoints are encoded as UTF-16BE
+    // Unicode codepoints are encoded as UTF-16BE.
     ttPlatformNames[TT_PLATFORM_APPLE_UNICODE] = "Apple (Unicode)";
     ttPlatformNames[TT_PLATFORM_MACINTOSH] = "Macintosh";
     ttPlatformNames[TT_PLATFORM_ISO] = "ISO (deprecated)";
@@ -76,7 +80,7 @@ mapTTPlatformIDToName(unsigned short platformID)
     ttPlatformNames[TT_PLATFORM_CUSTOM] = "Custom";
     ttPlatformNames[TT_PLATFORM_ADOBE] = "Adobe";
   }
-  
+
   auto it = ttPlatformNames.find(platformID);
   if (it == ttPlatformNames.end())
     return &ttPlatformNames[FTI_UnknownID];
@@ -85,7 +89,7 @@ mapTTPlatformIDToName(unsigned short platformID)
 
 
 QString*
-mapTTEncodingIDToName(unsigned short platformID, 
+mapTTEncodingIDToName(unsigned short platformID,
                       unsigned short encodingID)
 {
   if (ttEncodingUnicodeNames.empty())
diff --git a/src/ftinspect/engine/mmgx.cpp b/src/ftinspect/engine/mmgx.cpp
index 570d55f..91ff944 100644
--- a/src/ftinspect/engine/mmgx.cpp
+++ b/src/ftinspect/engine/mmgx.cpp
@@ -2,9 +2,8 @@
 
 // Copyright (C) 2022 by Charlie Jiang.
 
-#include "mmgx.hpp"
-
 #include "engine.hpp"
+#include "mmgx.hpp"
 
 #include <freetype/ftmm.h>
 
@@ -29,7 +28,7 @@ MMGXAxisInfo::get(Engine* engine,
   FT_Multi_Master dummy;
   auto error = FT_Get_Multi_Master(face, &dummy);
   auto state = error ? MMGXState::GX_OVF : MMGXState::MM;
-  
+
   FT_MM_Var* mm;
   if (FT_Get_MM_Var(face, &mm))
   {
diff --git a/src/ftinspect/engine/mmgx.hpp b/src/ftinspect/engine/mmgx.hpp
index 6d5a3b0..71cb6b2 100644
--- a/src/ftinspect/engine/mmgx.hpp
+++ b/src/ftinspect/engine/mmgx.hpp
@@ -5,17 +5,20 @@
 #pragma once
 
 #include <vector>
+
 #include <QString>
 
+
 class Engine;
 
 enum class MMGXState
 {
   NoMMGX,
-  MM,     // Adobe MM
+  MM, // Adobe MM
   GX_OVF, // GX or OpenType variable fonts
 };
 
+
 struct MMGXAxisInfo
 {
   QString name;
@@ -28,7 +31,8 @@ struct MMGXAxisInfo
   bool hidden;
   bool isMM;
 
-  static MMGXState get(Engine* engine, std::vector<MMGXAxisInfo>& infos);
+  static MMGXState get(Engine* engine,
+                       std::vector<MMGXAxisInfo>& infos);
 
 
   friend bool
@@ -36,12 +40,12 @@ struct MMGXAxisInfo
              const MMGXAxisInfo& rhs)
   {
     return lhs.name == rhs.name
-      && lhs.tag == rhs.tag
-      && lhs.minimum == rhs.minimum
-      && lhs.maximum == rhs.maximum
-      && lhs.def == rhs.def
-      && lhs.hidden == rhs.hidden
-      && lhs.isMM == rhs.isMM;
+           && lhs.tag == rhs.tag
+           && lhs.minimum == rhs.minimum
+           && lhs.maximum == rhs.maximum
+           && lhs.def == rhs.def
+           && lhs.hidden == rhs.hidden
+           && lhs.isMM == rhs.isMM;
   }
 
 
diff --git a/src/ftinspect/engine/paletteinfo.cpp 
b/src/ftinspect/engine/paletteinfo.cpp
index 302f3f7..d85bb44 100644
--- a/src/ftinspect/engine/paletteinfo.cpp
+++ b/src/ftinspect/engine/paletteinfo.cpp
@@ -2,12 +2,12 @@
 
 // Copyright (C) 2022 by Charlie Jiang.
 
+#include "fontinfo.hpp"
 #include "paletteinfo.hpp"
 
-#include "fontinfo.hpp"
 
-PaletteInfo::PaletteInfo(FT_Face face, 
-                         FT_Palette_Data& data, 
+PaletteInfo::PaletteInfo(FT_Face face,
+                         FT_Palette_Data& data,
                          int index,
                          std::vector<SFNTName> const* sfntNames)
 : index(index)
diff --git a/src/ftinspect/engine/paletteinfo.hpp 
b/src/ftinspect/engine/paletteinfo.hpp
index 8d66df7..947a867 100644
--- a/src/ftinspect/engine/paletteinfo.hpp
+++ b/src/ftinspect/engine/paletteinfo.hpp
@@ -5,18 +5,23 @@
 #pragma once
 
 #include <vector>
+
 #include <QString>
 
 #include <freetype/freetype.h>
 #include <freetype/ftcolor.h>
 
+
 struct SFNTName;
+
 struct PaletteInfo
 {
   int index;
   QString name;
 
-  PaletteInfo(FT_Face face, FT_Palette_Data& data, int index, 
+  PaletteInfo(FT_Face face,
+              FT_Palette_Data& data,
+              int index,
               std::vector<SFNTName> const* sfntNames);
 };
 
diff --git a/src/ftinspect/engine/rendering.cpp 
b/src/ftinspect/engine/rendering.cpp
index 4fa28e3..bcdd550 100644
--- a/src/ftinspect/engine/rendering.cpp
+++ b/src/ftinspect/engine/rendering.cpp
@@ -2,15 +2,16 @@
 
 // Copyright (C) 2022 by Charlie Jiang.
 
+#include "engine.hpp"
 #include "rendering.hpp"
 
 #include <cmath>
-#include <QPixmap>
+
 #include <QPainter>
+#include <QPixmap>
 
 #include <freetype/ftbitmap.h>
 
-#include "engine.hpp"
 
 RenderingEngine::RenderingEngine(Engine* engine)
 : engine_(engine)
@@ -58,8 +59,9 @@ RenderingEngine::calculateForegroundTable()
   foregroundTable_.resize(256);
   auto gamma = gamma_;
 
-  // Yes I know this is horribly slow, but we're only calculating the table 
once
-  // and can use it for all rendering if the color and gamma isn't changing.
+  // Yes, I know this is horribly slow, but we are only calculating the table
+  // once and can use it for all rendering if color and gamma aren't
+  // changing.
 
   double br = std::pow(qRed(backgroundColor_) / 255.0, gamma);
   double bg = std::pow(qGreen(backgroundColor_) / 255.0, gamma);
@@ -82,18 +84,17 @@ RenderingEngine::calculateForegroundTable()
     g = std::pow(g, invGamma);
     b = std::pow(b, invGamma);
 
-    foregroundTable_[i]
-        = qRgba(static_cast<int>(r * 255), 
-                static_cast<int>(g * 255),
-                static_cast<int>(b * 255), 
-                255);
+    foregroundTable_[i] = qRgba(static_cast<int>(r * 255),
+                                static_cast<int>(g * 255),
+                                static_cast<int>(b * 255),
+                                255);
   }
 }
 
 
 bool
 RenderingEngine::convertGlyphToBitmapGlyph(FT_Glyph src,
-                      FT_Glyph* out)
+                                           FT_Glyph* out)
 {
   if (src->format == FT_GLYPH_FORMAT_BITMAP)
   {
@@ -101,6 +102,7 @@ RenderingEngine::convertGlyphToBitmapGlyph(FT_Glyph src,
     *out = src;
     return false;
   }
+
   if (src->format != FT_GLYPH_FORMAT_OUTLINE)
   {
     *out = NULL;
@@ -112,7 +114,7 @@ RenderingEngine::convertGlyphToBitmapGlyph(FT_Glyph src,
   {
     FT_Glyph out2 = src;
     // This will create a new glyph object.
-    auto error = FT_Glyph_To_Bitmap(&out2, 
+    auto error = FT_Glyph_To_Bitmap(&out2,
                                     engine_->renderMode(),
                                     nullptr,
                                     false);
@@ -135,7 +137,7 @@ RenderingEngine::convertBitmapTo8Bpp(FT_Bitmap* bitmap)
 {
   FT_Bitmap out;
   out.buffer = NULL;
-  // This will create a new bitmap object
+  // This will create a new bitmap object.
   auto error = FT_Bitmap_Convert(engine_->ftLibrary(), bitmap, &out, 1);
   if (error)
   {
@@ -163,16 +165,17 @@ QImage*
 RenderingEngine::convertBitmapToQImage(FT_Bitmap* src)
 {
   QImage* result = NULL;
-  
+
   auto& bmap = *src;
-  bool ownBitmap = false; // if true, we need to cleanup `bmap`
+  bool ownBitmap = false; // If true, we need to clean up `bmap`.
 
-  int width = INT_MAX, height = INT_MAX;
+  int width = INT_MAX;
+  int height = INT_MAX;
   if (bmap.width < INT_MAX)
     width = static_cast<int>(bmap.width);
   if (bmap.rows < INT_MAX)
     height = static_cast<int>(bmap.rows);
-  auto format = QImage::Format_Indexed8; // goto crossing init
+  auto format = QImage::Format_Indexed8; // Go to crossing init.
 
   if (bmap.pixel_mode == FT_PIXEL_MODE_GRAY2
       || bmap.pixel_mode == FT_PIXEL_MODE_GRAY4)
@@ -198,7 +201,7 @@ RenderingEngine::convertBitmapToQImage(FT_Bitmap* src)
     break;
   case FT_PIXEL_MODE_BGRA:
     // XXX "ARGB" here means BGRA due to endianness - may be problematic
-    // on big-endian machines
+    //     on big-endian machines
     format = QImage::Format_ARGB32_Premultiplied;
     break;
   case FT_PIXEL_MODE_LCD:
@@ -209,15 +212,15 @@ RenderingEngine::convertBitmapToQImage(FT_Bitmap* src)
     goto cleanup;
   }
 
-  switch (bmap.pixel_mode) 
+  switch (bmap.pixel_mode)
   {
   case FT_PIXEL_MODE_MONO:
   case FT_PIXEL_MODE_GRAY:
   case FT_PIXEL_MODE_BGRA:
     {
-      QImage image(bmap.buffer, 
-                   width, height, 
-                   bmap.pitch, 
+      QImage image(bmap.buffer,
+                   width, height,
+                   bmap.pitch,
                    format);
       if (bmap.pixel_mode == FT_PIXEL_MODE_GRAY)
         image.setColorTable(foregroundTable_);
@@ -228,7 +231,7 @@ RenderingEngine::convertBitmapToQImage(FT_Bitmap* src)
         image.setColor(1, foregroundTable_[0xFF]);
       }
       result = new QImage(image.copy());
-      // Don't directly use `image` since we're destroying the `bmap`
+      // Don't directly use `image` since we are destroying `bmap`.
     }
     break;
   case FT_PIXEL_MODE_LCD:;
@@ -251,12 +254,13 @@ cleanup:
 
 QImage*
 RenderingEngine::convertGlyphToQImage(FT_Glyph src,
-                             QRect* outRect,
-                             bool inverseRectY)
+                                      QRect* outRect,
+                                      bool inverseRectY)
 {
   FT_BitmapGlyph bitmapGlyph;
   bool ownBitmapGlyph
-    = convertGlyphToBitmapGlyph(src, 
reinterpret_cast<FT_Glyph*>(&bitmapGlyph));
+    = convertGlyphToBitmapGlyph(src,
+                                reinterpret_cast<FT_Glyph*>(&bitmapGlyph));
   if (!bitmapGlyph)
     return NULL;
 
@@ -288,12 +292,13 @@ RenderingEngine::convertGlyphToQImage(FT_Glyph src,
 
 
 QPoint
-RenderingEngine::computeGlyphOffset(FT_Glyph glyph, bool inverseY)
+RenderingEngine::computeGlyphOffset(FT_Glyph glyph,
+                                    bool inverseY)
 {
   if (glyph->format == FT_GLYPH_FORMAT_OUTLINE)
   {
     FT_BBox cbox;
-    FT_Outline_Get_CBox(&reinterpret_cast<FT_OutlineGlyph>(glyph)->outline, 
+    FT_Outline_Get_CBox(&reinterpret_cast<FT_OutlineGlyph>(glyph)->outline,
                         &cbox);
     cbox.xMin &= ~63;
     cbox.yMin &= ~63;
@@ -318,19 +323,19 @@ RenderingEngine::computeGlyphOffset(FT_Glyph glyph, bool 
inverseY)
 
 QImage*
 RenderingEngine::tryDirectRenderColorLayers(int glyphIndex,
-                                   QRect* outRect,
-                                   bool inverseRectY)
+                                            QRect* outRect,
+                                            bool inverseRectY)
 {
   auto& paletteData = engine_->currentFontPaletteData();
   auto paletteIndex = engine_->paletteIndex();
   auto palette = engine_->currentPalette();
-  if (palette == NULL 
-      || !engine_->useColorLayer() 
+  if (palette == NULL
+      || !engine_->useColorLayer()
       || paletteIndex >= paletteData.num_palettes)
     return NULL;
 
   FT_LayerIterator iter = {};
-  
+
   FT_UInt layerGlyphIdx = 0;
   FT_UInt layerColorIdx = 0;
 
@@ -342,7 +347,7 @@ RenderingEngine::tryDirectRenderColorLayers(int glyphIndex,
   if (!next)
     return NULL;
 
-  // temporarily change lf
+  // Temporarily change load flags.
   auto imageType = engine_->imageType();
   auto oldLoadFlags = imageType->flags;
   auto loadFlags = oldLoadFlags;
@@ -387,7 +392,7 @@ RenderingEngine::tryDirectRenderColorLayers(int glyphIndex,
     {
       // TODO: FT_Palette_Get_Foreground_Color: #1134
       if (paletteData.palette_flags
-          && (paletteData.palette_flags[paletteIndex] 
+          && (paletteData.palette_flags[paletteIndex]
               & FT_PALETTE_FOR_DARK_BACKGROUND))
       {
         /* white opaque */
@@ -450,7 +455,8 @@ RenderingEngine::tryDirectRenderColorLayers(int glyphIndex,
 
 
 QPixmap
-RenderingEngine::padToSize(QImage* image, int ppem)
+RenderingEngine::padToSize(QImage* image,
+                           int ppem)
 {
   auto width = std::max(image->width(), ppem);
   auto height = std::max(image->height(), ppem);
@@ -494,7 +500,7 @@ convertLCDToARGB(FT_Bitmap& bitmap,
       dstPtr++;
     }
     srcPtr += bitmap.pitch;
-    dstPtr += image.bytesPerLine() / 4 - width; // skip blank area
+    dstPtr += image.bytesPerLine() / 4 - width; // Skip blank area.
   }
 }
 
@@ -528,8 +534,8 @@ convertLCDVToARGB(FT_Bitmap& bitmap,
       *dstPtr = (0xFFu << 24) | (dr << 16) | (dg << 8) | db;
       dstPtr++;
     }
-    srcPtr += 3ull * srcPitch;                  // move 3 lines
-    dstPtr += image.bytesPerLine() / 4 - width; // skip blank area
+    srcPtr += 3ull * srcPitch; // Move 3 lines.
+    dstPtr += image.bytesPerLine() / 4 - width; // Skip blank area.
   }
 }
 
diff --git a/src/ftinspect/engine/rendering.hpp 
b/src/ftinspect/engine/rendering.hpp
index 73545ee..b918bda 100644
--- a/src/ftinspect/engine/rendering.hpp
+++ b/src/ftinspect/engine/rendering.hpp
@@ -6,10 +6,13 @@
 
 #include <QColor>
 #include <QImage>
+
 #include <freetype/freetype.h>
 #include <freetype/ftglyph.h>
 
+
 class Engine;
+
 class RenderingEngine
 {
 public:
@@ -25,30 +28,29 @@ public:
   QRgb background() { return backgroundColor_; }
   double gamma() { return gamma_; }
 
-  // Return `true` if you need to free `out`
-  // `out` will be set to NULL in cases of error
-  bool convertGlyphToBitmapGlyph(FT_Glyph src, FT_Glyph* out);
+  // Return `true` if you need to free `out`.
+  // `out` will be set to NULL in case of error.
+  bool convertGlyphToBitmapGlyph(FT_Glyph src,
+                                 FT_Glyph* out);
   FT_Bitmap convertBitmapTo8Bpp(FT_Bitmap* bitmap);
   QImage* convertBitmapToQImage(FT_Bitmap* src);
-  QImage* convertGlyphToQImage(FT_Glyph src, 
+  QImage* convertGlyphToQImage(FT_Glyph src,
                                QRect* outRect,
                                bool inverseRectY);
-  QPoint computeGlyphOffset(FT_Glyph glyph, bool inverseY);
-
-  /*
-   * Directly render the glyph at the specified index
-   * to a `QImage`. If you want to perform color-layer
-   * rendering, call this before trying to load the
-   * glyph and do normal rendering, If the returning
-   * value is non-NULL, then there's no need to
-   * load the glyph the normal way, just draw the `QImage`.
-   * Will return NULL if not enabled or color layers not available.
-   */
+  QPoint computeGlyphOffset(FT_Glyph glyph,
+                            bool inverseY);
+
+  // Directly render the glyph at the specified index to a `QImage`.  If you
+  // want to perform color-layer rendering, call this before trying to load
+  // the glyph and do normal rendering.  If the return value is non-NULL
+  // there is no need to load the glyph the normal way, just draw the
+  // `QImage`.  Return NULL if not enabled or color layers not available.
   QImage* tryDirectRenderColorLayers(int glyphIndex,
                                      QRect* outRect,
                                      bool inverseRectY = false);
 
-  QPixmap padToSize(QImage* image, int ppem);
+  QPixmap padToSize(QImage* image,
+                    int ppem);
 
 private:
   Engine* engine_;
diff --git a/src/ftinspect/engine/stringrenderer.cpp 
b/src/ftinspect/engine/stringrenderer.cpp
index 20fa666..b5d0196 100644
--- a/src/ftinspect/engine/stringrenderer.cpp
+++ b/src/ftinspect/engine/stringrenderer.cpp
@@ -2,11 +2,11 @@
 
 // Copyright (C) 2022 by Charlie Jiang.
 
-#include "stringrenderer.hpp"
-
 #include "engine.hpp"
+#include "stringrenderer.hpp"
 
 #include <cmath>
+
 #include <QTextCodec>
 
 
@@ -83,7 +83,7 @@ StringRenderer::setKerning(bool kerning)
 void
 StringRenderer::reloadAll()
 {
-  clearActive(usingString_); // if "All Glyphs", then do a complete wipe
+  clearActive(usingString_); // If 'All Glyphs', do a complete wipe.
   if (usingString_)
     reloadGlyphIndices();
 }
@@ -99,7 +99,7 @@ StringRenderer::reloadGlyphs()
 void
 StringRenderer::setUseString(QString const& string)
 {
-  clearActive(); // clear existing
+  clearActive(); // Clear existing data.
   usingString_ = true;
 
   long long totalCount = 0;
@@ -110,7 +110,7 @@ StringRenderer::setUseString(QString const& string)
     it.charCodeUcs4 = it.charCode = static_cast<int>(ch);
     it.glyphIndex = 0;
     ++totalCount;
-    if (totalCount >= INT_MAX) // Prevent overflow
+    if (totalCount >= INT_MAX) // Prevent overflow.
       break;
   }
   reloadGlyphIndices();
@@ -180,11 +180,11 @@ StringRenderer::loadSingleContext(GlyphContext* ctx,
     ctx->cacheNode = NULL;
   }
   else if (ctx->glyph)
-    FT_Done_Glyph(ctx->glyph); // when caching isn't used
+    FT_Done_Glyph(ctx->glyph); // When caching isn't used.
 
   // TODO use FTC?
 
-  // After `prepareRendering`, current size/face is properly set
+  // After `prepareRendering`, current size/face is properly set.
   FT_GlyphSlot slot = engine_->currentFaceSlot();
   if (engine_->loadGlyphIntoSlotWithoutCache(ctx->glyphIndex) != 0)
   {
@@ -197,8 +197,8 @@ StringRenderer::loadSingleContext(GlyphContext* ctx,
     return;
   }
   auto& metrics = slot->metrics;
-  //ctx->glyph = engine_->loadGlyphWithoutUpdate(ctx->glyphIndex, 
-  //                                            &ctx->cacheNode);
+  //ctx->glyph = engine_->loadGlyphWithoutUpdate(ctx->glyphIndex,
+  //                                             &ctx->cacheNode);
 
   if (!ctx->glyph)
     return;
@@ -221,8 +221,8 @@ StringRenderer::loadSingleContext(GlyphContext* ctx,
 
   if (kerningMode_ != KM_None)
   {
-    FT_Vector kern = engine_->currentFontKerning(ctx->glyphIndex, 
-                                        prev->glyphIndex);
+    FT_Vector kern = engine_->currentFontKerning(ctx->glyphIndex,
+                                                 prev->glyphIndex);
 
     prev->hadvance.x += kern.x;
     prev->hadvance.y += kern.y;
@@ -274,15 +274,14 @@ StringRenderer::prepareLine(int offset,
   outActualLineWidth = {0, 0};
   if (!usingString_) // All glyphs
   {
-    // The thing gets a little complicated when we're using "All Glyphs" mode
-    // The input sequence is actually infinite
-    // so we have to combine loading glyph into rendering, and can't preload
-    // all glyphs
+    // The situation gets a little complicated when we are using the 'All
+    // Glyphs' mode: The input sequence is actually infinite so we have to
+    // combine loading glyph into rendering and can't preload all glyphs.
 
     // TODO: Low performance when the begin index is large.
     // TODO: Optimize: use a sparse vector...!
     // The problem is that when doing a `list::resize`, the ctor is called
-    // for unnecessarily many times.
+    // unnecessarily often.
     tempGlyphContext_ = {};
     for (unsigned n = offset; n < static_cast<unsigned>(limitIndex_);)
     {
@@ -294,14 +293,15 @@ StringRenderer::prepareLine(int offset,
       auto& ctx = activeGlyphs_[n];
       ctx.charCode = static_cast<int>(n);
       ctx.glyphIndex = static_cast<int>(
-          engine_->glyphIndexFromCharCode(static_cast<int>(n), charMapIndex_));
+                         engine_->glyphIndexFromCharCode(static_cast<int>(n),
+                                                         charMapIndex_));
 
       auto prev = n == 0 ? &tempGlyphContext_ : &activeGlyphs_[n - 1];
       if (!ctx.glyph)
         loadSingleContext(&ctx, prev);
 
-      // In All Glyphs mode, a red placeholder should be drawn for non-spacing
-      // glyphs (e.g. the stress mark)
+      // In 'All Glyphs' mode, a red placeholder should be drawn for
+      // non-spacing glyphs (e.g., the stress mark).
       auto actualAdvanceX = ctx.hadvance.x ? ctx.hadvance.x
                                            : nonSpacingPlaceholder << 6;
       if (outActualLineWidth.x + actualAdvanceX > lineWidth)
@@ -330,7 +330,8 @@ StringRenderer::prepareLine(int offset,
         break;
       }
 
-      if (repeated_) // if repeated, we must stop when we touch the end of line
+      if (repeated_) // If repeated, we must stop when we touch
+                     // the end of the line
       {
         if (outActualLineWidth.x + ctx.hadvance.x > lineWidth)
           break;
@@ -374,14 +375,14 @@ StringRenderer::render(int width,
 
   auto initialOffset = offset;
 
-  // Separated into 3 modes:
-  // Waterfall, fill the whole canvas and only single string.
+  // Separate into 3 modes: Waterfall, fill the whole canvas, and render a
+  // single string only.
   if (waterfall_)
   {
     // Waterfall
 
     vertical_ = false;
-    // They're only effective for non-bitmap-only (scalable) fonts!
+    // They are only effective for non-bitmap-only (scalable) fonts!
     auto originalSize = static_cast<int>(engine_->pointSize() * 64);
     auto ptSize = originalSize;
     auto ptHeight = 64 * 72 * height / engine_->dpi();
@@ -402,8 +403,8 @@ StringRenderer::render(int width,
     else if (!bitmapOnly)
     {
       ptSize = static_cast<int>(waterfallStart_ * 64.0) & ~31;
-      // we first get a ratio since height & ppem are near proportional...
-      // 64.0 is somewhat a magic reference number
+      // We first get a ratio since height & ppem are near proportional...
+      // Value 64.0 is somewhat a magic reference number.
       engine_->setSizeByPoint(64.0);
       engine_->reloadFont();
       if (!engine_->renderReady())
@@ -417,16 +418,17 @@ StringRenderer::render(int width,
 
       auto n = heightPt * 2 / (waterfallStart_ + waterfallEnd_);
       auto stepTemp = (waterfallEnd_ - waterfallStart_) / (n + 1);
-      // rounding to 0.25
+      // Rounding to 0.25.
       step = static_cast<int>(std::round(stepTemp * 4)) * 16 & ~15;
       if (step == 0)
-        step = 16; // 0.25 pt
+        step = 16; // 0.25pt
     }
 
     int y = 0;
-    // no position param in "All Glyphs" or repeated mode
-    int x = static_cast<int>((usingString_ && !repeated_) ? (width * position_)
-                                                          : 0);
+    // No position parameter in 'All Glyphs' or repeated mode.
+    int x = static_cast<int>((usingString_ && !repeated_)
+              ? (width * position_)
+              : 0);
     int count = 0;
 
     while (true)
@@ -440,16 +442,18 @@ StringRenderer::render(int width,
         engine_->setSizeByPixel(*fixedSizesIter);
       }
       clearActive(true);
-      prepareRendering(); // set size/face for engine, so metrics are valid
+      prepareRendering(); // Set size/face for engine to have valid metrics.
       auto& metrics = engine_->currentFontMetrics();
-      
+
       y += static_cast<int>(metrics.height >> 6) + 1;
       if (y >= height && !bitmapOnly)
         break;
 
       loadStringGlyphs();
-      auto lcount = renderLine(x, y + static_cast<int>(metrics.descender >> 6),
-                               width, height,
+      auto lcount = renderLine(x,
+                               y + static_cast<int>(metrics.descender >> 6),
+                               width,
+                               height,
                                offset);
       count = std::max(count, lcount);
 
@@ -470,7 +474,7 @@ StringRenderer::render(int width,
 
   if (repeated_ || !usingString_)
   {
-    // Fill the whole canvas (string repeated or all glyphs)
+    // Fill the whole canvas (string repeated or all glyphs).
 
     prepareRendering();
     if (!engine_->renderReady())
@@ -480,27 +484,27 @@ StringRenderer::render(int width,
     auto stepY = static_cast<int>(metrics.height >> 6) + 1;
     auto limitY = height + static_cast<int>(metrics.descender >> 6);
 
-    // Only care about multiline when in string mode
+    // Only care about multi-line rendering when in string mode.
     for (; y < limitY; y += stepY)
     {
       offset = renderLine(0, y, width, height, offset, usingString_);
-      // For repeating
+      // For repeating.
       if (usingString_ && repeated_ && !activeGlyphs_.empty())
         offset %= static_cast<int>(activeGlyphs_.size());
     }
-    if (!usingString_) // only return count for All Glyphs mode.
+    if (!usingString_) // Only return count for 'All Glyphs' mode.
       return offset - initialOffset;
     return 0;
   }
 
-  // Single string
+  // single string
   prepareRendering();
   if (!engine_->renderReady())
     return 0;
 
   auto& metrics = engine_->currentFontMetrics();
   auto x = static_cast<int>(width * position_);
-  // Anchor at top-left in vertical mode, at the center in horizontal mode
+  // Anchor at top-left in vertical mode, at the center in horizontal mode.
   auto y = vertical_ ? 0 : (height / 2);
   auto stepY = static_cast<int>(metrics.height >> 6) + 1;
   y += 4 + static_cast<int>(metrics.ascender >> 6);
@@ -509,7 +513,7 @@ StringRenderer::render(int width,
   while (offset < static_cast<int>(activeGlyphs_.size()))
   {
     offset = renderLine(x, y, width, height, offset, true);
-    if (offset == lastOffset) // prevent inf loop.
+    if (offset == lastOffset) // Prevent infinite loop.
       break;
     lastOffset = offset;
     y += stepY;
@@ -526,27 +530,27 @@ StringRenderer::renderLine(int x,
                            int offset,
                            bool handleMultiLine)
 {
-  // Don't limit the x y to be within the canvas viewport: string can be moved
-  // by the mouse
+  // Don't limit (x, y) to be within the canvas viewport: the string can be
+  // moved by the mouse.
 
-  y = height - y; // change to Cartesian coordinates
+  y = height - y; // Change to Cartesian coordinates.
 
   FT_Vector pen = { 0, 0 };
   FT_Vector advance;
   auto nonSpacingPlaceholder = engine_->currentFontMetrics().y_ppem / 2 + 2;
 
-  // When in "All Glyphs"  mode, no vertical support.
+  // When in 'All Glyphs' mode, no vertical support.
   if (repeated_ || !usingString_)
     vertical_ = false; // TODO: Support vertical + repeated
 
   int lineLength = 64 * (vertical_ ? height : width);
 
-  // first prepare the line & determine the line length
-  int totalCount = prepareLine(offset, lineLength, pen, 
+  // First prepare the line & determine the line length.
+  int totalCount = prepareLine(offset, lineLength, pen,
                                nonSpacingPlaceholder, handleMultiLine);
 
-  // round to control initial pen position and preserve hinting...
-  // pen.x, y is the actual length now, and we multiple it by pos
+  // Round to control initial pen position and preserve hinting...
+  // (pen.x, y) is the actual length now, and we multiple it by position.
   auto centerFixed = static_cast<int>(0x10000 * position_);
   if (!usingString_ || repeated_)
     centerFixed = 0;
@@ -561,8 +565,8 @@ StringRenderer::renderLine(int x,
   pen.x = (x << 6) - pen.x;
   pen.y = (y << 6) - pen.y;
 
-  // Need to transform the coord back to normal coord system
-  lineBeginCallback_({ (pen.x >> 6), 
+  // Need to transform the coordinates back to normal coordinate system.
+  lineBeginCallback_({ (pen.x >> 6),
                        height - (pen.y >> 6) },
                      engine_->pointSize());
 
@@ -570,8 +574,8 @@ StringRenderer::renderLine(int x,
   {
     auto& ctx = activeGlyphs_[i % activeGlyphs_.size()];
     if (handleMultiLine && ctx.charCode == '\n')
-      continue; // skip \n
-    FT_Glyph image = NULL; // Remember to clean up
+      continue; // Skip \n.
+    FT_Glyph image = NULL; // Remember to clean up.
     FT_BBox bbox;
 
     if (!ctx.glyph)
@@ -582,7 +586,8 @@ StringRenderer::renderLine(int x,
     QRect rect;
     QImage* colorLayerImage
       = engine_->renderingEngine()->tryDirectRenderColorLayers(ctx.glyphIndex,
-                                                               &rect, true);
+                                                               &rect,
+                                                               true);
 
     if (colorLayerImage)
     {
@@ -591,7 +596,7 @@ StringRenderer::renderLine(int x,
     }
     else
     {
-      // copy the glyph because we're doing manipulation
+      // Copy the glyph because we're doing manipulation.
       auto error = FT_Glyph_Copy(ctx.glyph, &image);
       if (error)
         continue;
@@ -619,7 +624,7 @@ StringRenderer::renderLine(int x,
       {
         auto bitmap = reinterpret_cast<FT_BitmapGlyph>(image);
 
-         if (vertical_)
+        if (vertical_)
         {
            bitmap->left += static_cast<int>(ctx.vvector.x) >> 6;
            bitmap->top += static_cast<int>(ctx.vvector.y) >> 6;
@@ -637,11 +642,11 @@ StringRenderer::renderLine(int x,
 
       FT_Done_Glyph(image);
     }
-    
+
     pen.x += advance.x;
     pen.y += advance.y;
 
-    if (!advance.x && !usingString_) // add placeholder
+    if (!advance.x && !usingString_) // Add placeholder.
       pen.x += nonSpacingPlaceholder << 6;
   }
 
@@ -657,7 +662,7 @@ StringRenderer::clearActive(bool glyphOnly)
     if (ctx.cacheNode)
       FTC_Node_Unref(ctx.cacheNode, engine_->cacheManager());
     else if (ctx.glyph)
-      FT_Done_Glyph(ctx.glyph); // when caching isn't used
+      FT_Done_Glyph(ctx.glyph); // When caching isn't used.
     ctx.cacheNode = NULL;
     ctx.glyph = NULL;
   }
@@ -669,7 +674,8 @@ StringRenderer::clearActive(bool glyphOnly)
 
 
 int
-StringRenderer::convertCharEncoding(int charUcs4, FT_Encoding encoding)
+StringRenderer::convertCharEncoding(int charUcs4,
+                                    FT_Encoding encoding)
 {
   switch (encoding)
   {
@@ -680,7 +686,8 @@ StringRenderer::convertCharEncoding(int charUcs4, 
FT_Encoding encoding)
   case FT_ENCODING_ADOBE_CUSTOM:
   case FT_ENCODING_ADOBE_LATIN_1:
     return charUcs4;
-  default:; // proceed
+  default:
+    ; // Proceed.
   }
 
   auto mib = -1;
@@ -696,7 +703,7 @@ StringRenderer::convertCharEncoding(int charUcs4, 
FT_Encoding encoding)
     mib = 2026; // Big5
     break;
   case FT_ENCODING_WANSUNG:
-    mib = -949; // KS C 5601:1987, this is a fake mib value
+    mib = -949; // KS C 5601:1987, this is a fake mib value.
     break;
   case FT_ENCODING_JOHAB:
     mib = 38; //  KS C 5601:1992 / EUC-KR
@@ -705,17 +712,17 @@ StringRenderer::convertCharEncoding(int charUcs4, 
FT_Encoding encoding)
     mib = 2027;
     break;
   default:
-    return charUcs4; // Failed
+    return charUcs4; // Failed.
   }
 
   if (mib == -1)
-    return charUcs4; // unsupported charmap
+    return charUcs4; // Unsupported charmap.
   auto codec = QTextCodec::codecForMib(mib);
   if (!codec)
-    return charUcs4; // unsupported
+    return charUcs4; // Unsupported.
 
   auto res = codec->fromUnicode(
-      QString::fromUcs4(reinterpret_cast<uint*>(&charUcs4), 1));
+               QString::fromUcs4(reinterpret_cast<uint*>(&charUcs4), 1));
   if (res.size() == 0)
     return charUcs4;
   if (res.size() == 1)
diff --git a/src/ftinspect/engine/stringrenderer.hpp 
b/src/ftinspect/engine/stringrenderer.hpp
index d8aa323..844f81c 100644
--- a/src/ftinspect/engine/stringrenderer.hpp
+++ b/src/ftinspect/engine/stringrenderer.hpp
@@ -4,13 +4,13 @@
 
 #pragma once
 
-#include <vector>
 #include <functional>
+#include <vector>
 
 #include <QString>
+#include <qslider.h>
 
 #include <ft2build.h>
-#include <qslider.h>
 #include <freetype/freetype.h>
 #include <freetype/ftcache.h>
 #include <freetype/ftglyph.h>
@@ -18,6 +18,7 @@
 // adopted from `ftcommon.h`
 
 class Engine;
+
 struct GlyphContext
 {
   int charCode = 0;
@@ -26,17 +27,18 @@ struct GlyphContext
   FT_Glyph glyph = NULL;
   FTC_Node cacheNode = NULL;
 
-  FT_Pos lsbDelta = 0;    // delta caused by hinting
-  FT_Pos rsbDelta = 0;   // delta caused by hinting
-  FT_Vector hadvance = { 0, 0 }; // kerned horizontal advance
+  FT_Pos lsbDelta = 0; // Delta caused by hinting.
+  FT_Pos rsbDelta = 0; // Delta caused by hinting.
 
-  FT_Vector vvector = { 0, 0 };  // vert. origin => hori. origin
-  FT_Vector vadvance = { 0, 0 }; // vertical advance
+  FT_Vector hadvance = { 0, 0 }; // Kerned horizontal advance.
+  FT_Vector vvector = { 0, 0 };  // Vertical origin to horizontal origin.
+  FT_Vector vadvance = { 0, 0 }; // Vertical advance.
 };
 
-// Class to populate chars to render, to load and properly position glyphs.
-// Use callbacks to receive characters and lines. You should save the result
-// from the callbacks to a cache.
+
+// Class to populate characters to render, to load and properly position
+// glyphs.  Use callbacks to receive characters and lines.  You should save
+// the result from the callbacks to a cache.
 class StringRenderer
 {
 public:
@@ -58,52 +60,50 @@ public:
     KM_Smart
   };
 
-  /*
-   * Called when outputting a glyph. The receiver is reponsible for rendering
-   * the glyph to bitmap.
-   *
-   * Need to pass the pen position because sometimes the outline vector
-   * contains no points, and thus can't be translated to the desired pen
-   * position.
-   */
-  using RenderCallback = std::function<void(FT_Glyph,        // glyph
-                                            FT_Vector,       // penPos
+  // Called when outputting a glyph.  The receiver is reponsible for
+  // rendering the glyph to bitmap.
+  //
+  // We need to pass the pen position because sometimes the outline vector
+  // contains no points and thus can't be translated to the desired pen
+  // position.
+  using RenderCallback = std::function<void(FT_Glyph, // glyph
+                                            FT_Vector, // penPos
                                             GlyphContext&)>;
-  /*
-   * Called when outputtng a glyph with bitmap pre-rendered.
-   * The receiver can simply use the bitmap, mainly for color layered fonts.
-   * 
-   * TODO: Remove `RenderCallback` and do QImage creation in this class?
-   * The receiver is responsible for deleteing the `QImage`
-   * (ownership transfered).
-   */
-  using RenderImageCallback = std::function<void(QImage*,   // bitmap
-                                                 QRect,     // bbox
+
+  // Called when outputting a glyph with a pre-rendered bitmap.  The
+  // receiver can simply use the bitmap, mainly for color layered fonts.
+  //
+  // TODO: Remove `RenderCallback` and do QImage creation in this class?
+  //
+  // The receiver is responsible for deleteing the `QImage` (ownership
+  // transfered).
+  using RenderImageCallback = std::function<void(QImage*, // bitmap
+                                                 QRect, // bbox
                                                  FT_Vector, // penPos
                                                  FT_Vector, // advance
                                                  GlyphContext&)>;
-  /*
-   * Called right after the glyph is obtained from the font, before any other
-   * operation is done. The receiver can do pre-processing like slanting and
-   * emboldening in this function.
-   *
-   * The glyph pointer may be replaced. In that case, ownership is transfered
-   * to the renderer, and the new glyph will be eventually freed by
-   * the renderer. The callback is responsible to free the old glyph.
-   * This allows you to do the following:
-   * void callback(FT_Glyph* ptr) {
-   *     ....
-   *     auto oldPtr = *ptr;
-   *     *ptr = ....;
-   *     FT_Done_Glyph(olPtr);
-   * }
-   */
+
+  // Called right after the glyph is obtained from the font, before any
+  // other operation is done.  The receiver can do pre-processing like
+  // slanting and emboldening in this function.
+  //
+  // The glyph pointer may be replaced.  In that case, ownership is
+  // transfered to the renderer, and the new glyph will be eventually freed
+  // by the renderer.  The callback is responsible to free the old glyph.
+  // This allows you to do the following:
+  //
+  //   void callback(FT_Glyph* ptr)
+  //   {
+  //     ...
+  //     auto oldPtr = *ptr;
+  //     *ptr = ...;
+  //     FT_Done_Glyph(oldPtr);
+  //   }
   using PreprocessCallback = std::function<void(FT_Glyph*)>;
-  /*
-   * Called when a new line begins.
-   */
+
+  // Called when a new line begins.
   using LineBeginCallback = std::function<void(FT_Vector, // initial penPos
-                                               double)>;  // size (points)
+                                               double)>; // size (points)
 
   //////// Getters
   bool isWaterfall() { return waterfall_; }
@@ -111,34 +111,24 @@ public:
   int charMapIndex() { return charMapIndex_; }
 
   //////// Callbacks
-  void
-  setCallback(RenderCallback cb)
-  {
-    renderCallback_ = std::move(cb);
-  }
-  void
-  setImageCallback(RenderImageCallback cb)
-  {
-    renderImageCallback_ = std::move(cb);
-  }
-  void
-  setPreprocessCallback(PreprocessCallback cb)
-  {
-    glyphPreprocessCallback_ = std::move(cb);
-  }
-  void
-  setLineBeginCallback(LineBeginCallback cb)
-  {
-    lineBeginCallback_ = std::move(cb);
-  }
+  void setCallback(RenderCallback cb)
+         { renderCallback_ = std::move(cb); }
+  void setImageCallback(RenderImageCallback cb)
+         { renderImageCallback_ = std::move(cb); }
+  void setPreprocessCallback(PreprocessCallback cb)
+         { glyphPreprocessCallback_ = std::move(cb); }
+  void setLineBeginCallback(LineBeginCallback cb)
+         { lineBeginCallback_ = std::move(cb); }
 
   //////// Setters for options
-  void setCharMapIndex(int charMapIndex, int limitIndex);
+  void setCharMapIndex(int charMapIndex,
+                       int limitIndex);
   void setRepeated(bool repeated) { repeated_ = repeated; }
   void setVertical(bool vertical) { vertical_ = vertical; }
   void setRotation(double rotation);
   void setWaterfall(bool waterfall) { waterfall_ = waterfall; }
-  void setWaterfallParameters(double start, double end)
+  void setWaterfallParameters(double start,
+                              double end)
   {
     waterfallStart_ = start;
     waterfallEnd_ = end;
@@ -147,7 +137,7 @@ public:
   void setLsbRsbDelta(bool enabled) { lsbRsbDeltaEnabled_ = enabled; }
   void setKerning(bool kerning);
 
-  // Need to be called when font or charMap changes
+  // Need to be called when font or charMap changes.
   void setUseString(QString const& string);
   void setUseAllGlyphs();
 
@@ -155,46 +145,51 @@ public:
   int render(int width,
              int height,
              int offset);
-  int renderLine(int x, int y,
-                 int width, int height,
+  int renderLine(int x,
+                 int y,
+                 int width,
+                 int height,
                  int offset,
                  bool handleMultiLine = false);
 
-  void reloadAll();      // text/font/charmap changes, will call
-                         // `reloadGlyphs`
-  void reloadGlyphs();   // any other parameter changes
+  void reloadAll(); // Text/font/charmap changes, will call `reloadGlyphs`.
+  void reloadGlyphs(); // Any other parameter changes.
 
 private:
   Engine* engine_;
 
   // Generally, rendering has those steps:
+  //
   // 1. If in string mode, the string is load into `activeGlyphs_`
-  //    (in `updateString`)
-  // 2. The char codes in contexts are converted to glyph indices
-  //    (in `reloadGlyphIndices`)
-  // 3. If in string mode, glyphs are loaded into contexts.
-  //    (in `loadStringGlyphs`)
+  //    (in `updateString`).
+  // 2. The character codes in contexts are converted to glyph indices
+  //    (in `reloadGlyphIndices`).
+  // 3. If in string mode, glyphs are loaded into contexts
+  //    (in `loadStringGlyphs`).
   // 4. In `render` function, according to mode, `renderLine` is called line
   //    by line (as well as `prepareRendering`).
   // 5. In `renderLine`, if in all glyphs mode, glyphs from the begin index
-  //    are loaded until the line is full (if the glyph already exists, it will
-  //    be reused). If in string mode, it will directly use the prepared 
glyphs.
-  //    Preprocessing is done within this step, such as emboldening or 
stroking.
-  //    Eventually the `FT_Glyph` pointer is passed to the callback.
-  
+  //    are loaded until the line is full (if the glyph already exists, it
+  //    will be reused).  If in string mode, it will directly use the
+  //    prepared glyphs.  Preprocessing is done within this step, such as
+  //    emboldening or stroking.  Eventually the `FT_Glyph` pointer is
+  //    passed to the callback.
+
   GlyphContext tempGlyphContext_;
-  // This vector stores all active glyphs for rendering. When rendering 
strings,
-  // this is the container for chars, so DO NOT directly clear it to flush
-  // cache, you should clean glyph objects only. However when rendering all
-  // glyphs, it's generally to directly wipe the vector because it's 
dynamically
-  // generated in `render` function (see above).
+
+  // This vector stores all active glyphs for rendering.  When rendering
+  // strings, this is the container for characters, so DO NOT directly clear
+  // it to flush the cache!  You should clean glyph objects only.  However,
+  // when rendering all glyphs, it's generally better to directly wipe the
+  // vector because it is dynamically generated in `render` function (see
+  // above).
   //
   // Note: Because of kerning, this list must be ordered and allow duplicate
   //       characters.
   //
-  // Actually this means 3 parts of storage: string charcode, glyph indices and
-  // glyph (+ all related info). Different parameter changes will trigger
-  // different levels of flushing.
+  // Actually this means 3 parts of storage: string character code, glyph
+  // indices, and glyph (+ all related info).  Different parameter changes
+  // will trigger different levels of flushing.
   std::vector<GlyphContext> activeGlyphs_;
   bool glyphCacheValid_ = false;
 
@@ -221,20 +216,22 @@ private:
   PreprocessCallback glyphPreprocessCallback_;
   LineBeginCallback lineBeginCallback_;
 
-  void reloadGlyphIndices(); // for string rendering
+  void reloadGlyphIndices(); // For string rendering.
   void prepareRendering();
-  void loadSingleContext(GlyphContext* ctx, GlyphContext* prev);
-  // Need to be called when font, charMap or size changes;
+  void loadSingleContext(GlyphContext* ctx,
+                         GlyphContext* prev);
+  // Need to be called when font, charMap or size changes.
   void loadStringGlyphs();
-  // Returns total line count
-  int prepareLine(int offset, 
+  // Returns total line count.
+  int prepareLine(int offset,
                   int lineWidth,
                   FT_Vector& outActualLineWidth,
                   int nonSpacingPlaceholder,
                   bool handleMultiLine = false);
   void clearActive(bool glyphOnly = false);
 
-  int convertCharEncoding(int charUcs4, FT_Encoding encoding);
+  int convertCharEncoding(int charUcs4,
+                          FT_Encoding encoding);
 };
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]