# Font Analysis Report - World Numerology Reporting System

**Date**: January 27, 2026  
**Project**: World Numerology API (WNAPI)  
**Focus**: Font configuration and rendering in PDF reports

---

## Executive Summary

The World Numerology reporting system uses **dompdf** (a PHP HTML-to-PDF library) to generate professional PDF reports. The system has multiple font configurations across the codebase, with some inconsistencies and potential issues that should be addressed.

### Key Findings:
- ✅ Multiple fonts available and configured
- ⚠️ Font declarations scattered across multiple files
- ⚠️ Some fonts referenced but not explicitly configured in dompdf
- ✅ Font files properly placed in dompdf library
- ⚠️ Potential font fallback issues for unsupported fonts

---

## 1. Current Font Architecture

### 1.1 Available Fonts in the System

#### Gotham Font Family (Primary)
Located in: `/var/www/html/wnapi/dompdf/lib/fonts/`
- `GothamBook.ttf` (56.6 KB) - Main regular font
- `GothamBookRegular.otf` (29.5 KB)
- `GothamLight.ttf` (56.5 KB)
- `GothamCondensed-Bold.otf` (28.5 KB)
- `GothamCondensed-Book.otf` (28.5 KB)
- `GothamCondensed-Light.otf` (28.5 KB)
- `GothamCondensed-Medium.otf` (28.6 KB) - Used for text-to-image conversion

#### DejaVu Font Family (Fallback/Unicode Support)
- `DejaVuSans.ttf` & variants (Bold, Oblique, BoldOblique)
- `DejaVuSerif.ttf` & variants
- `DejaVuSansMono.ttf` & variants
- All have associated `.ufm` (Unicode Font Metrics) and `.ufm.php` files

#### Core PDF Fonts (Native to PDF Spec)
- `Courier` and variants (Courier-Bold, Courier-BoldOblique, Courier-Oblique)
- `Helvetica` and variants
- Stored as `.afm` (Adobe Font Metrics) files

#### Other Fonts
- `JosefinSans-Regular.ttf`

### 1.2 Font Declaration Sources

The fonts are referenced in the codebase through:

#### **CSS Classes** (in pdf_footer.php and pdf.css)
```css
.header_start { font-family: Century Gothic; }
.header_text { font-family: Century Gothic; }
.subheader_start { font-family: Century Gothic; }
.subheader_text { font-family: Century Gothic; }
.pdf_chapter { font-family: Century Gothic; }
.summary_start { font-family: Century Gothic; }
.summary { font-family: Century Gothic; }
.pdf_chapter_reportname { font-family: "Profile Pro", sans-serif; }
```

#### **Inline Styles** (in pdf_header.php)
```php
font-family: 'Gotham', sans-serif !important;
font-family: 'Gotham', sans-serif !important;
font-family: kabelM !important;
font-family: 'Figtree Medium', 'Futura', 'GothamCondensed-Medium', sans-serif;
```

#### **Direct Font Paths** (in text-image.php)
```php
$font = dirname(__DIR__) . '/dompdf/lib/fonts/GothamCondensed-Medium.otf';
```

---

## 2. PDF Generation Flow

### 2.1 Report Generation Pipeline

```
User Request
    ↓
app_generate_reportmail.php / generate_personality_profile.php
    ↓
personality_pdf.php
    ↓
generatehtml.php (generates HTML content with CSS)
    ↓
pdf_footer.php (where dompdf is initialized and rendering occurs)
    ├─ pdf_header.php (optional cover pages)
    ├─ text-image.php (text-to-image rendering using GD)
    └─ HTML String with inline CSS
    ↓
dompdf->load_html() → dompdf->render() → PDF Output
    ↓
file_put_contents() → Saved to pdf-uploads/
```

### 2.2 DOMPDF Initialization (pdf_footer.php, Line 7-8)

```php
require_once(dirname(__DIR__)."/vendor/autoload.php");
require_once dirname(__DIR__).'/dompdf/lib/html5lib/Parser.php';
require_once dirname(__DIR__).'/dompdf/src/Autoloader.php';

Dompdf\Autoloader::register();
use Dompdf\Dompdf;

$dompdf = new DOMPDF(array(
    'enable_remote' => true,
    'isPhpEnabled' => true,
    'isHtml5Parser' => true
));
```

**Note**: No explicit font directory or default font configuration is set. This means dompdf uses its internal defaults.

---

## 3. Current Font Issues & Inconsistencies

### 🔴 Critical Issues

#### 3.1 Missing Font Definitions for "Century Gothic"
**Location**: pdf.css and pdf_footer.php (multiple classes)  
**Problem**: Century Gothic is referenced in CSS but is NOT available in the dompdf font directory.
```css
.header_start { font-family: Century Gothic; }  /* NOT FOUND IN FONTS DIRECTORY */
```
**Impact**: When dompdf renders these elements, it will fall back to the default font (likely Helvetica or DejaVuSans) instead of Century Gothic.  
**Status**: ❌ BROKEN

#### 3.2 Missing Font Definition for "kabelM"
**Location**: pdf_header.php (inline styles, multiple lines)
```php
font-family:kabelM; /* NOT FOUND IN FONTS DIRECTORY */
```
**Impact**: Same as above - will render with fallback font.  
**Status**: ❌ BROKEN

#### 3.3 Missing Font Definition for "Profile Pro"
**Location**: pdf_footer.php, line 167
```css
.pdf_chapter_reportname { font-family: "Profile Pro", sans-serif; }
```
**Impact**: Will render with sans-serif fallback (DejaVuSans or Helvetica).  
**Status**: ❌ BROKEN

#### 3.4 Missing Font Definition for "Figtree Medium" & "Futura"
**Location**: pdf_header.php, line 261
```php
font-family: 'Figtree Medium', 'Futura', 'GothamCondensed-Medium', sans-serif;
```
**Impact**: Only GothamCondensed-Medium will work; others will use fallback.  
**Status**: ⚠️ PARTIAL

### 🟡 Medium Issues

#### 3.5 Inconsistent Gotham Font Naming
- Some references use: `'Gotham'`
- Some references use: `'GothamCondensed-Medium'`
- Some reference: `GothamBook.ttf` (filename)

**Problem**: The actual font files are named `GothamBook.ttf`, `GothamLight.ttf`, etc., but CSS/inline styles reference `'Gotham'`.  
**Status**: ⚠️ May work if dompdf font aliasing handles this, but unclear.

#### 3.6 Text-to-Image Font Path Hardcoding
**Location**: text-image.php and pdf_header.php
```php
$font = dirname(__DIR__) . '/dompdf/lib/fonts/GothamCondensed-Medium.otf';
```
**Problem**: Direct file system path dependency. If fonts directory moves, text-to-image rendering breaks.  
**Status**: ⚠️ FRAGILE

### 🟢 Positive Findings

#### 3.7 Good Fallback Chain for Report Names
**Location**: pdf_footer.php, line 161
```css
font-family: 'Figtree Medium', 'Futura', 'GothamCondensed-Medium', sans-serif;
```
**Positive**: Has multiple fallbacks, with GothamCondensed-Medium as a guaranteed working option.  
**Status**: ✅ ACCEPTABLE

#### 3.8 DejaVu Fonts Available for Unicode
**Status**: ✅ Good for special characters and international text support.

#### 3.9 Font Cache Files Present
`.ufm.php` files exist for font metrics (DejaVuSans, DejaVuSans-Bold, DejaVuSerif-Italic)  
**Status**: ✅ Proper font metric caching configured.

---

## 4. Font Usage by Report Type

### Report Types Generated:
1. **Personality Profile** (`personality_pdf.php`)
2. **Relationship Profile** (Relationship Compatibility)
3. **Nine Year Forecast**
4. **Name Advisor**
5. **Talent Profile**
6. **Various Numerology Reports**

All use the same dompdf pipeline with the same CSS/font configuration.

---

## 5. Specific Font Rendering Locations

### Main Title/Cover Name (pdf_footer.php)
- **CSS Class**: `.pdf_chapter_reportname`
- **Font Declaration**: `"Profile Pro", sans-serif`
- **Actual Rendered Font**: Sans-serif fallback (likely DejaVuSans)
- **Issue**: ❌ Profile Pro not available

### Report Headers (pdf_footer.php & pdf.css)
- **CSS Class**: `.header_start`, `.header_text`, `.subheader_start`, `.subheader_text`
- **Font Declaration**: `Century Gothic`
- **Actual Rendered Font**: Sans-serif fallback (likely DejaVuSans)
- **Issue**: ❌ Century Gothic not available

### Report Content Text (pdf.css)
- **CSS Class**: `.summary_start`, `.summary`, `.pdf_chapter`
- **Font Declaration**: `Century Gothic`
- **Actual Rendered Font**: Sans-serif fallback
- **Issue**: ❌ Century Gothic not available

### Custom Cover Business Info (pdf_header.php)
- **Font Declaration**: `'Gotham', sans-serif`
- **Actual Rendered Font**: Likely works (GothamBook.ttf available)
- **Status**: ✅ LIKELY WORKING

### Text-as-Image Cover Names (text-image.php)
- **Font**: `GothamCondensed-Medium.otf`
- **Method**: GD library ImageTTFText()
- **Status**: ✅ WORKING (direct file path)

---

## 6. Dompdf Configuration Analysis

### Current Configuration (pdf_footer.php, line 10-13)
```php
$dompdf = new DOMPDF(array(
    'enable_remote' => true,      // Allow external resources
    'isPhpEnabled' => true,       // Allow PHP in HTML
    'isHtml5Parser' => true       // Use HTML5 parser
));
```

### Missing Configurations
```php
// NOT SET:
// 'defaultFont' => 'DejaVuSans',
// 'fontDir' => dirname(__DIR__) . '/dompdf/lib/fonts/',
// 'tempDir' => '/tmp/',
// 'isFontSubsettingEnabled' => true,
```

### Implications
1. **Default Font**: Uses dompdf's internal default (likely Helvetica)
2. **Font Directory**: Uses dompdf's embedded fonts directory
3. **Font Subsetting**: Unknown state (may or may not embed font subsets)
4. **Temp Directory**: Uses system default (may have permission issues)

---

## 7. Font Fallback Mechanism in Dompdf

When a requested font is not found:
1. dompdf checks registered fonts
2. If not found, attempts font-family fallbacks
3. If all fallbacks missing, uses `defaultFont` (Helvetica)
4. For unsupported characters, uses `DejaVuSans` (if set up)

### Actual Fallback Chain for Current Setup
```
Requested: "Century Gothic"
    → Not found in dompdf
    → Fallback: sans-serif
    → Resolved to: DejaVuSans or Helvetica (whichever is set as default)
```

---

## 8. Recommendations

### 🔴 HIGH PRIORITY - Missing Fonts

#### 8.1 Add Missing Font Files
**Action**: Obtain and add the following fonts to `/var/www/html/wnapi/dompdf/lib/fonts/`:
- **Century Gothic** (TTF/OTF) - Referenced extensively in CSS
- **kabelM** (TTF/OTF) - Used in pdf_header.php  
- **Profile Pro** (TTF/OTF) - Used for report titles
- **Futura** (TTF/OTF) - Fallback option in pdf_header.php
- **Figtree Medium** (TTF/OTF) - Fallback option in pdf_header.php

**Steps**:
1. Acquire licensed copies of fonts
2. Convert to TTF if needed (using FontForge or online converters)
3. Place in `/var/www/html/wnapi/dompdf/lib/fonts/`
4. Update dompdf font cache (delete `.ufm.php` files to force regeneration)

#### 8.2 Configure Dompdf with Explicit Font Directory
**Location**: pdf_footer.php, line 10-13
**Change**:
```php
$fontDir = dirname(__DIR__) . '/dompdf/lib/fonts/';
$dompdf = new DOMPDF(array(
    'enable_remote' => true,
    'isPhpEnabled' => true,
    'isHtml5Parser' => true,
    'fontDir' => $fontDir,
    'defaultFont' => 'DejaVuSans',  // Better Unicode support
    'isFontSubsettingEnabled' => true  // Reduce PDF file size
));
```

### 🟡 MEDIUM PRIORITY - Consistency Issues

#### 8.3 Standardize Font References
**Action**: Create a centralized font configuration file

**New File**: `/var/www/html/wnapi/pdf-files-app/font-config.php`
```php
<?php
// PDF Report Font Configuration
define('PDF_FONT_PRIMARY', 'GothamBook');        // Main body text
define('PDF_FONT_HEADER', 'Century Gothic');     // Headers (if available)
define('PDF_FONT_TITLE', 'Profile Pro');         // Cover titles (if available)
define('PDF_FONT_FALLBACK', 'DejaVuSans');       // Fallback for missing fonts
define('PDF_FONT_MONO', 'DejaVuSansMono');       // Monospace text

// Font weights and styles
define('PDF_FONT_STYLES', [
    'bold' => 'GothamBook bold',
    'light' => 'GothamLight',
    'condensed' => 'GothamCondensed-Medium'
]);
?>
```

#### 8.4 Update All CSS Font Declarations
**Files to Update**:
- `/var/www/html/wnapi/pdf-files-app/pdf.css`
- `/var/www/html/wnapi/pdf-files-app/pdf_footer.php` (inline styles)
- `/var/www/html/wnapi/pdf-files-app/pdf_header.php` (inline styles)

**Before**:
```css
.header_start { font-family: Century Gothic; }
```

**After** (with fallback):
```css
.header_start { font-family: 'Century Gothic', 'DejaVuSans', sans-serif; }
```

### 🟢 LOW PRIORITY - Enhancements

#### 8.5 Add Font Subset Configuration
**Benefit**: Reduces PDF file size by embedding only used characters
**Action**: Enable font subsetting in dompdf options

```php
'isFontSubsettingEnabled' => true,
'fontHeightRatio' => 1.0  // Adjust if text rendering looks odd
```

#### 8.6 Document Font Usage
**Action**: Create inline documentation in CSS files explaining font choices:

```css
/*
 * PRIMARY FONTS
 * - GothamBook: Professional, modern appearance (body text)
 * - Century Gothic: Not available - falls back to DejaVuSans
 * - DejaVuSans: Reliable fallback with good Unicode support
 * 
 * SPECIAL USE CASES
 * - Cover names: Rendered as images using GD library (GothamCondensed-Medium.otf)
 * - International text: Uses DejaVuSans with Unicode support
 */
```

#### 8.7 Create Font Testing Report
**Action**: Generate test PDFs with each font to verify rendering

**Test File**: `/var/www/html/wnapi/test-fonts.php`
```php
<?php
// Test script to verify all fonts render correctly in PDFs
// Usage: http://localhost/wnapi/test-fonts.php

$fonts_to_test = [
    'GothamBook',
    'GothamLight', 
    'GothamCondensed-Medium',
    'Century Gothic',
    'DejaVuSans',
    'DejaVuSerif',
    'Helvetica',
    'Courier'
];

foreach ($fonts_to_test as $font) {
    // Generate test PDF for each font
    // Log results
}
?>
```

---

## 9. Testing Checklist

### Before Making Changes
- [ ] Backup current dompdf configuration
- [ ] Backup current pdf_footer.php
- [ ] Document current PDF appearance

### After Adding Fonts
- [ ] Generate test PDFs with each report type
- [ ] Verify font rendering in PDF viewer
- [ ] Check PDF file size (should decrease with subsetting)
- [ ] Test with special characters (é, ñ, etc.)
- [ ] Verify cover name rendering (text-as-image)
- [ ] Check all report pages for consistency

### Regression Testing
- [ ] Generate Personality Profile reports
- [ ] Generate Relationship reports
- [ ] Generate Forecast reports
- [ ] Generate Name Advisor reports
- [ ] Verify custom cover rendering
- [ ] Test email attachments with PDFs

---

## 10. Font File Directory Structure (Current)

```
/var/www/html/wnapi/dompdf/lib/fonts/
├── [CORE PDF FONTS]
│   ├── Courier* (4 files)
│   ├── Helvetica* (4 files)
│   ├── Times-Roman* (4 files)
│   ├── Symbol.afm
│   └── ZapfDingbats.afm
│
├── [DEJAVU FONTS - UNICODE SUPPORT]
│   ├── DejaVuSans* (TTF + metrics)
│   ├── DejaVuSerif* (TTF + metrics)
│   └── DejaVuSansMono* (TTF + metrics)
│
├── [GOTHAM FONTS - CUSTOM FONTS]
│   ├── GothamBook.ttf ✅
│   ├── GothamBookRegular.otf ✅
│   ├── GothamLight.ttf ✅
│   ├── GothamCondensed-Bold.otf ✅
│   ├── GothamCondensed-Book.otf ✅
│   ├── GothamCondensed-Light.otf ✅
│   └── GothamCondensed-Medium.otf ✅
│
├── [OTHER FONTS]
│   ├── JosefinSans-Regular.ttf
│   └── [MISSING: Century Gothic, kabelM, Profile Pro, Futura, Figtree]
│
└── dompdf_font_family_cache.dist.php
    (Font cache configuration)
```

---

## 11. Summary Table: Font Coverage

| Font Name | Status | Used In | Files | Recommendation |
|-----------|--------|---------|-------|-----------------|
| GothamBook | ✅ Present | Cover & Body | pdf_header.php | Keep |
| GothamLight | ✅ Present | - | - | Can use in CSS |
| GothamCondensed-Medium | ✅ Present | Text-to-image | text-image.php | Keep |
| Century Gothic | ❌ Missing | Headers, body text | pdf.css, pdf_footer.php | **ADD** |
| kabelM | ❌ Missing | Cover decorations | pdf_header.php | **ADD** |
| Profile Pro | ❌ Missing | Report titles | pdf_footer.php | **ADD** |
| Futura | ❌ Missing | Fallback option | pdf_header.php | **ADD or REMOVE** |
| Figtree Medium | ❌ Missing | Fallback option | pdf_header.php | **ADD or REMOVE** |
| DejaVuSans | ✅ Present | Fallback | (automatic) | Keep - essential |
| Helvetica | ✅ Present | PDF native | (automatic) | Keep - essential |

---

## 12. Impact Assessment

### If Issues Are NOT Fixed
- **Visual Quality**: Reports will render with "wrong" fonts (less professional appearance)
- **Brand Consistency**: Font inconsistency across reports
- **File Size**: PDFs may be larger without proper font subsetting
- **Performance**: Fallback font resolution adds minimal overhead

### If Issues ARE Fixed
- **Visual Quality**: Reports will match intended design
- **Brand Consistency**: Professional appearance across all reports
- **File Size**: Optimized with font subsetting
- **Maintenance**: Centralized font configuration easier to manage

---

## 13. References & Technical Details

### Dompdf Documentation
- Font support: http://dompdf.github.io/
- Font-face rules: CSS @font-face in dompdf

### Font Standards
- TTF (TrueType Font): Unicode support, widely compatible
- OTF (OpenType Font): Extended features, backward compatible
- AFM (Adobe Font Metrics): For PostScript fonts
- UFM (Unicode Font Metrics): dompdf-specific Unicode support

### PHP Functions Used
- `imagettfbbox()` - GD library font measurement
- `imagettftext()` - GD library text rendering
- `file_get_contents()` - Font file loading
- `file_put_contents()` - PDF file writing

---

## 14. Conclusion

The World Numerology reporting system has a **partial font setup** where:
- ✅ Font infrastructure is properly configured with dompdf
- ✅ Gotham fonts are available and being used
- ✅ DejaVu fallbacks provide Unicode support
- ❌ Multiple referenced fonts are missing (Century Gothic, kabelM, Profile Pro, etc.)
- ⚠️ Font configuration could be more explicit and centralized

**Immediate Action Required**: Add missing font files and configure them in dompdf, or remove references to unavailable fonts to ensure consistent rendering across all generated reports.

---

**Document Version**: 1.0  
**Last Updated**: January 27, 2026  
**Analysis Status**: Complete
