diff --git a/BOIDS_ROADMAP.md b/BOIDS_ROADMAP.md deleted file mode 100644 index 7b4384f..0000000 --- a/BOIDS_ROADMAP.md +++ /dev/null @@ -1,709 +0,0 @@ -# BOIDS ROADMAP - Plan de Mejora Completo - -**Proyecto:** ViBe3 Physics - Sistema de Boids (Flocking Behavior) -**Fecha de creación:** 2025-01-XX -**Estado actual:** Implementación básica funcional pero con problemas críticos - ---- - -## 📊 Diagnóstico de Problemas Actuales - -### 🔴 CRÍTICO: Bug de Clustering (Colapso a Punto Único) - -**Problema observado:** -- Los boids se agrupan correctamente en grupos separados -- **PERO** dentro de cada grupo, todos colapsan al mismo punto exacto -- Las pelotas se superponen completamente, formando una "masa" sin espacio entre ellas - -**Causa raíz identificada:** -1. **Desbalance de fuerzas**: Cohesión (80px radio) domina sobre Separación (30px radio) -2. **Aplicación de fuerzas**: Se aplican fuerzas cada frame sin velocidad mínima -3. **Fuerza máxima muy baja**: `BOID_MAX_FORCE = 0.1` es insuficiente para separación efectiva -4. **Sin velocidad mínima**: Los boids pueden quedarse completamente estáticos (vx=0, vy=0) - -**Impacto:** Sistema de boids inutilizable visualmente - ---- - -### 🔴 CRÍTICO: Rendimiento O(n²) Inaceptable - -**Problema observado:** -- 100 boids: ~60 FPS ✅ -- 1,000 boids: ~15-20 FPS ❌ (caída del 70%) -- 5,000+ boids: < 5 FPS ❌ (completamente inutilizable) - -**Causa raíz identificada:** -```cpp -// Cada boid revisa TODOS los demás boids (3 veces: separation, alignment, cohesion) -for (auto& boid : balls) { - applySeparation(boid); // O(n) - itera todos los balls - applyAlignment(boid); // O(n) - itera todos los balls - applyCohesion(boid); // O(n) - itera todos los balls -} -// Complejidad total: O(n²) × 3 = O(3n²) -``` - -**Cálculos de complejidad:** -- 100 boids: 100 × 100 × 3 = **30,000 checks/frame** -- 1,000 boids: 1,000 × 1,000 × 3 = **3,000,000 checks/frame** (100x más lento) -- 10,000 boids: 10,000 × 10,000 × 3 = **300,000,000 checks/frame** (imposible) - -**Impacto:** No escalable más allá de ~500 boids - ---- - -### 🟡 MEDIO: Comportamiento Visual Pobre - -**Problemas identificados:** -1. **Sin variedad visual**: Todos los boids idénticos (mismo tamaño, color) -2. **Movimiento robótico**: Steering demasiado directo, sin suavizado -3. **Wrapping abrupto**: Teletransporte visible rompe inmersión -4. **Sin personalidad**: Todos los boids se comportan idénticamente - -**Impacto:** Resultado visual poco interesante y repetitivo - ---- - -## 🎯 Plan de Fases de Mejora - ---- - -## **FASE 1: Fix Clustering Bug (CRÍTICO)** ⚠️ - -**Objetivo:** Eliminar el colapso a punto único, mantener grupos dispersos - -**Prioridad:** CRÍTICA -**Tiempo estimado:** 2-3 horas -**Complejidad:** Baja (ajustes de parámetros + lógica mínima) - -### Cambios a Implementar - -#### 1.1 Rebalanceo de Radios y Pesos - -**Problema actual:** -```cpp -// defines.h - VALORES ACTUALES (INCORRECTOS) -BOID_SEPARATION_RADIUS = 30.0f; // Radio muy pequeño -BOID_ALIGNMENT_RADIUS = 50.0f; -BOID_COHESION_RADIUS = 80.0f; // Radio muy grande (domina) -BOID_SEPARATION_WEIGHT = 1.5f; // Peso insuficiente -BOID_ALIGNMENT_WEIGHT = 1.0f; -BOID_COHESION_WEIGHT = 0.8f; -BOID_MAX_FORCE = 0.1f; // Fuerza máxima muy débil -BOID_MAX_SPEED = 3.0f; -``` - -**Solución propuesta:** -```cpp -// defines.h - VALORES CORREGIDOS -BOID_SEPARATION_RADIUS = 25.0f; // Radio pequeño pero suficiente -BOID_ALIGNMENT_RADIUS = 40.0f; -BOID_COHESION_RADIUS = 60.0f; // Reducido (menos dominante) -BOID_SEPARATION_WEIGHT = 3.0f; // TRIPLICADO (alta prioridad) -BOID_ALIGNMENT_WEIGHT = 1.0f; // Sin cambios -BOID_COHESION_WEIGHT = 0.5f; // REDUCIDO a la mitad -BOID_MAX_FORCE = 0.5f; // QUINTUPLICADO (permite reacción rápida) -BOID_MAX_SPEED = 3.0f; // Sin cambios -BOID_MIN_SPEED = 0.5f; // NUEVO: velocidad mínima -``` - -**Justificación:** -- **Separation dominante**: Evita colapso con peso 3x mayor -- **Cohesion reducida**: Radio 60px (antes 80px) + peso 0.5 (antes 0.8) -- **Max force aumentada**: Permite correcciones rápidas -- **Min speed añadida**: Evita boids estáticos - -#### 1.2 Implementar Velocidad Mínima - -**Archivo:** `source/boids_mgr/boid_manager.cpp` - -**Añadir al final de `limitSpeed()`:** -```cpp -void BoidManager::limitSpeed(Ball* boid) { - float vx, vy; - boid->getVelocity(vx, vy); - - float speed = std::sqrt(vx * vx + vy * vy); - - // Limitar velocidad máxima - if (speed > BOID_MAX_SPEED) { - vx = (vx / speed) * BOID_MAX_SPEED; - vy = (vy / speed) * BOID_MAX_SPEED; - boid->setVelocity(vx, vy); - } - - // NUEVO: Aplicar velocidad mínima (evitar boids estáticos) - if (speed > 0.0f && speed < BOID_MIN_SPEED) { - vx = (vx / speed) * BOID_MIN_SPEED; - vy = (vy / speed) * BOID_MIN_SPEED; - boid->setVelocity(vx, vy); - } -} -``` - -#### 1.3 Mejorar Aplicación de Fuerza de Separación - -**Problema actual:** Separación se divide por distancia² (muy débil cuando cerca) - -**Archivo:** `source/boids_mgr/boid_manager.cpp::applySeparation()` - -**Cambio:** -```cpp -// ANTES (línea 145): -steer_x += (dx / distance) / distance; // Dividir por distance² hace fuerza muy débil -steer_y += (dy / distance) / distance; - -// DESPUÉS: -// Separación más fuerte cuando más cerca (inversa de distancia, no cuadrado) -float separation_strength = (BOID_SEPARATION_RADIUS - distance) / BOID_SEPARATION_RADIUS; -steer_x += (dx / distance) * separation_strength; -steer_y += (dy / distance) * separation_strength; -``` - -**Justificación:** Fuerza de separación ahora es proporcional a cercanía (0% en radio máximo, 100% en colisión) - -### Testing de Fase 1 - -**Checklist de validación:** -- [ ] Con 100 boids: Grupos visibles con espacio entre boids individuales -- [ ] Con 1000 boids: Sin colapso a puntos únicos -- [ ] Ningún boid completamente estático (velocidad > 0.5) -- [ ] Distancia mínima entre boids vecinos: ~10-15px -- [ ] FPS con 1000 boids: ~15-20 FPS (sin mejorar, pero funcional) - -**Criterio de éxito:** -✅ Los boids mantienen distancia personal dentro de grupos sin colapsar - ---- - -## **FASE 2: Spatial Hash Grid (ALTO IMPACTO)** 🚀 ✅ **COMPLETADA** - -**Objetivo:** O(n²) → O(n) mediante optimización espacial - -**Prioridad:** ALTA -**Tiempo estimado:** 4-6 horas → **Real: 2 horas** -**Complejidad:** Media (nueva estructura de datos) - -### Concepto: Spatial Hash Grid - -**Problema actual:** -``` -Cada boid revisa TODOS los demás boids -→ 1000 boids × 1000 checks = 1,000,000 comparaciones -``` - -**Solución:** -``` -Dividir espacio en grid de celdas -Cada boid solo revisa boids en celdas vecinas (3×3 = 9 celdas) -→ 1000 boids × ~10 vecinos = 10,000 comparaciones (100x más rápido) -``` - -### Implementación - -#### 2.1 Crear Estructura de Spatial Grid - -**Nuevo archivo:** `source/boids_mgr/spatial_grid.h` -```cpp -#pragma once -#include -#include - -class Ball; - -// Clase para optimización espacial de búsqueda de vecinos -class SpatialGrid { -public: - SpatialGrid(int screen_width, int screen_height, float cell_size); - - void clear(); - void insert(Ball* boid); - std::vector getNearby(Ball* boid, float radius); - -private: - int screen_width_; - int screen_height_; - float cell_size_; - int grid_width_; - int grid_height_; - - // Hash map: cell_id → vector de boids en esa celda - std::unordered_map> grid_; - - int getCellId(float x, float y) const; - void getCellCoords(int cell_id, int& cx, int& cy) const; -}; -``` - -**Nuevo archivo:** `source/boids_mgr/spatial_grid.cpp` -```cpp -#include "spatial_grid.h" -#include "../ball.h" -#include - -SpatialGrid::SpatialGrid(int screen_width, int screen_height, float cell_size) - : screen_width_(screen_width) - , screen_height_(screen_height) - , cell_size_(cell_size) - , grid_width_(static_cast(std::ceil(screen_width / cell_size))) - , grid_height_(static_cast(std::ceil(screen_height / cell_size))) { -} - -void SpatialGrid::clear() { - grid_.clear(); -} - -void SpatialGrid::insert(Ball* boid) { - SDL_FRect pos = boid->getPosition(); - float center_x = pos.x + pos.w / 2.0f; - float center_y = pos.y + pos.h / 2.0f; - - int cell_id = getCellId(center_x, center_y); - grid_[cell_id].push_back(boid); -} - -std::vector SpatialGrid::getNearby(Ball* boid, float radius) { - std::vector nearby; - - SDL_FRect pos = boid->getPosition(); - float center_x = pos.x + pos.w / 2.0f; - float center_y = pos.y + pos.h / 2.0f; - - // Calcular rango de celdas a revisar (3x3 en el peor caso) - int min_cx = static_cast((center_x - radius) / cell_size_); - int max_cx = static_cast((center_x + radius) / cell_size_); - int min_cy = static_cast((center_y - radius) / cell_size_); - int max_cy = static_cast((center_y + radius) / cell_size_); - - // Clamp a límites de grid - min_cx = std::max(0, min_cx); - max_cx = std::min(grid_width_ - 1, max_cx); - min_cy = std::max(0, min_cy); - max_cy = std::min(grid_height_ - 1, max_cy); - - // Recopilar boids de celdas vecinas - for (int cy = min_cy; cy <= max_cy; ++cy) { - for (int cx = min_cx; cx <= max_cx; ++cx) { - int cell_id = cy * grid_width_ + cx; - auto it = grid_.find(cell_id); - if (it != grid_.end()) { - for (Ball* other : it->second) { - if (other != boid) { - nearby.push_back(other); - } - } - } - } - } - - return nearby; -} - -int SpatialGrid::getCellId(float x, float y) const { - int cx = static_cast(x / cell_size_); - int cy = static_cast(y / cell_size_); - cx = std::max(0, std::min(grid_width_ - 1, cx)); - cy = std::max(0, std::min(grid_height_ - 1, cy)); - return cy * grid_width_ + cx; -} - -void SpatialGrid::getCellCoords(int cell_id, int& cx, int& cy) const { - cx = cell_id % grid_width_; - cy = cell_id / grid_width_; -} -``` - -#### 2.2 Integrar SpatialGrid en BoidManager - -**Archivo:** `source/boids_mgr/boid_manager.h` -```cpp -#include "spatial_grid.h" - -class BoidManager { -private: - // ... miembros existentes ... - std::unique_ptr spatial_grid_; // NUEVO -}; -``` - -**Archivo:** `source/boids_mgr/boid_manager.cpp` - -**Modificar `initialize()`:** -```cpp -void BoidManager::initialize(...) { - // ... código existente ... - - // Crear spatial grid con tamaño de celda = radio máximo de búsqueda - float max_radius = std::max({BOID_SEPARATION_RADIUS, BOID_ALIGNMENT_RADIUS, BOID_COHESION_RADIUS}); - spatial_grid_ = std::make_unique(screen_width, screen_height, max_radius); -} -``` - -**Modificar `update()`:** -```cpp -void BoidManager::update(float delta_time) { - if (!boids_active_) return; - - auto& balls = scene_mgr_->getBallsMutable(); - - // NUEVO: Reconstruir spatial grid cada frame - spatial_grid_->clear(); - for (auto& ball : balls) { - spatial_grid_->insert(ball.get()); - } - - // Aplicar reglas (ahora con grid optimizado) - for (auto& ball : balls) { - applySeparation(ball.get(), delta_time); - applyAlignment(ball.get(), delta_time); - applyCohesion(ball.get(), delta_time); - applyBoundaries(ball.get()); - limitSpeed(ball.get()); - } - - // ... resto del código ... -} -``` - -**Modificar `applySeparation()`, `applyAlignment()`, `applyCohesion()`:** - -**ANTES:** -```cpp -const auto& balls = scene_mgr_->getBalls(); -for (const auto& other : balls) { // O(n) - itera TODOS -``` - -**DESPUÉS:** -```cpp -// O(1) amortizado - solo vecinos cercanos -auto nearby = spatial_grid_->getNearby(boid, BOID_SEPARATION_RADIUS); -for (Ball* other : nearby) { // Solo ~10-50 boids -``` - -### Testing de Fase 2 - -**Métricas de rendimiento esperadas:** - -| Cantidad Boids | FPS Antes | FPS Después | Mejora | -|----------------|-----------|-------------|--------| -| 100 | 60 | 60 | 1x (sin cambio) | -| 1,000 | 15-20 | 60+ | **3-4x** ✅ | -| 5,000 | <5 | 40-50 | **10x+** ✅ | -| 10,000 | <1 | 20-30 | **30x+** ✅ | -| 50,000 | imposible | 5-10 | **funcional** ✅ | - -**Checklist de validación:** -- [x] FPS con 1000 boids: >50 FPS → **Pendiente de medición** -- [x] FPS con 5000 boids: >30 FPS → **Pendiente de medición** -- [x] FPS con 10000 boids: >15 FPS → **Pendiente de medición** -- [x] Comportamiento visual idéntico a Fase 1 → **Garantizado (misma lógica)** -- [x] Sin boids "perdidos" (todos actualizados correctamente) → **Verificado en código** - -**Criterio de éxito:** -✅ Mejora de rendimiento **10x+** para 5000+ boids → **ESPERADO** - -### Resultados de Implementación (Fase 2) - -**Implementación completada:** -- ✅ SpatialGrid genérico creado (spatial_grid.h/.cpp) -- ✅ Integración completa en BoidManager -- ✅ Grid poblado cada frame (O(n)) -- ✅ 3 reglas de Reynolds usando queryRadius() (O(1) amortizado) -- ✅ Compilación exitosa sin errores -- ✅ Sistema reutilizable para futuras colisiones físicas - -**Código añadido:** -- 206 líneas nuevas (+5 archivos modificados) -- spatial_grid.cpp: 89 líneas de implementación -- spatial_grid.h: 74 líneas con documentación exhaustiva -- defines.h: BOID_GRID_CELL_SIZE = 100.0f - -**Arquitectura:** -- Tamaño de celda: 100px (≥ BOID_COHESION_RADIUS de 80px) -- Hash map: unordered_map> -- Búsqueda: Solo celdas adyacentes (máx 9 celdas) -- Clear + repoblación cada frame: ~0.01ms para 10K boids - -**Próximo paso:** Medir rendimiento real y comparar con estimaciones - ---- - -## **FASE 3: Mejoras Visuales y de Comportamiento** 🎨 - -**Objetivo:** Hacer el comportamiento más interesante y natural - -**Prioridad:** MEDIA -**Tiempo estimado:** 3-4 horas -**Complejidad:** Baja-Media - -### 3.1 Variedad Visual por Boid - -**Añadir propiedades individuales:** -```cpp -// En ball.h (si no existen ya) -struct BoidProperties { - float size_scale; // 0.8-1.2 (variación de tamaño) - float speed_factor; // 0.9-1.1 (algunos más rápidos) - Color original_color; // Color base individual -}; -``` - -**Aplicar al activar boids:** -- Tamaños variados (80%-120% del tamaño base) -- Velocidades máximas ligeramente diferentes -- Colores con variación de tinte - -### 3.2 Steering Suavizado - -**Problema:** Fuerzas aplicadas directamente causan movimiento robótico - -**Solución:** Interpolación exponencial (smoothing) -```cpp -// Aplicar smooth steering -float smooth_factor = 0.3f; // 0-1 (menor = más suave) -vx += steer_x * smooth_factor; -vy += steer_y * smooth_factor; -``` - -### 3.3 Boundaries Suaves (Soft Wrapping) - -**Problema actual:** Teletransporte abrupto visible - -**Solución:** "Avoid edges" behavior -```cpp -void BoidManager::applyEdgeAvoidance(Ball* boid, float delta_time) { - SDL_FRect pos = boid->getPosition(); - float center_x = pos.x + pos.w / 2.0f; - float center_y = pos.y + pos.h / 2.0f; - - float margin = 50.0f; // Margen de detección de borde - float turn_force = 0.5f; - - float steer_x = 0.0f, steer_y = 0.0f; - - if (center_x < margin) steer_x += turn_force; - if (center_x > screen_width_ - margin) steer_x -= turn_force; - if (center_y < margin) steer_y += turn_force; - if (center_y > screen_height_ - margin) steer_y -= turn_force; - - if (steer_x != 0.0f || steer_y != 0.0f) { - float vx, vy; - boid->getVelocity(vx, vy); - vx += steer_x * delta_time; - vy += steer_y * delta_time; - boid->setVelocity(vx, vy); - } -} -``` - -### Testing de Fase 3 - -**Checklist de validación:** -- [ ] Boids con tamaños variados visibles -- [ ] Movimiento más orgánico y fluido -- [ ] Giros en bordes de pantalla suaves (no teletransporte) -- [ ] Variación de colores perceptible - ---- - -## **FASE 4: Comportamientos Avanzados** 🎮 - -**Objetivo:** Añadir interactividad y dinámicas interesantes - -**Prioridad:** BAJA (opcional) -**Tiempo estimado:** 4-6 horas -**Complejidad:** Media-Alta - -### 4.1 Obstacle Avoidance (Ratón) - -**Funcionalidad:** -- Mouse position actúa como "predador" -- Boids huyen del cursor en un radio de 100px - -**Implementación:** -```cpp -void BoidManager::applyMouseAvoidance(Ball* boid, int mouse_x, int mouse_y) { - SDL_FRect pos = boid->getPosition(); - float center_x = pos.x + pos.w / 2.0f; - float center_y = pos.y + pos.h / 2.0f; - - float dx = center_x - mouse_x; - float dy = center_y - mouse_y; - float distance = std::sqrt(dx * dx + dy * dy); - - const float AVOID_RADIUS = 100.0f; - const float AVOID_STRENGTH = 2.0f; - - if (distance < AVOID_RADIUS && distance > 0.0f) { - float flee_x = (dx / distance) * AVOID_STRENGTH; - float flee_y = (dy / distance) * AVOID_STRENGTH; - - float vx, vy; - boid->getVelocity(vx, vy); - vx += flee_x; - vy += flee_y; - boid->setVelocity(vx, vy); - } -} -``` - -### 4.2 Predator/Prey Dynamics - -**Concepto:** -- 10% de boids son "predadores" (color rojo) -- 90% son "presas" (color normal) -- Predadores persiguen presas -- Presas huyen de predadores - -### 4.3 Leader Following - -**Concepto:** -- Un boid aleatorio es designado "líder" -- Otros boids tienen peso adicional hacia el líder -- El líder se mueve con input del usuario (teclas WASD) - ---- - -## **FASE 5: Optimizaciones Avanzadas** ⚡ - -**Objetivo:** Rendimiento extremo para 50K+ boids - -**Prioridad:** MUY BAJA (solo si necesario) -**Tiempo estimado:** 8-12 horas -**Complejidad:** Alta - -### 5.1 Multi-threading (Parallel Processing) - -**Concepto:** Dividir trabajo entre múltiples hilos CPU - -**Complejidad:** Alta (requiere thread-safety, atomic ops, etc.) - -### 5.2 SIMD Vectorization - -**Concepto:** Procesar 4-8 boids simultáneamente con instrucciones SSE/AVX - -**Complejidad:** Muy Alta (requiere conocimiento de intrinsics) - -### 5.3 GPU Compute Shaders - -**Concepto:** Mover toda la física de boids a GPU - -**Complejidad:** Extrema (requiere OpenGL compute o Vulkan) - ---- - -## **FASE 6: Integración y Pulido** ✨ - -**Objetivo:** Integrar boids con sistemas existentes - -**Prioridad:** MEDIA -**Tiempo estimado:** 2-3 horas -**Complejidad:** Baja - -### 6.1 Integración con Modo DEMO - -**Añadir boids al repertorio de acciones aleatorias:** -```cpp -// En defines.h -constexpr int DEMO_WEIGHT_BOIDS = 8; // 8% probabilidad de activar boids - -// En state_manager.cpp -case Action::ACTIVATE_BOIDS: - engine_->toggleBoidsMode(); - break; -``` - -### 6.2 Debug Visualization - -**Funcionalidad:** Tecla "H" muestra overlay de debug: -- Radios de separación/alignment/cohesion (círculos) -- Vectores de velocidad (flechas) -- Spatial grid (líneas de celdas) -- ID de boid y vecinos - -### 6.3 Configuración Runtime - -**Sistema de "presets" de comportamiento:** -- Preset 1: "Tight Flocks" (cohesión alta) -- Preset 2: "Loose Swarms" (separación alta) -- Preset 3: "Chaotic" (todos los pesos bajos) -- Preset 4: "Fast" (velocidad alta) - -**Controles:** -- Numpad 1-4 (en modo boids) para cambiar preset -- Shift+Numpad +/- para ajustar parámetros en vivo - ---- - -## 📈 Métricas de Éxito del Roadmap Completo - -### Funcionalidad -- ✅ Sin clustering (grupos dispersos correctamente) -- ✅ Comportamiento natural y orgánico -- ✅ Transiciones suaves (no teletransporte visible) - -### Rendimiento -- ✅ 1,000 boids: >50 FPS -- ✅ 5,000 boids: >30 FPS -- ✅ 10,000 boids: >15 FPS - -### Visual -- ✅ Variedad perceptible entre boids -- ✅ Movimiento fluido y dinámico -- ✅ Efectos visuales opcionales funcionales - -### Integración -- ✅ Compatible con modo DEMO -- ✅ Debug overlay útil y claro -- ✅ Configuración runtime funcional - ---- - -## 🔧 Orden de Implementación Recomendado - -### Mínimo Viable (MVP) -1. **FASE 1** (CRÍTICO) - Fix clustering -2. **FASE 2** (ALTO) - Spatial grid - -**Resultado:** Boids funcionales y performantes para 1K-5K boids - -### Producto Completo -3. **FASE 3** (MEDIO) - Mejoras visuales -4. **FASE 6** (MEDIO) - Integración y debug - -**Resultado:** Experiencia pulida y profesional - -### Opcional (Si hay tiempo) -5. **FASE 4** (BAJO) - Comportamientos avanzados -6. **FASE 5** (MUY BAJO) - Optimizaciones extremas - ---- - -## 📝 Notas de Implementación - -### Archivos a Modificar (Fase 1-2) -- `source/defines.h` - Constantes de boids -- `source/boids_mgr/boid_manager.h` - Header del manager -- `source/boids_mgr/boid_manager.cpp` - Implementación -- `source/boids_mgr/spatial_grid.h` - NUEVO archivo -- `source/boids_mgr/spatial_grid.cpp` - NUEVO archivo -- `CMakeLists.txt` - Sin cambios (glob ya incluye boids_mgr/*.cpp) - -### Estrategia de Testing -1. **Compilar después de cada cambio** -2. **Probar con 100 boids primero** (debug rápido) -3. **Escalar a 1000, 5000, 10000** (validar rendimiento) -4. **Usar modo debug (tecla H)** para visualizar parámetros - -### Compatibilidad con Sistema Actual -- ✅ No interfiere con modo PHYSICS -- ✅ No interfiere con modo SHAPE -- ✅ Compatible con todos los temas -- ✅ Compatible con cambio de resolución -- ✅ Compatible con modo DEMO/LOGO - ---- - -**FIN DEL ROADMAP** - -*Documento vivo - Se actualizará según avance la implementación* diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index c4aafa7..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,577 +0,0 @@ -# Claude Code Session - ViBe3 Physics - -## Estado del Proyecto - -**Proyecto:** ViBe3 Physics - Simulador de sprites con físicas avanzadas -**Objetivo:** Implementar nuevas físicas experimentales expandiendo sobre el sistema de delta time -**Base:** Migrado desde vibe1_delta con sistema delta time ya implementado - -## Progreso Actual - -### ✅ Completado - -#### 1. **Migración y Setup Inicial** - - ✅ Renombrado vibe1_delta → vibe3_physics en todos los archivos - - ✅ Carpeta resources → data - - ✅ Actualizado CMakeLists.txt, .gitignore, defines.h, README.md - - ✅ Añadido .claude/ al .gitignore - - ✅ Sistema de compilación CMake funcionando - -#### 2. **Sistema de Físicas Base (Heredado)** - - ✅ **Delta time implementado** - Física independiente del framerate - - ✅ Contador FPS en tiempo real (esquina superior derecha, amarillo) - - ✅ Control V-Sync dinámico con tecla "V" (ON/OFF) - - ✅ Display V-Sync (esquina superior izquierda, cian) - - ✅ **Sistema de temas visuales** - 15 temas (9 estáticos + 6 dinámicos con animación) - - ✅ **Batch rendering optimizado** - Maneja hasta 100,000 sprites - -#### 3. **NUEVA CARACTERÍSTICA: Gravedad Direccional** 🎯 - - ✅ **Enum GravityDirection** (UP/DOWN/LEFT/RIGHT) en defines.h - - ✅ **Ball class actualizada** para física multi-direccional - - ✅ **Detección de superficie inteligente** - Adaptada a cada dirección - - ✅ **Fricción direccional** - Se aplica en la superficie correcta - - ✅ **Controles de cursor** - Cambio dinámico de gravedad - - ✅ **Debug display actualizado** - Muestra dirección actual - -#### 4. **NUEVA CARACTERÍSTICA: Coeficientes de Rebote Variables** ⚡ - - ✅ **Rango ampliado** - De 0.60-0.89 a 0.30-0.95 (+120% variabilidad) - - ✅ **Comportamientos diversos** - Desde pelotas super rebotonas a muy amortiguadas - - ✅ **Debug display** - Muestra coeficiente LOSS de primera pelota - - ✅ **Física realista** - Elimina sincronización entre pelotas - -#### 5. **🎯 NUEVA CARACTERÍSTICA: Modo RotoBall (Esfera 3D Rotante)** 🌐 - - ✅ **Fibonacci Sphere Algorithm** - Distribución uniforme de puntos en esfera 3D - - ✅ **Rotación dual (X/Y)** - Efecto visual dinámico estilo demoscene - - ✅ **Profundidad Z simulada** - Color mod según distancia (oscuro=lejos, brillante=cerca) - - ✅ **Física de atracción con resorte** - Sistema de fuerzas con conservación de momento - - ✅ **Transición física realista** - Pelotas atraídas a esfera rotante con aceleración - - ✅ **Amortiguación variable** - Mayor damping cerca del punto (estabilización) - - ✅ **Sin sprites adicionales** - Usa SDL_SetTextureColorMod para profundidad - - ✅ **Proyección ortográfica** - Coordenadas 3D → 2D en tiempo real - - ✅ **Conservación de inercia** - Al salir mantienen velocidad tangencial - - ✅ **Compatible con temas** - Mantiene paleta de colores activa - - ✅ **Performance optimizado** - Funciona con 1-100,000 pelotas - -### 📋 Controles Actuales - -| Tecla | Acción | -|-------|--------| -| **↑** | **Gravedad hacia ARRIBA** | -| **↓** | **Gravedad hacia ABAJO** | -| **←** | **Gravedad hacia IZQUIERDA** | -| **→** | **Gravedad hacia DERECHA** | -| **C** | **🌐 MODO ROTOBALL - Toggle esfera 3D rotante** | -| V | Alternar V-Sync ON/OFF | -| H | **Toggle debug display (FPS, V-Sync, física, gravedad, modo)** | -| **Numpad Enter** | **Toggle página de temas (Página 1 ↔ Página 2)** | -| **Numpad 1-9, 0** | **Acceso directo a temas según página activa** (ver tablas abajo) | -| B | Ciclar entre TODOS los temas de colores (15 temas) - Adelante | -| Shift+B | Ciclar entre TODOS los temas de colores - Atrás | -| 1-8 | Cambiar número de pelotas (1 a 100,000) | -| ESPACIO | Impulsar pelotas hacia arriba | -| G | Alternar gravedad ON/OFF (mantiene dirección) | -| ESC | Salir | - -### 🎨 Temas de Colores (15 Temas Disponibles - Sistema de 2 Páginas) - -**IMPORTANTE:** Usa **Numpad Enter** para cambiar entre Página 1 y Página 2 - -#### **Página 1** (Temas Estáticos + 1 Dinámico) -| Tecla | Tema | Tipo | Descripción | -|-------|------|------|-------------| -| Numpad 1 | ATARDECER | Estático | Naranjas, rojos, amarillos, rosas | -| Numpad 2 | OCÉANO | Estático | Azules, turquesas, blancos | -| Numpad 3 | NEÓN | Estático | Cian, magenta, verde lima, amarillo vibrante | -| Numpad 4 | BOSQUE | Estático | Verdes, marrones, amarillos otoño | -| Numpad 5 | RGB | Estático | Círculo cromático 24 colores (fondo blanco) | -| Numpad 6 | MONOCROMO | Estático | Fondo negro degradado, sprites blancos | -| Numpad 7 | LAVANDA | Estático | Degradado violeta-azul, pelotas amarillo dorado | -| Numpad 8 | CARMESÍ | Estático | Fondo negro-rojo, pelotas rojas uniformes | -| Numpad 9 | ESMERALDA | Estático | Fondo negro-verde, pelotas verdes uniformes | -| Numpad 0 | AMANECER | **Dinámico** | Noche → Alba → Día (loop 12s) | - -#### **Página 2** (Temas Dinámicos Animados) -| Tecla | Tema | Tipo | Descripción | -|-------|------|------|-------------| -| Numpad 1 | OLAS OCEÁNICAS | **Dinámico** | Azul oscuro ↔ Turquesa (loop 8s) | -| Numpad 2 | PULSO NEÓN | **Dinámico** | Negro ↔ Neón brillante (ping-pong 3s) | -| Numpad 3 | FUEGO | **Dinámico** | Brasas → Llamas → Inferno (loop 10s) | -| Numpad 4 | AURORA | **Dinámico** | Verde → Violeta → Cian (loop 14s) | -| Numpad 5 | VOLCÁN | **Dinámico** | Ceniza → Erupción → Lava (loop 12s) | -| Numpad 6-9, 0 | (sin asignar) | - | Sin función en Página 2 | - -### 🎯 Debug Display (Tecla H) - -Cuando está activado muestra: -``` -FPS: 75 # Esquina superior derecha (amarillo) -VSYNC ON # Esquina superior izquierda (cian) -GRAV 720 # Magnitud gravedad (magenta) -VY -145 # Velocidad Y primera pelota (magenta) -SURFACE YES # En superficie (magenta) -LOSS 0.73 # Coeficiente rebote primera pelota (magenta) -GRAVITY DOWN # Dirección actual (amarillo) -THEME SUNSET # Tema activo (amarillo claro) -MODE PHYSICS # Modo simulación actual (verde claro) - PHYSICS/ROTOBALL -``` - -## Arquitectura Actual - -``` -vibe3_physics/ -├── source/ -│ ├── main.cpp # Bucle principal + controles + debug -│ ├── ball.h/.cpp # Clase Ball con física direccional -│ ├── defines.h # Constantes + enum GravityDirection -│ └── external/ # Utilidades externas -│ ├── texture.h/.cpp # Gestión texturas + nearest filter -│ ├── sprite.h/.cpp # Sistema sprites -│ ├── dbgtxt.h # Debug text + nearest filter -│ └── stb_image.h # Carga imágenes -├── data/ # Recursos (antes resources/) -│ └── ball.png # Textura pelota 10x10px -├── CMakeLists.txt # Build system -└── CLAUDE.md # Este archivo de seguimiento -``` - -## Sistema de Gravedad Direccional - -### 🔧 Implementación Técnica - -#### Enum y Estados -```cpp -enum class GravityDirection { - DOWN, // ↓ Gravedad hacia abajo (por defecto) - UP, // ↑ Gravedad hacia arriba - LEFT, // ← Gravedad hacia la izquierda - RIGHT // → Gravedad hacia la derecha -}; -``` - -#### Lógica de Física por Dirección -- **DOWN**: Pelotas caen hacia abajo, fricción en suelo inferior -- **UP**: Pelotas "caen" hacia arriba, fricción en techo -- **LEFT**: Pelotas "caen" hacia izquierda, fricción en pared izquierda -- **RIGHT**: Pelotas "caen" hacia derecha, fricción en pared derecha - -#### Cambios en Ball Class -- `on_floor_` → `on_surface_` (más genérico) -- `gravity_direction_` (nuevo miembro) -- `setGravityDirection()` (nueva función) -- `update()` completamente reescrito para lógica direccional - -## Lecciones Aprendidas de ViBe2 Modules - -### ✅ Éxitos de Modularización -- **C++20 modules** son viables para código propio -- **CMake + Ninja** funciona bien para modules -- **Separación clara** de responsabilidades mejora arquitectura - -### ❌ Limitaciones Encontradas -- **SDL3 + modules** generan conflictos irresolubles -- **Bibliotecas externas** requieren includes tradicionales -- **Enfoque híbrido** (modules propios + includes externos) es más práctico - -### 🎯 Decisión para ViBe3 Physics -- **Headers tradicionales** (.h/.cpp) por compatibilidad -- **Enfoque en características** antes que arquitectura -- **Organización por clases** en lugar de modules inicialmente - -## Sistema de Coeficientes de Rebote Variables - -### 🔧 Implementación Técnica - -#### Problema Anterior -```cpp -// Sistema ANTIGUO - Poca variabilidad -loss_ = ((rand() % 30) * 0.01f) + 0.6f; // 0.60 - 0.89 (diferencia: 0.29) -``` - -**Resultado**: Pelotas con comportamientos muy similares → Sincronización visible - -#### Solución Implementada -```cpp -// Sistema NUEVO - Alta variabilidad -loss_ = ((rand() % 66) * 0.01f) + 0.30f; // 0.30 - 0.95 (diferencia: 0.65) -``` - -### 🎯 Tipos de Comportamiento - -#### Categorías de Materiales -- **🏀 Super Rebotona** (0.85-0.95): Casi no pierde energía, rebota muchas veces -- **⚽ Normal** (0.65-0.85): Comportamiento estándar equilibrado -- **🎾 Amortiguada** (0.45-0.65): Pierde energía moderada, se estabiliza -- **🏐 Muy Amortiguada** (0.30-0.45): Se para rápidamente, pocas rebotes - -### ✅ Beneficios Conseguidos -- **+120% variabilidad** en coeficientes de rebote -- **Eliminación de sincronización** entre pelotas -- **Comportamientos diversos** visibles inmediatamente -- **Física más realista** con materiales diferentes -- **Debug display** para monitoreo en tiempo real - -## 🚀 Próximos Pasos - Físicas Avanzadas - -### Ideas Pendientes de Implementación - -#### 1. **Colisiones Entre Partículas** -- Detección de colisión ball-to-ball -- Física de rebotes entre pelotas -- Conservación de momentum - -#### 2. **Materiales y Propiedades** -- Diferentes coeficientes de rebote por pelota -- Fricción variable por material -- Densidad y masa como propiedades - -#### 3. **Fuerzas Externas** -- **Viento** - Fuerza horizontal constante -- **Campos magnéticos** - Atracción/repulsión a puntos -- **Turbulencia** - Fuerzas aleatorias localizadas - -#### 4. **Interactividad Avanzada** -- Click para aplicar fuerzas puntuales -- Arrastrar para crear campos de fuerza -- Herramientas de "pincel" de física - -#### 5. **Visualización Avanzada** -- **Trails** - Estelas de movimiento -- **Heatmaps** - Visualización de velocidad/energía -- **Vectores de fuerza** - Visualizar gravedad y fuerzas - -#### 6. **Optimizaciones** -- Spatial partitioning para colisiones -- Level-of-detail para muchas partículas -- GPU compute shaders para física masiva - -### 🎮 Controles Futuros Sugeridos -``` -Mouse Click: Aplicar fuerza puntual -Mouse Drag: Crear campo de fuerza -Mouse Wheel: Ajustar intensidad -R: Reset todas las pelotas -P: Pausa/Resume física -M: Modo materiales -W: Toggle viento -``` - -## 🌐 Implementación Técnica: Modo RotoBall - -### Algoritmo Fibonacci Sphere - -Distribución uniforme de puntos en una esfera usando la secuencia de Fibonacci: - -```cpp -const float golden_ratio = (1.0f + sqrtf(5.0f)) / 2.0f; -const float angle_increment = PI * 2.0f * golden_ratio; - -for (int i = 0; i < num_points; i++) { - float t = static_cast(i) / static_cast(num_points); - float phi = acosf(1.0f - 2.0f * t); // Latitud: 0 a π - float theta = angle_increment * i; // Longitud: 0 a 2π * golden_ratio - - // Coordenadas esféricas → cartesianas - float x = cosf(theta) * sinf(phi) * radius; - float y = sinf(theta) * sinf(phi) * radius; - float z = cosf(phi) * radius; -} -``` - -**Ventajas:** -- Distribución uniforme sin clustering en polos -- O(1) cálculo por punto (no requiere iteraciones) -- Visualmente perfecto para demoscene effects - -### Rotación 3D (Matrices de Rotación) - -```cpp -// Rotación en eje Y (horizontal) -float cos_y = cosf(angle_y); -float sin_y = sinf(angle_y); -float x_rot = x * cos_y - z * sin_y; -float z_rot = x * sin_y + z * cos_y; - -// Rotación en eje X (vertical) -float cos_x = cosf(angle_x); -float sin_x = sinf(angle_x); -float y_rot = y * cos_x - z_rot * sin_x; -float z_final = y * sin_x + z_rot * cos_x; -``` - -**Velocidades:** -- Eje Y: 1.5 rad/s (rotación principal horizontal) -- Eje X: 0.8 rad/s (rotación secundaria vertical) -- Ratio Y/X ≈ 2:1 para efecto visual dinámico - -### Proyección 3D → 2D - -**Proyección Ortográfica:** -```cpp -float screen_x = center_x + x_rotated; -float screen_y = center_y + y_rotated; -``` - -**Profundidad Z (Color Modulation):** -```cpp -// Normalizar Z de [-radius, +radius] a [0, 1] -float z_normalized = (z_final + radius) / (2.0f * radius); - -// Mapear a rango de brillo [MIN_BRIGHTNESS, MAX_BRIGHTNESS] -float brightness_factor = (MIN + z_normalized * (MAX - MIN)) / 255.0f; - -// Aplicar a color RGB -int r_mod = color.r * brightness_factor; -int g_mod = color.g * brightness_factor; -int b_mod = color.b * brightness_factor; -``` - -**Efecto visual:** -- Z cerca (+radius): Brillo máximo (255) → Color original -- Z lejos (-radius): Brillo mínimo (50) → Color oscuro -- Simula profundidad sin sprites adicionales - -### Transición Suave (Interpolación) - -```cpp -// Progress de 0.0 a 1.0 en ROTOBALL_TRANSITION_TIME (1.5s) -transition_progress += delta_time / ROTOBALL_TRANSITION_TIME; - -// Lerp desde posición actual a posición de esfera -float lerp_x = current_x + (target_sphere_x - current_x) * progress; -float lerp_y = current_y + (target_sphere_y - current_y) * progress; -``` - -**Características:** -- Independiente del framerate (usa delta_time) -- Suave y orgánico -- Sin pop visual - -### Performance - -- **Batch rendering**: Una sola llamada `SDL_RenderGeometry` para todos los puntos -- **Recalculación**: Fibonacci sphere recalculada cada frame (O(n) predecible) -- **Sin malloc**: Usa datos ya almacenados en Ball objects -- **Color mod**: CPU-side, sin overhead GPU adicional - -**Rendimiento medido:** -- 100 pelotas: >300 FPS -- 1,000 pelotas: >200 FPS -- 10,000 pelotas: >100 FPS -- 100,000 pelotas: >60 FPS (mismo que modo física) - ---- - -## 🔬 Sistema de Física con Atracción (Spring Force) - -### Mejora Implementada: Transición Física Realista - -**Problema anterior:** Interpolación lineal artificial (lerp) sin física real -**Solución:** Sistema de resorte (Hooke's Law) con conservación de momento - -### Ecuaciones Implementadas - -#### Fuerza de Resorte (Ley de Hooke) -```cpp -F_spring = k * (target - position) -``` -- `k = 300.0`: Constante de rigidez del resorte (N/m) -- Mayor k = atracción más fuerte - -#### Fuerza de Amortiguación (Damping) -```cpp -F_damping = c * velocity -F_total = F_spring - F_damping -``` -- `c_base = 15.0`: Amortiguación lejos del punto -- `c_near = 50.0`: Amortiguación cerca (estabilización) -- Evita oscilaciones infinitas - -#### Aplicación de Fuerzas -```cpp -acceleration = F_total / mass // Asumiendo mass = 1 -velocity += acceleration * deltaTime -position += velocity * deltaTime -``` - -### Comportamiento Físico - -**Al activar RotoBall (tecla C):** -1. Esfera comienza a rotar inmediatamente -2. Cada pelota mantiene su velocidad actual (`vx`, `vy`) -3. Se aplica fuerza de atracción hacia punto móvil en esfera -4. Las pelotas se aceleran hacia sus destinos -5. Amortiguación las estabiliza al llegar - -**Durante RotoBall:** -- Punto destino rota constantemente (actualización cada frame) -- Fuerza se recalcula hacia posición rotada -- Pelotas "persiguen" su punto mientras este se mueve -- Efecto: Convergencia con ligera oscilación orbital - -**Al desactivar RotoBall (tecla C):** -1. Atracción se desactiva (`enableRotoBallAttraction(false)`) -2. Pelotas conservan velocidad tangencial actual -3. Gravedad vuelve a aplicarse -4. Transición suave a física normal - -### Constantes Físicas Ajustables - -```cpp -// En defines.h (VALORES ACTUALES - Amortiguamiento crítico) -ROTOBALL_SPRING_K = 300.0f; // Rigidez resorte -ROTOBALL_DAMPING_BASE = 35.0f; // Amortiguación lejos (crítico ≈ 2*√k*m) -ROTOBALL_DAMPING_NEAR = 80.0f; // Amortiguación cerca (absorción rápida) -ROTOBALL_NEAR_THRESHOLD = 5.0f; // Distancia "cerca" (px) -ROTOBALL_MAX_FORCE = 1000.0f; // Límite fuerza (seguridad) -``` - -**Changelog de Ajustes:** -- **v1:** `DAMPING_BASE=15.0, NEAR=50.0` → Oscilación visible (subdamped) -- **v2:** `DAMPING_BASE=35.0, NEAR=80.0` → **Absorción rápida sin oscilación** ✅ - -### Ajustes Recomendados - -**Si siguen oscilando (poco probable):** -```cpp -ROTOBALL_DAMPING_BASE = 50.0f; // Amortiguamiento super crítico -ROTOBALL_DAMPING_NEAR = 100.0f; // Absorción instantánea -``` - -**Si llegan muy lento:** -```cpp -ROTOBALL_SPRING_K = 400.0f; // Más fuerza -ROTOBALL_DAMPING_BASE = 40.0f; // Compensar con más damping -``` - -**Si quieres más "rebote" visual:** -```cpp -ROTOBALL_DAMPING_BASE = 25.0f; // Menos amortiguación -ROTOBALL_DAMPING_NEAR = 60.0f; // Ligera oscilación -``` - -### Ventajas del Sistema - -✅ **Física realista**: Conservación de momento angular -✅ **Transición orgánica**: Aceleración natural, no artificial -✅ **Inercia preservada**: Al salir conservan velocidad -✅ **Estabilización automática**: Damping evita oscilaciones infinitas -✅ **Performance**: O(1) por pelota, muy eficiente - ---- - -## 🎨 Z-Sorting (Painter's Algorithm) - -### Problema de Renderizado 3D - -**Antes del Z-sorting:** -- Pelotas renderizadas en orden fijo del vector: `Ball[0] → Ball[1] → ... → Ball[N]` -- Orden aleatorio respecto a profundidad Z -- **Problema:** Pelotas oscuras (fondo) pintadas sobre claras (frente) -- Resultado: Inversión de profundidad visual incorrecta - -**Después del Z-sorting:** -- Pelotas ordenadas por `depth_brightness` antes de renderizar -- Painter's Algorithm: **Fondo primero, frente último** -- Pelotas oscuras (Z bajo) renderizadas primero -- Pelotas claras (Z alto) renderizadas último (encima) -- **Resultado:** Oclusión 3D correcta ✅ - -### Implementación (engine.cpp::render()) - -```cpp -if (current_mode_ == SimulationMode::ROTOBALL) { - // 1. Crear vector de índices - std::vector render_order; - for (size_t i = 0; i < balls_.size(); i++) { - render_order.push_back(i); - } - - // 2. Ordenar por depth_brightness (menor primero = fondo primero) - std::sort(render_order.begin(), render_order.end(), - [this](size_t a, size_t b) { - return balls_[a]->getDepthBrightness() < balls_[b]->getDepthBrightness(); - }); - - // 3. Renderizar en orden de profundidad - for (size_t idx : render_order) { - // Renderizar balls_[idx]... - } -} -``` - -### Complejidad y Performance - -| Operación | Complejidad | Tiempo (estimado) | -|-----------|-------------|-------------------| -| Crear índices | O(n) | ~0.001ms (1K pelotas) | -| std::sort | O(n log n) | ~0.01ms (1K pelotas) | -| Renderizar | O(n) | ~variable | -| **Total** | **O(n log n)** | **~0.15ms (10K pelotas)** | - -**Impacto en FPS:** -- 100 pelotas: Imperceptible (<0.001ms) -- 1,000 pelotas: Imperceptible (~0.01ms) -- 10,000 pelotas: Leve (~0.15ms, ~1-2 FPS) -- 100,000 pelotas: Moderado (~2ms, ~10-15 FPS) - -### Optimizaciones Aplicadas - -✅ **Solo en modo RotoBall**: Modo física no tiene overhead -✅ **Vector de índices**: `balls_` no se modifica (física estable) -✅ **Reserve() usado**: Evita realocaciones -✅ **Lambda eficiente**: Acceso directo sin copias - -### Resultado Visual - -✅ **Profundidad correcta**: Fondo detrás, frente delante -✅ **Oclusión apropiada**: Pelotas claras cubren oscuras -✅ **Efecto 3D realista**: Percepción de profundidad correcta -✅ **Sin artefactos visuales**: Ordenamiento estable cada frame - -## Métricas del Proyecto - -### ✅ Logros Actuales -- **Compilación exitosa** con CMake -- **Commit inicial** creado (dec8d43) -- **17 archivos** versionados -- **9,767 líneas** de código -- **Física direccional** 100% funcional -- **Coeficientes variables** implementados - -### 🎯 Objetivos Cumplidos -- ✅ Migración limpia desde vibe1_delta -- ✅ Sistema de gravedad direccional implementado -- ✅ Coeficientes de rebote variables (+120% diversidad) -- ✅ **Modo RotoBall (esfera 3D rotante) implementado** -- ✅ **Fibonacci sphere algorithm funcionando** -- ✅ **Profundidad Z con color modulation** -- ✅ Debug display completo y funcional -- ✅ Controles intuitivos con teclas de cursor -- ✅ Eliminación de sincronización entre pelotas - ---- - -## Comandos Útiles - -### Compilación -```bash -mkdir -p build && cd build && cmake .. && cmake --build . -``` - -### Ejecución -```bash -./vibe3_physics.exe # Windows -./vibe3_physics # Linux/macOS -``` - -### Git -```bash -git status # Ver cambios -git add . # Añadir archivos -git commit -m "..." # Crear commit -``` - ---- - -*Archivo de seguimiento para sesiones Claude Code - ViBe3 Physics* -*Actualizado: Implementación de gravedad direccional completada* \ No newline at end of file diff --git a/Makefile b/Makefile index b19222b..6e01cf5 100644 --- a/Makefile +++ b/Makefile @@ -132,16 +132,16 @@ windows_release: resources.pack @echo "Creando release para Windows - Version: $(VERSION)" # Crea carpeta temporal 'RELEASE_FOLDER' - @rm -rf "$(RELEASE_FOLDER)" - @mkdir -p "$(RELEASE_FOLDER)" + @if exist "$(RELEASE_FOLDER)" rmdir /S /Q "$(RELEASE_FOLDER)" + @mkdir "$(RELEASE_FOLDER)" # Copia el archivo 'resources.pack' - @cp -f "resources.pack" "$(RELEASE_FOLDER)/" + @copy /Y "resources.pack" "$(RELEASE_FOLDER)\" >nul # Copia los ficheros que estan en la raíz del proyecto - @cp -f "LICENSE" "$(RELEASE_FOLDER)/" 2>/dev/null || echo "LICENSE not found (optional)" - @cp -f "README.md" "$(RELEASE_FOLDER)/" - @cp -f release/*.dll "$(RELEASE_FOLDER)/" 2>/dev/null || echo "No DLL files found (optional)" + @copy /Y "LICENSE" "$(RELEASE_FOLDER)\" >nul 2>&1 || echo LICENSE not found (optional) + @copy /Y "README.md" "$(RELEASE_FOLDER)\" >nul + @copy /Y release\*.dll "$(RELEASE_FOLDER)\" >nul 2>&1 || echo DLLs copied successfully # Compila @windres release/vibe3.rc -O coff -o $(RESOURCE_FILE) @@ -149,12 +149,12 @@ windows_release: resources.pack @strip -s -R .comment -R .gnu.version "$(WIN_RELEASE_FILE).exe" --strip-unneeded # Crea el fichero .zip - @rm -f "$(WINDOWS_RELEASE)" + @if exist "$(WINDOWS_RELEASE)" del /Q "$(WINDOWS_RELEASE)" @powershell.exe -Command "Compress-Archive -Path '$(RELEASE_FOLDER)/*' -DestinationPath '$(WINDOWS_RELEASE)' -Force" @echo "Release creado: $(WINDOWS_RELEASE)" # Elimina la carpeta temporal 'RELEASE_FOLDER' - @rm -rf "$(RELEASE_FOLDER)" + @rmdir /S /Q "$(RELEASE_FOLDER)" macos: @echo "Compilando para macOS: $(TARGET_NAME)" diff --git a/REFACTOR_PLAN.md b/REFACTOR_PLAN.md deleted file mode 100644 index 0c34717..0000000 --- a/REFACTOR_PLAN.md +++ /dev/null @@ -1,218 +0,0 @@ -# Plan de Refactorización - ViBe3 Physics Engine - -## Objetivo -Aplicar el **Principio de Responsabilidad Única (SRP)** al motor Engine para: -- Mejorar mantenibilidad del código -- Facilitar extensión de funcionalidades -- Reducir acoplamiento entre sistemas -- Hacer el código más testeable - -## Métricas Iniciales (Pre-refactorización) -- **engine.cpp**: 2341 líneas -- **engine.h**: 196 líneas con 40+ miembros privados -- **Responsabilidades mezcladas**: 7 subsistemas en una sola clase - -## Progreso de Refactorización - -### ✅ FASE 1: InputHandler (COMPLETADA) -**Fecha**: 10/01/2025 -**Commit**: (pendiente) - -**Impacto**: ~430 líneas extraídas del `handleEvents()` - -**Archivos creados**: -- `source/input/input_handler.h` -- `source/input/input_handler.cpp` - -**Métodos públicos agregados a Engine (24 total)**: -```cpp -// Gravedad y física -void pushBallsAwayFromGravity(); -void handleGravityToggle(); -void handleGravityDirectionChange(GravityDirection, const char*); - -// Display y depuración -void toggleVSync(); -void toggleDebug(); - -// Figuras 3D -void toggleShapeMode(); -void activateShape(ShapeType, const char*); -void handleShapeScaleChange(bool); -void resetShapeScale(); -void toggleDepthZoom(); - -// Temas de colores -void cycleTheme(bool); -void switchThemeByNumpad(int); -void toggleThemePage(); -void pauseDynamicTheme(); - -// Sprites/Texturas -void switchTexture(); - -// Escenarios -void changeScenario(int, const char*); - -// Zoom y fullscreen -void handleZoomIn(); -void handleZoomOut(); -void toggleFullscreen(); -void toggleRealFullscreen(); -void toggleIntegerScaling(); - -// Modos de aplicación -void toggleDemoMode(); -void toggleDemoLiteMode(); -void toggleLogoMode(); -``` - -**Cambios internos**: -- Métodos internos renombrados con sufijo `Internal`: - - `toggleShapeMode()` → `toggleShapeModeInternal()` - - `activateShape()` → `activateShapeInternal()` - - `switchTexture()` → `switchTextureInternal()` -- Eliminado método `handleEvents()` (420 líneas) -- Bucle `run()` simplificado a 12 líneas - -**Beneficios**: -- ✅ Engine desacoplado de eventos SDL -- ✅ InputHandler stateless (fácilmente testeable) -- ✅ Clara separación entre detección de input y ejecución de lógica -- ✅ Compilación exitosa sin errores - ---- - -### 🔄 FASE 2: SceneManager (PENDIENTE) -**Impacto estimado**: ~500 líneas + `std::vector` movido - -**Responsabilidad**: Crear, actualizar y gestionar todas las `Ball` - -**Miembros a mover**: -- `std::vector> balls_` -- `GravityDirection current_gravity_` -- `int scenario_` - -**Métodos a mover**: -- `initBalls()` -- `pushBallsAwayFromGravity()` -- `switchBallsGravity()` -- `enableBallsGravityIfDisabled()` -- `forceBallsGravityOn() / Off()` -- `changeGravityDirection()` -- `updateBallSizes()` - ---- - -### 🔄 FASE 3: UIManager (PENDIENTE) -**Impacto estimado**: ~300 líneas + rendering de texto movido - -**Responsabilidad**: Renderizar y actualizar interfaz de usuario - -**Miembros a mover**: -- `Notifier notifier_` -- `TextRenderer text_renderer_debug_` -- `bool show_debug_` -- Variables FPS (`fps_frame_count_`, `fps_current_`, `fps_text_`, `vsync_text_`) - -**Métodos a mover**: -- `showNotificationForAction()` -- Renderizado de FPS, debug info, gravedad, tema, modo - ---- - -### 🔄 FASE 4: StateManager (PENDIENTE) -**Impacto estimado**: ~600 líneas de lógica compleja - -**Responsabilidad**: Gestionar máquina de estados (DEMO/LOGO/SANDBOX) - -**Miembros a mover**: -- `AppMode current_app_mode_, previous_app_mode_` -- Variables DEMO (`demo_timer_`, `demo_next_action_time_`) -- Variables LOGO (todas las relacionadas con logo mode) - -**Métodos a mover**: -- `setState()` -- `updateDemoMode()` -- `performDemoAction()` -- `randomizeOnDemoStart()` -- `enterLogoMode() / exitLogoMode()` - ---- - -### 🔄 FASE 5: ShapeManager (PENDIENTE) -**Impacto estimado**: ~400 líneas + lógica de shapes - -**Responsabilidad**: Crear, actualizar y renderizar figuras 3D polimórficas - -**Miembros a mover**: -- `SimulationMode current_mode_` -- `ShapeType current_shape_type_, last_shape_type_` -- `std::unique_ptr active_shape_` -- `float shape_scale_factor_` -- `bool depth_zoom_enabled_` - -**Métodos a mover**: -- `toggleShapeModeInternal()` -- `activateShapeInternal()` -- `updateShape()` -- `generateShape()` -- `clampShapeScale()` - ---- - -### 🔄 FASE 6: Limpieza y Consolidación Final (PENDIENTE) -**Impacto esperado**: Engine reducido a ~400 líneas (coordinador) - -**Tareas**: -1. Limpiar `engine.h` / `engine.cpp` de código legacy -2. Verificar que todos los sistemas están correctamente integrados -3. Documentar interfaz pública de Engine -4. Actualizar `CLAUDE.md` con nueva arquitectura -5. Verificar compilación y funcionamiento completo - ---- - -## Arquitectura Final Esperada - -```cpp -class Engine { -private: - // SDL Core - SDL_Window* window_; - SDL_Renderer* renderer_; - - // Componentes (composición) - std::unique_ptr input_handler_; - std::unique_ptr scene_manager_; - std::unique_ptr ui_manager_; - std::unique_ptr state_manager_; - std::unique_ptr shape_manager_; - std::unique_ptr theme_manager_; - - // Estado mínimo - bool should_exit_; - float delta_time_; - -public: - void run() { - while (!should_exit_) { - calculateDeltaTime(); - input_handler_->process(*this); - update(); - render(); - } - } -}; -``` - -## Notas -- Cada fase incluye su propio **commit atómico** -- Las fases son **secuenciales** (cada una depende de la anterior) -- Se preserva **100% de funcionalidad** en cada fase -- Compilación verificada después de cada commit - ---- - -*Documento de seguimiento para refactorización ViBe3 Physics* -*Última actualización: 2025-01-10 - Fase 1 completada* diff --git a/REFACTOR_SUMMARY.md b/REFACTOR_SUMMARY.md deleted file mode 100644 index 5c5d8d3..0000000 --- a/REFACTOR_SUMMARY.md +++ /dev/null @@ -1,184 +0,0 @@ -# Engine Refactoring Summary - -## Overview - -Successful refactoring of `engine.cpp` (2341 → 1759 lines, -25%) following Single Responsibility Principle using facade/delegation pattern. - -## Completed Phases - -### Phase 1: InputHandler ✅ -- **Lines extracted:** ~420 lines -- **Files created:** - - `source/input/input_handler.h` - - `source/input/input_handler.cpp` -- **Responsibility:** SDL event handling, keyboard/mouse input processing -- **Commit:** 7629c14 - -### Phase 2: SceneManager ✅ -- **Lines extracted:** ~500 lines -- **Files created:** - - `source/scene/scene_manager.h` - - `source/scene/scene_manager.cpp` -- **Responsibility:** Ball physics, collision detection, gravity management, scenarios -- **Commit:** 71aea6e - -### Phase 3: UIManager ✅ -- **Lines extracted:** ~300 lines -- **Files created:** - - `source/ui/ui_manager.h` - - `source/ui/ui_manager.cpp` -- **Responsibility:** HUD rendering, FPS display, debug info, notifications -- **Commit:** e655c64 -- **Note:** Moved AppMode enum to defines.h for global access - -### Phase 4: StateManager ✅ -- **Approach:** Facade/delegation pattern -- **Files created:** - - `source/state/state_manager.h` - - `source/state/state_manager.cpp` -- **Responsibility:** Application state machine (SANDBOX/DEMO/DEMO_LITE/LOGO) -- **Commits:** e2a60e4, e4636c8 -- **Note:** StateManager maintains state, Engine keeps complex logic temporarily - -### Phase 5: ShapeManager ✅ -- **Approach:** Facade pattern (structure only) -- **Files created:** - - `source/shapes_mgr/shape_manager.h` - - `source/shapes_mgr/shape_manager.cpp` -- **Responsibility:** 3D shape management (sphere, cube, PNG shapes, etc.) -- **Commit:** 8be4c55 -- **Note:** Stub implementation, full migration deferred - -### Phase 6: Consolidation ✅ -- **Result:** Engine acts as coordinator between components -- **Final metrics:** - - engine.cpp: 2341 → 1759 lines (-582 lines, -25%) - - engine.h: 237 → 205 lines (-32 lines, -13%) - -## Architecture Pattern - -**Facade/Delegation Hybrid:** -- Components maintain state and provide interfaces -- Engine delegates calls to components -- Complex logic remains in Engine temporarily (pragmatic approach) -- Allows future incremental migration without breaking functionality - -## Component Composition - -```cpp -class Engine { -private: - std::unique_ptr input_handler_; // Input management - std::unique_ptr scene_manager_; // Ball physics - std::unique_ptr shape_manager_; // 3D shapes - std::unique_ptr state_manager_; // App modes - std::unique_ptr ui_manager_; // UI/HUD - std::unique_ptr theme_manager_; // Color themes (pre-existing) -}; -``` - -## Key Decisions - -1. **Token Budget Constraint:** After Phase 3, pivoted from "full migration" to "facade pattern" to stay within 200k token budget - -2. **Incremental Refactoring:** Each phase: - - Has atomic commit - - Compiles successfully - - Preserves 100% functionality - - Can be reviewed independently - -3. **Pragmatic Approach:** Prioritized: - - Structural improvements over perfection - - Compilation success over complete migration - - Interface clarity over implementation relocation - -## Benefits Achieved - -✅ **Separation of Concerns:** Clear component boundaries -✅ **Testability:** Components can be unit tested independently -✅ **Maintainability:** Smaller, focused files easier to navigate -✅ **Extensibility:** New features can target specific components -✅ **Readability:** Engine.cpp 25% smaller, easier to understand -✅ **Compilation Speed:** Smaller translation units compile faster - -## Future Work - -### Deferred Migrations (Optional) -1. Complete StateManager logic migration (~600 lines) -2. Complete ShapeManager logic migration (~400 lines) -3. Remove duplicate state members from Engine -4. Extract ThemeManager to separate component (currently inline) - -### Architectural Improvements -1. Consider event bus for component communication -2. Add observer pattern for state change notifications -3. Implement proper dependency injection -4. Add component lifecycle management - -## Metrics - -| Metric | Before | After | Change | -|--------|--------|-------|--------| -| engine.cpp | 2341 lines | 1759 lines | -582 (-25%) | -| engine.h | 237 lines | 205 lines | -32 (-13%) | -| Components | 1 (Engine) | 6 (Engine + 5 managers) | +5 | -| Files | 2 | 12 | +10 | -| Separation of concerns | ❌ Monolithic | ✅ Modular | ✅ | - -## Post-Refactor Bug Fix - -### Critical Crash: Nullptr Dereference (Commit 0fe2efc) - -**Problem Discovered:** -- Refactor compiled successfully but crashed immediately at runtime -- Stack trace: `UIManager::updatePhysicalWindowSize()` → `Engine::updatePhysicalWindowSize()` → `Engine::initialize()` -- Root cause: `Engine::initialize()` line 228 called `updatePhysicalWindowSize()` BEFORE creating `ui_manager_` at line 232 - -**Solution Implemented:** -```cpp -// BEFORE (crashed): -updatePhysicalWindowSize(); // Calls ui_manager_->updatePhysicalWindowSize() → nullptr dereference -ui_manager_ = std::make_unique(); - -// AFTER (fixed): -int window_w = 0, window_h = 0; -SDL_GetWindowSizeInPixels(window_, &window_w, &window_h); -physical_window_width_ = window_w; -physical_window_height_ = window_h; -ui_manager_ = std::make_unique(); -ui_manager_->initialize(renderer_, theme_manager_.get(), physical_window_width_, physical_window_height_); -``` - -**Additional Documentation:** -- Added comments to `engine.h` explaining pragmatic state duplication (Engine ↔ StateManager) -- Documented facade pattern stubs in `shape_manager.cpp` with rationale for each method -- Clarified future migration paths - -**Verification:** -- ✅ Compilation successful -- ✅ Application runs without crashes -- ✅ All resources load correctly -- ✅ Initialization order corrected - -## Verification - -All phases verified with: -- ✅ Successful compilation (CMake + MinGW) -- ✅ No linker errors -- ✅ All components initialized correctly -- ✅ Engine runs as coordinator -- ✅ No runtime crashes (post-fix verification) -- ✅ Application executes successfully with all features functional - -## Conclusion - -Refactoring completed successfully within constraints: -- ✅ All 6 phases done -- ✅ 25% code reduction in engine.cpp -- ✅ Clean component architecture -- ✅ 100% functional preservation -- ✅ Critical crash bug fixed (commit 0fe2efc) -- ✅ Comprehensive documentation added -- ✅ Token budget respected (~65k / 200k used) - -**Status:** COMPLETED AND VERIFIED ✅ diff --git a/ROADMAP.md b/ROADMAP.md deleted file mode 100644 index 92233b1..0000000 --- a/ROADMAP.md +++ /dev/null @@ -1,339 +0,0 @@ -# ROADMAP - ViBe3 Physics - -## Estado Actual ✅ - -### Figuras 3D (8/8 Completadas) -- ✅ Q - SPHERE (Esfera Fibonacci) -- ✅ W - WAVE_GRID (Malla ondeante) - ⚠️ Necesita mejora de movimiento -- ✅ E - HELIX (Espiral helicoidal) -- ✅ R - TORUS (Toroide/donut) -- ✅ T - CUBE (Cubo rotante) -- ✅ Y - CYLINDER (Cilindro) - ⚠️ Necesita rotación multi-eje -- ✅ U - ICOSAHEDRON (Icosaedro D20) -- ✅ I - ATOM (Núcleo + órbitas) - -### Temas Visuales (7/7 Completadas) -- ✅ SUNSET (Atardecer) -- ✅ OCEAN (Océano) -- ✅ NEON (Neón vibrante) -- ✅ FOREST (Bosque) -- ✅ RGB (Círculo cromático matemático) -- ✅ MONOCHROME (Monocromo - blanco puro) -- ✅ LAVENDER (Lavanda - degradado violeta-azul, pelotas doradas) - -### Sistemas de Presentación -- ✅ Transiciones LERP entre temas (0.5s suaves) -- ✅ Carga dinámica de texturas desde data/balls/ -- ✅ Hot-swap de sprites con tecla N (cicla entre todas las texturas) -- ✅ PNG_SHAPE (O) - Logo "JAILGAMES" con rotación legible - ---- - -## Mejoras de Presentación 🎨 - -### 1. ✅ Mejorar Animaciones de Figuras 3D -**Descripción:** Añadir movimientos más dinámicos e interesantes a algunas figuras -**Prioridad:** Media -**Estado:** ✅ COMPLETADO -**Detalles:** - -#### CYLINDER (Y): -- ✅ **Rotación principal en eje Y** (spin horizontal continuo) -- ✅ **Tumbling ocasional en eje X** cada 3-5 segundos -- ✅ Transiciones suaves con ease-in-out (1.5s duración) -- ✅ Efecto visual: cilindro "se da una vuelta" ocasionalmente - -#### WAVE_GRID (W): -- ✅ **Vista frontal paralela a pantalla** (sin rotación confusa) -- ✅ **Pivoteo sutil en ejes X e Y** -- ✅ Esquinas se mueven adelante/atrás según posición -- ✅ Movimiento ondulatorio + pivoteo = efecto "océano" -- ✅ Velocidades lentas (0.3-0.5 rad/s) para organicidad - -### 2. ✅ Modo DEMO (Auto-play) -**Descripción:** Modo demostración automática con acciones aleatorias -**Prioridad:** Alta -**Estado:** ✅ COMPLETADO -**Detalles:** -- ✅ Toggle con tecla `D` -- ✅ Timer que ejecuta acciones cada 3-8 segundos (configurable) -- ✅ Acciones: gravedad, figuras, temas, escenarios, impulso, profundidad, escala, sprite -- ✅ Secuencia pseudo-aleatoria con pesos configurables (defines.h) -- ✅ Totalmente interactivo - usuario puede seguir usando controles -- ✅ Indicador visual "DEMO MODE" centrado en pantalla (naranja) -- ✅ Eliminado sistema auto-restart antiguo (ya no necesario) - -### 3. ✅ Resolución Lógica Configurable -**Descripción:** Especificar resolución lógica por parámetros de línea de comandos -**Prioridad:** Media -**Estado:** ✅ COMPLETADO -**Detalles:** -- ✅ Parámetros `-w/--width ` y `-h/--height ` -- ✅ Parámetro `-f/--fullscreen` para pantalla completa -- ✅ Defaults: 1280x720 en ventana (si no se especifica) -- ✅ Validación: mínimo 640x480 -- ✅ Help text con `--help` -- Ejemplo: `./vibe3_physics -w 1920 -h 1080 -f` - -### 4. ✅ Implementar Modo Logo (Easter Egg) -**Descripción:** Modo especial que muestra el logo JAILGAMES como "marca de agua" -**Prioridad:** Alta (característica distintiva) -**Estado:** ✅ COMPLETADO -**Detalles:** - -#### ✅ Configuración Modo Logo: -- ✅ **Figura:** Solo PNG_SHAPE (logo JAILGAMES) -- ✅ **Textura:** Siempre "tiny" (pelota más pequeña) -- ✅ **Tema:** Siempre MONOCHROME (blanco puro) -- ✅ **Escala:** 120% (figuras más grandes que normal) -- ✅ **Pelotas mínimas:** 500 -- ✅ **Tecla manual:** K (activa/desactiva modo logo) - -#### ✅ Comportamiento en Modo Logo: -- ✅ Alterna entre modo SHAPE y modo PHYSICS (como DEMO) -- ✅ Mantiene configuración fija (no cambia tema/textura/escala) -- ✅ Es como un "DEMO específico del logo" - -#### ✅ Integración con DEMO LITE: -- ✅ **Requisitos para salto automático:** - - Mínimo 500 pelotas - - Tema MONOCHROME activo - - Si se cumplen → cambia automáticamente textura a "tiny" y escala a 120% -- ✅ **Duración:** Menos tiempo que DEMO normal (es un "recordatorio") -- ✅ **Después:** Vuelve a DEMO LITE normal - -#### ✅ Integración con DEMO: -- ✅ **Requisitos:** Mínimo 500 pelotas -- ✅ **Acción:** Cambia automáticamente a: MONOCHROME + tiny + escala 120% -- ✅ **Duración:** Menos tiempo que acciones normales -- ✅ **Después:** Vuelve a DEMO normal - -#### ✅ Proporción temporal sugerida: -- ✅ DEMO/DEMO_LITE normal: 80-90% del tiempo -- ✅ Modo Logo: 10-20% del tiempo (aparición ocasional como "easter egg") - -### 5. ⏳ Mejorar Sistema de Vértices PNG_SHAPE -**Descripción:** Con 50 pelotas no activa modo vértices correctamente -**Prioridad:** Baja (mejora visual) -**Estimación:** 1 hora -**Detalles:** -- **Comportamiento actual:** Con 50 pelotas usa filas alternas en bordes -- **Comportamiento deseado:** Activar modo VÉRTICES (extremos izq/der de cada fila) -- **Problema:** Condición `num_points < 150` no es suficientemente agresiva -- **Solución propuesta:** - - Ajustar umbrales de activación de vértices - - Mejorar algoritmo extractCornerVertices() para detectar puntos clave - - Considerar densidad de píxeles en decisión (no solo cantidad absoluta) - -### 5. 🐛 Corregir Escalado de Pelotas en Reposo -**Descripción:** Las pelotas cambian de tamaño cuando están quietas (bug visual) -**Prioridad:** Alta (bug visible) -**Estimación:** 30 minutos -**Detalles:** -- **Síntoma:** Pelotas en reposo (velocidad ≈ 0) se escalan incorrectamente -- **Posible causa:** - - Scale factor calculado desde velocidad o energía - - División por cero o valor muy pequeño - - Interpolación incorrecta en modo transición -- **Investigar:** Ball::render(), scale calculations, depth brightness -- **Solución esperada:** Tamaño constante independiente de velocidad - -### 6. ✅ Sistema de Release -**Descripción:** Empaquetado para distribución standalone -**Prioridad:** Baja -**Estimación:** 30 minutos -**Estado:** ✅ COMPLETADO -**Detalles:** -- ✅ Carpeta `release/` con recursos -- ✅ ResourcePack sistema de empaquetado binario (VBE3 format) -- ✅ Tool `pack_resources` para generar resources.pack -- ✅ SDL3.dll incluido en release -- ✅ Carga híbrida: resources.pack con fallback a data/ -- ✅ Target `make windows_release` en Makefile -- ✅ ZIP generado: vibe3_physics-YYYY-MM-DD-win32-x64.zip - -### 7. ⏳ Logo/Autor Sobreimpreso (Watermark) -**Descripción:** Mostrar logo JAILGAMES en esquina con animación periódica -**Prioridad:** Media -**Estimación:** 2 horas -**Detalles:** -- **Posición:** Esquina inferior derecha (o configurable) -- **Aparición:** Cada X segundos (ej: cada 30-60s) -- **Animación entrada:** Fade-in + slide desde fuera de pantalla -- **Duración visible:** 3-5 segundos -- **Animación salida:** Fade-out + slide hacia fuera -- **Rendering:** Textura PNG con alpha blending -- **Configuración:** - - Intervalo de aparición (LOGO_WATERMARK_INTERVAL) - - Duración visible (LOGO_WATERMARK_DURATION) - - Tamaño relativo a pantalla (ej: 10-15% ancho) - - Opacidad máxima (ej: 70-80% alpha) -- **Integración:** No interfiere con debug display ni modos DEMO/LOGO -- **Asset:** Reutilizar data/jailgames_logo.png existente - -### 8. ⏳ Mejorar Sistema de Renderizado de Texto -**Descripción:** Actualizar tipografía y mejorar clase dbgtxt para mejor legibilidad -**Prioridad:** Media -**Estimación:** 3-4 horas -**Detalles:** -- **Problemas actuales:** - - Fuente bitmap actual poco legible en resoluciones altas - - Sistema dbgtxt limitado (solo fuente fija) - - Sin suavizado (aliasing visible) - - Tamaño no escala con resolución -- **Soluciones propuestas:** - - **Opción A - SDL_ttf:** Usar fuentes TrueType (.ttf) - - Mayor calidad y escalabilidad - - Antialiasing nativo - - Soporte Unicode completo - - Requiere añadir dependencia SDL3_ttf - - **Opción B - Bitmap mejorada:** Nueva fuente bitmap de mayor calidad - - Sin dependencias adicionales - - Textura PNG con caracteres ASCII - - Escalado nearest-neighbor para estética pixel-art - - Más control sobre aspecto retro -- **Mejoras clase dbgtxt:** - - Soporte múltiples tamaños (pequeño/normal/grande) - - Sombra/outline configurable para mejor contraste - - Alineación (izquierda/centro/derecha) - - Color y alpha por texto individual - - Medición de ancho de texto (para centrado dinámico) -- **Assets necesarios:** - - Si TTF: Fuente .ttf embebida (ej: Roboto Mono, Source Code Pro) - - Si Bitmap: Nueva textura font_atlas.png de mayor resolución -- **Retrocompatibilidad:** Mantener API actual de dbgtxt - -### 9. ⏳ Temas Dinámicos (Color Generativo) -**Descripción:** Sistema de generación procedural de temas de colores -**Prioridad:** Baja -**Estimación:** 4-6 horas -**Detalles:** -- **Objetivos:** - - Gradiente de fondo variable (color base + variaciones automáticas) - - Color de pelotas variable (monocromático, complementario, análogo, etc.) - - Generación algorítmica de paletas armónicas -- **Implementación propuesta:** - - **HSV Color Space:** Generar paletas en espacio HSV para control intuitivo - - Hue (matiz): 0-360° para variación de color - - Saturation (saturación): 0-100% para intensidad - - Value (brillo): 0-100% para luminosidad - - **Esquemas de color:** - - Monocromático (un matiz + variaciones de saturación/brillo) - - Complementario (matiz opuesto en rueda de color) - - Análogo (matices adyacentes ±30°) - - Triádico (3 matices equidistantes 120°) - - Tetrádico (4 matices en cuadrado/rectángulo) - - **Parámetros configurables:** - - Base hue (0-360°): Color principal del tema - - Saturation range (0-100%): Rango de intensidad - - Value range (0-100%): Rango de brillo - - Esquema de armonía: mono/complementario/análogo/etc. - - Gradiente de fondo: Automático según base hue - - **Controles de usuario:** - - Tecla G: Generar nuevo tema aleatorio - - Tecla Shift+G: Ciclar esquemas de armonía - - Guardar temas generados favoritos (slot 8-12) -- **Algoritmos:** - - **Gradiente de fondo:** Base hue → Variación análoga oscura (fondo inferior) - - **Color de pelotas:** Según esquema elegido (complementario para contraste máximo) - - **Conversión HSV → RGB:** Algoritmo estándar para SDL rendering -- **Ejemplos de temas generados:** - - Tema "Cyberpunk": Base cyan (180°) + Complementario magenta (300°) - - Tema "Autumn": Base naranja (30°) + Análogo rojo-amarillo - - Tema "Ocean Deep": Base azul (240°) + Monocromático variaciones - - Tema "Toxic": Base verde lima (120°) + Complementario púrpura -- **Persistencia:** - - Guardar temas generados en config.ini (opcional) - - Teclas 8-9-0 para slots de temas custom -- **Compatibilidad:** - - No reemplaza temas existentes (1-7) - - Modo adicional de selección de tema - ---- - -## Futuras Mejoras (Ideas) - -### Performance -- [ ] Spatial partitioning para colisiones ball-to-ball -- [ ] Level-of-detail para 100K+ pelotas -- [ ] GPU compute shaders para física masiva - -### Efectos Visuales -- [ ] Trails (estelas de movimiento) -- [ ] Heatmaps de velocidad/energía -- [ ] Bloom/glow para sprites - -### Física Avanzada -- [ ] Colisiones entre partículas -- [ ] Viento (fuerza horizontal) -- [ ] Campos magnéticos (atracción/repulsión) -- [ ] Turbulencia - -### Shapes PNG -- [ ] **Voxelización 3D para PNG_SHAPE** (Enfoque B) - - Actualmente: Extrusión 2D simple (píxeles → capas Z) - - Futuro: Voxelización real con detección de interior/exterior - - Permite formas 3D más complejas desde imágenes - - Rotación volumétrica en vez de extrusión plana - -### Interactividad -- [ ] Mouse: click para aplicar fuerzas -- [ ] Mouse: drag para crear campos -- [ ] Mouse wheel: ajustar intensidad - ---- - -## Historial de Cambios - -### 2025-10-04 (Sesión 5) - PNG Shape + Texturas Dinámicas + CLI -- ✅ **PNG_SHAPE implementado** - Tecla O para activar logo "JAILGAMES" -- ✅ Carga de PNG 1-bit con stb_image -- ✅ Extrusión 2D (Enfoque A) - píxeles → capas Z -- ✅ Detección de bordes vs relleno completo (configurable) -- ✅ Tamaño 80% pantalla (como otras figuras) -- ✅ Rotación "legible" - De frente con volteretas ocasionales (3-8s idle) -- ✅ Fix: Z forzado a máximo cuando está de frente (texto brillante) -- ✅ Excluido de DEMO/DEMO_LITE (logo especial) -- ✅ **Sistema de texturas dinámicas** - Carga automática desde data/balls/ -- ✅ Tecla N cicla entre todas las texturas PNG encontradas -- ✅ Orden alfabético con normal.png primero por defecto -- ✅ Display dinámico del nombre de textura (uppercase) -- ✅ **Física mejorada SHAPE** - Constantes separadas de ROTOBALL -- ✅ Pegajosidad 2.67x mayor (SPRING_K=800 vs 300) -- ✅ Pelotas se adhieren mejor durante rotaciones rápidas -- ✅ **Parámetros de línea de comandos** - `-w/-h/-f/--help` -- ✅ Resolución configurable (mínimo 640x480) -- 📝 Preparado para voxelización 3D (Enfoque B) en futuro - -### 2025-10-04 (Sesión 4) - Modo DEMO + Mejoras Animaciones -- ✅ **Implementado Modo DEMO (auto-play)** - Tecla D para toggle -- ✅ Sistema de acciones aleatorias cada 3-8 segundos (configurable) -- ✅ 8 tipos de acciones con pesos de probabilidad ajustables -- ✅ Totalmente interactivo - usuario puede seguir controlando -- ✅ Display visual "DEMO MODE" centrado en naranja -- ✅ **Mejoras animaciones 3D**: tumbling en cilindro + pivoteo en wave grid -- ✅ CYLINDER: tumbling ocasional en eje X cada 3-5s con ease-in-out -- ✅ WAVE_GRID: pivoteo sutil paralelo a pantalla (efecto océano) -- ❌ Eliminado sistema auto-restart antiguo (ya no necesario) - -### 2025-10-04 (Sesión 3) -- ✅ Implementado tema MONOCHROME (6º tema) -- ✅ Sistema LERP para transiciones suaves de temas (0.5s) -- ✅ Hot-swap de sprites con tecla N (ball.png ↔ ball_small.png) -- ✅ Tamaño dinámico de pelotas desde texture->getWidth() -- ✅ Ajuste de posiciones inteligente al cambiar sprite -- 📝 Añadidas mejoras propuestas para CYLINDER y WAVE_GRID - -### 2025-10-03 (Sesión 2) -- ✅ Implementadas 8 figuras 3D (SPHERE, WAVE_GRID, HELIX, TORUS, CUBE, CYLINDER, ICOSAHEDRON, ATOM) -- ✅ Sistema polimórfico de shapes con herencia virtual - -### 2025-10-02 (Sesión 1) -- ✅ Migración desde vibe1_delta -- ✅ Sistema de gravedad direccional (4 direcciones) -- ✅ Coeficientes de rebote variables (0.30-0.95) -- ✅ 5 temas de colores iniciales - ---- - -**Última actualización:** 2025-10-04 diff --git a/RULES.md b/RULES.md deleted file mode 100644 index d12d3c7..0000000 --- a/RULES.md +++ /dev/null @@ -1,128 +0,0 @@ -Documento de especificaciones de ViBe3 Physics - -# Codigo -* Se preferira el uso de #pragma once a #ifndef -* Se preferira el uso de C++ frente a C -* Se preferirá el uso de verisiones mas moderdas de C++ frente a las mas viejas, es decir, C++20 frente a C++17, por ejemplo -* Se preferirá el uso de smart pointers frente a new/delete y sobretodo antes que malloc/free -* Los archivos de cabecera que definan clases, colocaran primero la parte publica y luego la privada. Agruparan los metodos por categorias. Todas las variables, constantes, estructuras, enumeraciones, metodos, llevaran el comentario a la derecha -* Se respetarán las reglas definidas en los ficheros .clang-tidy y .clang-format que hay en la raíz o en las subcarpetas - -# Funcionamiento -* El programa tiene modos de funcionamiento (AppMode). El funcionamiento de cada uno de ellos se describirá mas adelante. Son estados exclusivos que van automatizando cambios en el SimulationMode, Theme y Scene y serian: - * SANDBOX - * DEMO - * DEMO LITE - * LOGO - * LOGO LITE -* El progama tiene otros modos de funcionamiento (SimulationMode). El funcionamiento de cada uno de ellos se describirá mas adelante. Son estados exclusivos: - * PHYISICS - * FIGURE - * BOIDS -* El programa tiene un gestor de temas (Theme) que cambia los colores de lo que se ve en pantalla. Hay temas estáticos y dinamicos. El cambio de tema se realiza mediante LERP y no afecta en nada ni al AppMode ni al SimulationMode, es decir, no modifica sus estados. -* El programa tiene escenarios (Scene). Cada escena tiene un numero de pelotas. Cuando se cambia el escenario, se elimina el vector de pelotas y se crea uno nuevo. En funcion del SimulationMode actual se inicializan las pelotas de manera distinta: - * PHYSICS: Se crean todas las pelotas cerca de la parte superior de la pantalla distribuidas en el 75% central del eje X (es como está ahora) - * FIGURE: Se crean todas las pelotas en el punto central de la pantalla - * BOIDS: Se crean todas las pelotas en posiciones al azar de la pantalla con velocidades y direcciones aleatorias -* El cambio de SimulationMode ha de preservar la inercia (velocidad, aceleracion, direccion) de cada pelota. El cambio se produce tanto de forma manual (pulsacion de una tecla por el usuario) como de manera automatica (cualquier AppMode que no sea SANDBOX) - * PHYSICS a FIGURE: - * Pulsando la tecla de la figura correspondiente - * Pulsando la tecla F (ultima figura seleccionada) - * PHYSICS a BOIDS: - * Pulsando la tecla B - * FIGURE a PHYSICS: - * Pulsando los cursores: Gravedad ON en la direccion del cursor - * Pulsando la tecla G: Gravedad OFF - * Pulsando la tecla F: Ultima gravedad seleccionada (direccion o OFF) - * FIGURE a BOIDS: - * Pulsando la tecla B - * BOIDS a PHYSICS: - * Pulsando la tecla G: Gravedad OFF - * Pulsando los cursores: Gravedad ON en la direccion del cursor - * BOIDS a FIGURE: - * Pulsando la tecla de la figura - * Pulsando la tecla F (ultima figura) - -# AppMode -* SANDBOX - * No hay ningun automatismo. El usuario va pulsando teclas para ejecutar acciones. - * Si pulsa una de estas teclas, cambia de modo: - * D: DEMO - * L: DEMO LITE - * K: LOGO -* DEMO - * En el modo DEMO el programa va cambiando el SimulationMode de manera automatica (como está ahora es correcto) - * Se inicializa con un Theme al azar, Scene al azar, SimulationMode al azar. Restringido FIGURE->PNG_SHAPE - * Va cambiando de Theme - * Va cambiando de Scene - * Cambia la escala de la Figure - * Cambia el Sprite de las pelotas - * NO PUEDE cambiar a la figura PNG_SHAPE - * Eventualmente puede cambiar de manera automatica a LOGO LITE, sin restricciones - * El usuario puede cambiar el SimulationMode, el Theme o el Scene. Esto no hace que se salga del modo DEMO - * El usuario puede cambiar de AppMode pulsando: - * D: SANDBOX - * L: DEMO LITE - * K: LOGO -* DEMO LITE - * En el modo DEMO el programa va cambiando el SimulationMode de manera automatica (como está ahora es correcto) - * Se inicializa con un Theme al azar, Scene al azar, SimulationMode al azar. Restringido FIGURE->PNG_SHAPE - * Este modo es exactamente igual a DEMO pero NO PUEDE: - * Cambiar de Scene - * Cambiar de Theme - * Cambiar el Sprite de las pelotas - * Eventualmente puede cambiar de manera automatica a LOGO LITE, sin restricciones - * NO PUEDE cambiar a la figura PNG_SHAPE - * El usuario puede cambiar el SimulationMode, el Theme o el Scene. Esto no hace que se salga del modo DEMO LITE - * El usuario puede cambiar de AppMode pulsando: - * D: DEMO - * L: SANDBOX - * K: LOGO -* LOGO - * Se inicializa con la Scene de 5.000 pelotas, con el tamaño de Sprite->Small, con SimulationMode en FIGURE->PNG_SHAPE, con un tema al azar de los permitidos - * No cambia de Scene - * No cambia el tamaño de Sprite - * No cambia la escala de FIGURE - * Los temas permitidos son MONOCROMO, LAVANDA, CARMESI, ESMERALDA o cualquiera de los temas dinamicos - * En este modo SOLO aparece la figura PNG_SHAPE - * Solo cambiara a los temas permitidos - * Cambia el SimulationMode de PHYSICS a FIGURE (como hace ahora) pero no a BOIDS. BOIDS prohibido - * El usuario puede cambiar el SimulationMode, el Theme o el Scene. Esto no hace que se salga del modo LOGO. Incluso puede poner un Theme no permitido o otro Scene. - * El automatismo no cambia nunca de Theme así que se mantiene el del usuario. - * El automatismo no cambia nunca de Scene asi que se mantiene el del usuario. - * El usuario puede cambiar de AppMode pulsando: - * D: DEMO - * L: DEMO LITE - * K: SANDBOX - * B: SANDBOX->BOIDS -* LOGO LITE - * Este modo es exactamente igual al modo LOGO pero con unas pequeñas diferencias: - * Solo se accede a el de manera automatica, el usuario no puede invocarlo. No hay tecla - * Como se accede de manera automatica solo se puede llegar a él desde DEMO o DEMO LITE. Hay que guardar el estado en el que se encontraba AppMode, EngindeMode, Scene, Theme, Sprite, Scale... etc - * Este modo tiene una muy alta probabilidad de terminar, volviendo al estado anterior desde donde se invocó. - * El usuario puede cambiar de AppMode pulsando: - * D: Si el modo anterior era DEMO -> SANDBOX, else -> DEMO) - * L: Si el modo anterior era DEMO LITE -> SANDBOX, else -> DEMO LITE) - * K: LOGO - * B: SANDBOX->BOIDS - - -# Debug Hud -* En el debug hud hay que añadir que se vea SIEMPRE el AppMode (actualmente aparece centrado, hay que ponerlo a la izquierda) y no solo cietos AppModes -* Tiene que aparecer tambien el SimulationMode -* El modo de Vsync -* El modo de escalado entero, stretched, ventana -* la resolucion fisica -* la resolucion logica -* el refresco del panel -* El resto de cosas que salen - -# Ventana de ayuda -* La ventana de ayuda actualmente es cuadrada -* Esa es la anchura minima que ha de tener -* Hay que ver cual es la linea mas larga, multiplicarla por el numero de columnas, añadirle los paddings y que ese sea el nuevo ancho -* Actualmente se renderiza a cada frame. El rendimiento cae de los 1200 frames por segundo a 200 frames por segundo. Habria que renderizarla a una textura o algo. El problema es que el cambio de Theme con LERP afecta a los colores de la ventana. Hay que investigar qué se puede hacer. - -# Bugs actuales -* En el modo LOGO, si se pulsa un cursor, se activa la gravedad y deja de funcionar los automatismos. Incluso he llegado a ver como sale solo del modo LOGO sin pulsar nada -* En el modo BOIDS, pulsar la G activa la gravedad. La G deberia pasar al modo PHYSICS con la gravedad en OFF y que las pelotas mantuvieran el momento/inercia \ No newline at end of file diff --git a/release/SDL3.dll b/release/SDL3.dll new file mode 100644 index 0000000..bfeaf13 Binary files /dev/null and b/release/SDL3.dll differ diff --git a/release/SDL3_ttf.dll b/release/SDL3_ttf.dll new file mode 100644 index 0000000..b1616f9 Binary files /dev/null and b/release/SDL3_ttf.dll differ diff --git a/release/frameworks/SDL3_ttf.xcframework/Info.plist b/release/frameworks/SDL3_ttf.xcframework/Info.plist new file mode 100644 index 0000000..5069acc --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/Info.plist @@ -0,0 +1,90 @@ + + + + + AvailableLibraries + + + BinaryPath + SDL3_ttf.framework/SDL3_ttf + LibraryIdentifier + tvos-arm64 + LibraryPath + SDL3_ttf.framework + SupportedArchitectures + + arm64 + + SupportedPlatform + tvos + + + BinaryPath + SDL3_ttf.framework/SDL3_ttf + LibraryIdentifier + ios-arm64_x86_64-simulator + LibraryPath + SDL3_ttf.framework + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + ios + SupportedPlatformVariant + simulator + + + BinaryPath + SDL3_ttf.framework/SDL3_ttf + LibraryIdentifier + tvos-arm64_x86_64-simulator + LibraryPath + SDL3_ttf.framework + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + tvos + SupportedPlatformVariant + simulator + + + BinaryPath + SDL3_ttf.framework/SDL3_ttf + LibraryIdentifier + ios-arm64 + LibraryPath + SDL3_ttf.framework + SupportedArchitectures + + arm64 + + SupportedPlatform + ios + + + BinaryPath + SDL3_ttf.framework/Versions/A/SDL3_ttf + LibraryIdentifier + macos-arm64_x86_64 + LibraryPath + SDL3_ttf.framework + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + macos + + + CFBundlePackageType + XFWK + XCFrameworkFormatVersion + 1.0 + + diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/Headers/SDL_textengine.h b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/Headers/SDL_textengine.h new file mode 100644 index 0000000..9f5f1f0 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/Headers/SDL_textengine.h @@ -0,0 +1,181 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + + +/** + * \file SDL_textengine.h + * + * Definitions for implementations of the TTF_TextEngine interface. + */ +#ifndef SDL_TTF_TEXTENGINE_H_ +#define SDL_TTF_TEXTENGINE_H_ + +#include +#include + +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A font atlas draw command. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_DrawCommand +{ + TTF_DRAW_COMMAND_NOOP, + TTF_DRAW_COMMAND_FILL, + TTF_DRAW_COMMAND_COPY +} TTF_DrawCommand; + +/** + * A filled rectangle draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_FillOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_FILL */ + SDL_Rect rect; /**< The rectangle to fill, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ +} TTF_FillOperation; + +/** + * A texture copy draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_CopyOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_COPY */ + int text_offset; /**< The offset in the text corresponding to this glyph. + There may be multiple glyphs with the same text offset + and the next text offset might be several Unicode codepoints + later. In this case the glyphs and codepoints are grouped + together and the group bounding box is the union of the dst + rectangles for the corresponding glyphs. */ + TTF_Font *glyph_font; /**< The font containing the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + Uint32 glyph_index; /**< The glyph index of the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + SDL_Rect src; /**< The area within the glyph to be drawn */ + SDL_Rect dst; /**< The drawing coordinates of the glyph, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ + void *reserved; +} TTF_CopyOperation; + +/** + * A text engine draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef union TTF_DrawOperation +{ + TTF_DrawCommand cmd; + TTF_FillOperation fill; + TTF_CopyOperation copy; +} TTF_DrawOperation; + + +/* Private data in TTF_Text, to assist in text measurement and layout */ +typedef struct TTF_TextLayout TTF_TextLayout; + + +/* Private data in TTF_Text, available to implementations */ +struct TTF_TextData +{ + TTF_Font *font; /**< The font used by this text, read-only. */ + SDL_FColor color; /**< The color of the text, read-only. */ + + bool needs_layout_update; /**< True if the layout needs to be updated */ + TTF_TextLayout *layout; /**< Cached layout information, read-only. */ + int x; /**< The x offset of the upper left corner of this text, in pixels, read-only. */ + int y; /**< The y offset of the upper left corner of this text, in pixels, read-only. */ + int w; /**< The width of this text, in pixels, read-only. */ + int h; /**< The height of this text, in pixels, read-only. */ + int num_ops; /**< The number of drawing operations to render this text, read-only. */ + TTF_DrawOperation *ops; /**< The drawing operations used to render this text, read-only. */ + int num_clusters; /**< The number of substrings representing clusters of glyphs in the string, read-only */ + TTF_SubString *clusters; /**< Substrings representing clusters of glyphs in the string, read-only */ + + SDL_PropertiesID props; /**< Custom properties associated with this text, read-only. This field is created as-needed using TTF_GetTextProperties() and the properties may be then set and read normally */ + + bool needs_engine_update; /**< True if the engine text needs to be updated */ + TTF_TextEngine *engine; /**< The engine used to render this text, read-only. */ + void *engine_text; /**< The implementation-specific representation of this text */ +}; + +/** + * A text engine interface. + * + * This structure should be initialized using SDL_INIT_INTERFACE() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa SDL_INIT_INTERFACE + */ +struct TTF_TextEngine +{ + Uint32 version; /**< The version of this interface */ + + void *userdata; /**< User data pointer passed to callbacks */ + + /* Create a text representation from draw instructions. + * + * All fields of `text` except `internal->engine_text` will already be filled out. + * + * This function should set the `internal->engine_text` field to a non-NULL value. + * + * \param userdata the userdata pointer in this interface. + * \param text the text object being created. + */ + bool (SDLCALL *CreateText)(void *userdata, TTF_Text *text); + + /** + * Destroy a text representation. + */ + void (SDLCALL *DestroyText)(void *userdata, TTF_Text *text); + +}; + +/* Check the size of TTF_TextEngine + * + * If this assert fails, either the compiler is padding to an unexpected size, + * or the interface has been updated and this should be updated to match and + * the code using this interface should be updated to handle the old version. + */ +SDL_COMPILE_TIME_ASSERT(TTF_TextEngine_SIZE, + (sizeof(void *) == 4 && sizeof(TTF_TextEngine) == 16) || + (sizeof(void *) == 8 && sizeof(TTF_TextEngine) == 32)); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_TEXTENGINE_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/Headers/SDL_ttf.h b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/Headers/SDL_ttf.h new file mode 100644 index 0000000..b723bc7 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/Headers/SDL_ttf.h @@ -0,0 +1,2833 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* WIKI CATEGORY: SDLTTF */ + +/** + * # CategorySDLTTF + * + * Header file for SDL_ttf library + * + * This library is a wrapper around the excellent FreeType 2.0 library, + * available at: https://www.freetype.org/ + */ + +#ifndef SDL_TTF_H_ +#define SDL_TTF_H_ + +#include +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO + */ +#define SDL_TTF_MAJOR_VERSION 3 +#define SDL_TTF_MINOR_VERSION 2 +#define SDL_TTF_MICRO_VERSION 2 + +/** + * This is the version number macro for the current SDL_ttf version. + */ +#define SDL_TTF_VERSION \ + SDL_VERSIONNUM(SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION) + +/** + * This macro will evaluate to true if compiled with SDL_ttf at least X.Y.Z. + */ +#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \ + ((SDL_TTF_MAJOR_VERSION >= X) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || SDL_TTF_MICRO_VERSION >= Z)) + +/** + * This function gets the version of the dynamically linked SDL_ttf library. + * + * \returns SDL_ttf version. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_Version(void); + +/** + * Query the version of the FreeType library in use. + * + * TTF_Init() should be called before calling this function. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetFreeTypeVersion(int *major, int *minor, int *patch); + +/** + * Query the version of the HarfBuzz library in use. + * + * If HarfBuzz is not available, the version reported is 0.0.0. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetHarfBuzzVersion(int *major, int *minor, int *patch); + +/** + * The internal structure containing font information. + * + * Opaque data! + */ +typedef struct TTF_Font TTF_Font; + +/** + * Initialize SDL_ttf. + * + * You must successfully call this function before it is safe to call any + * other function in this library. + * + * It is safe to call this more than once, and each successful TTF_Init() call + * should be paired with a matching TTF_Quit() call. + * + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Quit + */ +extern SDL_DECLSPEC bool SDLCALL TTF_Init(void); + +/** + * Create a font from a file, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param file path to font file. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, float ptsize); + +/** + * Create a font from an SDL_IOStream, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * If `closeio` is true, `src` will be automatically closed once the font is + * closed. Otherwise you should close `src` yourself after closing the font. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param src an SDL_IOStream to provide a font file's data. + * \param closeio true to close `src` when the font is closed, false to leave + * it open. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIO(SDL_IOStream *src, bool closeio, float ptsize); + +/** + * Create a font with the specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_FONT_CREATE_FILENAME_STRING`: the font file to open, if an + * SDL_IOStream isn't being used. This is required if + * `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER`: an SDL_IOStream containing the + * font to be opened. This should not be closed until the font is closed. + * This is required if `TTF_PROP_FONT_CREATE_FILENAME_STRING` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER`: the offset in the iostream + * for the beginning of the font, defaults to 0. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN`: true if closing the + * font should also close the associated SDL_IOStream. + * - `TTF_PROP_FONT_CREATE_SIZE_FLOAT`: the point size of the font. Some .fon + * fonts will have several sizes embedded in the file, so the point size + * becomes the index of choosing which size. If the value is too high, the + * last indexed size will be the default. + * - `TTF_PROP_FONT_CREATE_FACE_NUMBER`: the face index of the font, if the + * font contains multiple font faces. + * - `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER`: the horizontal DPI to use + * for font rendering, defaults to + * `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER` if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER`: the vertical DPI to use for + * font rendering, defaults to `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER` + * if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_EXISTING_FONT`: an optional TTF_Font that, if set, + * will be used as the font data source and the initial size and style of + * the new font. + * + * \param props the properties to use. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_FONT_CREATE_FILENAME_STRING "SDL_ttf.font.create.filename" +#define TTF_PROP_FONT_CREATE_IOSTREAM_POINTER "SDL_ttf.font.create.iostream" +#define TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER "SDL_ttf.font.create.iostream.offset" +#define TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN "SDL_ttf.font.create.iostream.autoclose" +#define TTF_PROP_FONT_CREATE_SIZE_FLOAT "SDL_ttf.font.create.size" +#define TTF_PROP_FONT_CREATE_FACE_NUMBER "SDL_ttf.font.create.face" +#define TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER "SDL_ttf.font.create.hdpi" +#define TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER "SDL_ttf.font.create.vdpi" +#define TTF_PROP_FONT_CREATE_EXISTING_FONT "SDL_ttf.font.create.existing_font" + +/** + * Create a copy of an existing font. + * + * The copy will be distinct from the original, but will share the font file + * and have the same size and style as the original. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param existing_font the font to copy. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * original font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_CopyFont(TTF_Font *existing_font); + +/** + * Get the properties associated with a font. + * + * The following read-write properties are provided by SDL: + * + * - `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`: The FT_Stroker_LineCap value + * used when setting the font outline, defaults to + * `FT_STROKER_LINECAP_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`: The FT_Stroker_LineJoin value + * used when setting the font outline, defaults to + * `FT_STROKER_LINEJOIN_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER`: The FT_Fixed miter limit used + * when setting the font outline, defaults to 0. + * + * \param font the font to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetFontProperties(TTF_Font *font); + +#define TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER "SDL_ttf.font.outline.line_cap" +#define TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER "SDL_ttf.font.outline.line_join" +#define TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER "SDL_ttf.font.outline.miter_limit" + +/** + * Get the font generation. + * + * The generation is incremented each time font properties change that require + * rebuilding glyphs, such as style, size, etc. + * + * \param font the font to query. + * \returns the font generation or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontGeneration(TTF_Font *font); + +/** + * Add a fallback font. + * + * Add a font that will be used for glyphs that are not in the current font. + * The fallback font should have the same size and style as the current font. + * + * If there are multiple fallback fonts, they are used in the order added. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to add as a fallback. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_ClearFallbackFonts + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AddFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove a fallback font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to remove as a fallback. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_ClearFallbackFonts + */ +extern SDL_DECLSPEC void SDLCALL TTF_RemoveFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove all fallback fonts. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC void SDLCALL TTF_ClearFallbackFonts(TTF_Font *font); + +/** + * Set a font's size dynamically. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSize(TTF_Font *font, float ptsize); + +/** + * Set font size dynamically with target resolutions, in dots per inch. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + * \sa TTF_GetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSizeDPI(TTF_Font *font, float ptsize, int hdpi, int vdpi); + +/** + * Get the size of a font. + * + * \param font the font to query. + * \returns the size of the font, or 0.0f on failure; call SDL_GetError() for + * more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSize + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC float SDLCALL TTF_GetFontSize(TTF_Font *font); + +/** + * Get font target resolutions, in dots per inch. + * + * \param font the font to query. + * \param hdpi a pointer filled in with the target horizontal DPI. + * \param vdpi a pointer filled in with the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontDPI(TTF_Font *font, int *hdpi, int *vdpi); + +/** + * Font style flags for TTF_Font + * + * These are the flags which can be used to set the style of a font in + * SDL_ttf. A combination of these flags can be used with functions that set + * or query font style, such as TTF_SetFontStyle or TTF_GetFontStyle. + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + * \sa TTF_GetFontStyle + */ +typedef Uint32 TTF_FontStyleFlags; + +#define TTF_STYLE_NORMAL 0x00 /**< No special style */ +#define TTF_STYLE_BOLD 0x01 /**< Bold style */ +#define TTF_STYLE_ITALIC 0x02 /**< Italic style */ +#define TTF_STYLE_UNDERLINE 0x04 /**< Underlined text */ +#define TTF_STYLE_STRIKETHROUGH 0x08 /**< Strikethrough text */ + +/** + * Set a font's current style. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to set a new style on. + * \param style the new style values to set, OR'd together. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontStyle + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, TTF_FontStyleFlags style); + +/** + * Query a font's current style. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to query. + * \returns the current font style, as a set of bit flags. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + */ +extern SDL_DECLSPEC TTF_FontStyleFlags SDLCALL TTF_GetFontStyle(const TTF_Font *font); + +/** + * Set a font's current outline. + * + * This uses the font properties `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`, + * `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`, and + * `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER` when setting the font outline. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set a new outline on. + * \param outline positive outline value, 0 to default. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontOutline + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline); + +/** + * Query a font's current outline. + * + * \param font the font to query. + * \returns the font's current outline value. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontOutline + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font); + +/** + * Hinting flags for TTF (TrueType Fonts) + * + * This enum specifies the level of hinting to be applied to the font + * rendering. The hinting level determines how much the font's outlines are + * adjusted for better alignment on the pixel grid. + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + * \sa TTF_GetFontHinting + */ +typedef enum TTF_HintingFlags +{ + TTF_HINTING_INVALID = -1, + TTF_HINTING_NORMAL, /**< Normal hinting applies standard grid-fitting. */ + TTF_HINTING_LIGHT, /**< Light hinting applies subtle adjustments to improve rendering. */ + TTF_HINTING_MONO, /**< Monochrome hinting adjusts the font for better rendering at lower resolutions. */ + TTF_HINTING_NONE, /**< No hinting, the font is rendered without any grid-fitting. */ + TTF_HINTING_LIGHT_SUBPIXEL /**< Light hinting with subpixel rendering for more precise font edges. */ +} TTF_HintingFlags; + +/** + * Set a font's current hinter setting. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to set a new hinter setting on. + * \param hinting the new hinter setting. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontHinting + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, TTF_HintingFlags hinting); + +/** + * Query the number of faces of a font. + * + * \param font the font to query. + * \returns the number of FreeType font faces. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetNumFontFaces(const TTF_Font *font); + +/** + * Query a font's current FreeType hinter setting. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to query. + * \returns the font's current hinter value, or TTF_HINTING_INVALID if the + * font is invalid. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + */ +extern SDL_DECLSPEC TTF_HintingFlags SDLCALL TTF_GetFontHinting(const TTF_Font *font); + +/** + * Enable Signed Distance Field rendering for a font. + * + * SDF is a technique that helps fonts look sharp even when scaling and + * rotating, and requires special shader support for display. + * + * This works with Blended APIs, and generates the raw signed distance values + * in the alpha channel of the resulting texture. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set SDF support on. + * \param enabled true to enable SDF, false to disable. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSDF(TTF_Font *font, bool enabled); + +/** + * Query whether Signed Distance Field rendering is enabled for a font. + * + * \param font the font to query. + * \returns true if enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontSDF(const TTF_Font *font); + +/** + * Query a font's weight, in terms of the lightness/heaviness of the strokes. + * + * \param font the font to query. + * \returns the font's current weight. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.4.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontWeight(const TTF_Font *font); + +#define TTF_FONT_WEIGHT_THIN 100 /**< Thin (100) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_LIGHT 200 /**< ExtraLight (200) named font weight value */ +#define TTF_FONT_WEIGHT_LIGHT 300 /**< Light (300) named font weight value */ +#define TTF_FONT_WEIGHT_NORMAL 400 /**< Normal (400) named font weight value */ +#define TTF_FONT_WEIGHT_MEDIUM 500 /**< Medium (500) named font weight value */ +#define TTF_FONT_WEIGHT_SEMI_BOLD 600 /**< SemiBold (600) named font weight value */ +#define TTF_FONT_WEIGHT_BOLD 700 /**< Bold (700) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BOLD 800 /**< ExtraBold (800) named font weight value */ +#define TTF_FONT_WEIGHT_BLACK 900 /**< Black (900) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BLACK 950 /**< ExtraBlack (950) named font weight value */ + +/** + * The horizontal alignment used when rendering wrapped text. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_HorizontalAlignment +{ + TTF_HORIZONTAL_ALIGN_INVALID = -1, + TTF_HORIZONTAL_ALIGN_LEFT, + TTF_HORIZONTAL_ALIGN_CENTER, + TTF_HORIZONTAL_ALIGN_RIGHT +} TTF_HorizontalAlignment; + +/** + * Set a font's current wrap alignment option. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set a new wrap alignment option on. + * \param align the new wrap alignment option. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontWrapAlignment + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontWrapAlignment(TTF_Font *font, TTF_HorizontalAlignment align); + +/** + * Query a font's current wrap alignment option. + * + * \param font the font to query. + * \returns the font's current wrap alignment option. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontWrapAlignment + */ +extern SDL_DECLSPEC TTF_HorizontalAlignment SDLCALL TTF_GetFontWrapAlignment(const TTF_Font *font); + +/** + * Query the total height of a font. + * + * This is usually equal to point size. + * + * \param font the font to query. + * \returns the font's height. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontHeight(const TTF_Font *font); + +/** + * Query the offset from the baseline to the top of a font. + * + * This is a positive value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's ascent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontAscent(const TTF_Font *font); + +/** + * Query the offset from the baseline to the bottom of a font. + * + * This is a negative value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's descent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontDescent(const TTF_Font *font); + +/** + * Set the spacing between lines of text for a font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param lineskip the new line spacing for the font. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontLineSkip + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontLineSkip(TTF_Font *font, int lineskip); + +/** + * Query the spacing between lines of text for a font. + * + * \param font the font to query. + * \returns the font's recommended spacing. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontLineSkip + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontLineSkip(const TTF_Font *font); + +/** + * Set if kerning is enabled for a font. + * + * Newly-opened fonts default to allowing kerning. This is generally a good + * policy unless you have a strong reason to disable it, as it tends to + * produce better rendering (with kerning disabled, some fonts might render + * the word `kerning` as something that looks like `keming` for example). + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set kerning on. + * \param enabled true to enable kerning, false to disable. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontKerning + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, bool enabled); + +/** + * Query whether or not kerning is enabled for a font. + * + * \param font the font to query. + * \returns true if kerning is enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontKerning + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontKerning(const TTF_Font *font); + +/** + * Query whether a font is fixed-width. + * + * A "fixed-width" font means all glyphs are the same width across; a + * lowercase 'i' will be the same size across as a capital 'W', for example. + * This is common for terminals and text editors, and other apps that treat + * text as a grid. Most other things (WYSIWYG word processors, web pages, etc) + * are more likely to not be fixed-width in most cases. + * + * \param font the font to query. + * \returns true if the font is fixed-width, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsFixedWidth(const TTF_Font *font); + +/** + * Query whether a font is scalable or not. + * + * Scalability lets us distinguish between outline and bitmap fonts. + * + * \param font the font to query. + * \returns true if the font is scalable, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsScalable(const TTF_Font *font); + +/** + * Query a font's family name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's family name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontFamilyName(const TTF_Font *font); + +/** + * Query a font's style name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's style name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontStyleName(const TTF_Font *font); + +/** + * Direction flags + * + * The values here are chosen to match + * [hb_direction_t](https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-direction-t) + * . + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontDirection + */ +typedef enum TTF_Direction +{ + TTF_DIRECTION_INVALID = 0, + TTF_DIRECTION_LTR = 4, /**< Left to Right */ + TTF_DIRECTION_RTL, /**< Right to Left */ + TTF_DIRECTION_TTB, /**< Top to Bottom */ + TTF_DIRECTION_BTT /**< Bottom to Top */ +} TTF_Direction; + +/** + * Set the direction to be used for text shaping by a font. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping by a font. + * + * This defaults to TTF_DIRECTION_INVALID if it hasn't been set. + * + * \param font the font to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetFontDirection(TTF_Font *font); + +/** + * Convert from a 4 character string to a 32-bit tag. + * + * \param string the 4 character string to convert. + * \returns the 32-bit representation of the string. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_StringToTag(const char *string); + +/** + * Convert from a 32-bit tag to a 4 character string. + * + * \param tag the 32-bit tag to convert. + * \param string a pointer filled in with the 4 character representation of + * the tag. + * \param size the size of the buffer pointed at by string, should be at least + * 4. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC void SDLCALL TTF_TagToString(Uint32 tag, char *string, size_t size); + +/** + * Set the script to be used for text shaping by a font. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontScript(TTF_Font *font, Uint32 script); + +/** + * Get the script used for text shaping a font. + * + * \param font the font to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontScript(TTF_Font *font); + +/** + * Get the script used by a 32-bit codepoint. + * + * \param ch the character code to check. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * on success, or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function is thread-safe. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetGlyphScript(Uint32 ch); + +/** + * Set language to be used for text shaping by a font. + * + * If SDL_ttf was not built with HarfBuzz support, this function returns + * false. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to specify a language for. + * \param language_bcp47 a null-terminated string containing the desired + * language's BCP47 code. Or null to reset the value. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47); + +/** + * Check whether a glyph is provided by the font for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \returns true if font provides a glyph for this character, false if not. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontHasGlyph(TTF_Font *font, Uint32 ch); + +/** + * The type of data in a glyph image + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_ImageType +{ + TTF_IMAGE_INVALID, + TTF_IMAGE_ALPHA, /**< The color channels are white */ + TTF_IMAGE_COLOR, /**< The color channels have image data */ + TTF_IMAGE_SDF, /**< The alpha channel has signed distance field information */ +} TTF_ImageType; + +/** + * Get the pixel image for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImage(TTF_Font *font, Uint32 ch, TTF_ImageType *image_type); + +/** + * Get the pixel image for a character index. + * + * This is useful for text engine implementations, which can call this with + * the `glyph_index` in a TTF_CopyOperation + * + * \param font the font to query. + * \param glyph_index the index of the glyph to return. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImageForIndex(TTF_Font *font, Uint32 glyph_index, TTF_ImageType *image_type); + +/** + * Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint. + * + * To understand what these metrics mean, here is a useful link: + * + * https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param minx a pointer filled in with the minimum x coordinate of the glyph + * from the left edge of its bounding box. This value may be + * negative. + * \param maxx a pointer filled in with the maximum x coordinate of the glyph + * from the left edge of its bounding box. + * \param miny a pointer filled in with the minimum y coordinate of the glyph + * from the bottom edge of its bounding box. This value may be + * negative. + * \param maxy a pointer filled in with the maximum y coordinate of the glyph + * from the bottom edge of its bounding box. + * \param advance a pointer filled in with the distance to the next glyph from + * the left edge of this glyph's bounding box. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphMetrics(TTF_Font *font, Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance); + +/** + * Query the kerning size between the glyphs of two UNICODE codepoints. + * + * \param font the font to query. + * \param previous_ch the previous codepoint. + * \param ch the current codepoint. + * \param kerning a pointer filled in with the kerning size between the two + * glyphs, in pixels, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphKerning(TTF_Font *font, Uint32 previous_ch, Uint32 ch, int *kerning); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSize(TTF_Font *font, const char *text, size_t length, int *w, int *h); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param wrap_width the maximum width or 0 to wrap on newline characters. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSizeWrapped(TTF_Font *font, const char *text, size_t length, int wrap_width, int *w, int *h); + +/** + * Calculate how much of a UTF-8 string will fit in a given width. + * + * This reports the number of characters that can be rendered before reaching + * `max_width`. + * + * This does not need to render the string to do this calculation. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param max_width maximum width, in pixels, available for the string, or 0 + * for unbounded width. + * \param measured_width a pointer filled in with the width, in pixels, of the + * string that will fit, may be NULL. + * \param measured_length a pointer filled in with the length, in bytes, of + * the string that will fit, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_MeasureString(TTF_Font *font, const char *text, size_t length, int max_width, int *measured_width, size_t *measured_length); + +/** + * Render UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Solid_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrapLength the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrapLength); + +/** + * Render a single 32-bit glyph at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Shaded, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Shaded_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + +/** + * Render UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Blended_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_LCD_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_Blended. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_Blended_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_Blended. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_LCD(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + + +/** + * A text engine used to create text objects. + * + * This is a public interface that can be used by applications and libraries + * to perform customize rendering with text objects. See + * for details. + * + * There are three text engines provided with the library: + * + * - Drawing to an SDL_Surface, created with TTF_CreateSurfaceTextEngine() + * - Drawing with an SDL 2D renderer, created with + * TTF_CreateRendererTextEngine() + * - Drawing with the SDL GPU API, created with TTF_CreateGPUTextEngine() + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextEngine TTF_TextEngine; + +/** + * Internal data for TTF_Text + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextData TTF_TextData; + +/** + * Text created with TTF_CreateText() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + * \sa TTF_GetTextProperties + * \sa TTF_DestroyText + */ +typedef struct TTF_Text +{ + char *text; /**< A copy of the UTF-8 string that this text object represents, useful for layout, debugging and retrieving substring text. This is updated when the text object is modified and will be freed automatically when the object is destroyed. */ + int num_lines; /**< The number of lines in the text, 0 if it's empty */ + + int refcount; /**< Application reference count, used when freeing surface */ + + TTF_TextData *internal; /**< Private */ + +} TTF_Text; + +/** + * Create a text engine for drawing text on SDL surfaces. + * + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroySurfaceTextEngine + * \sa TTF_DrawSurfaceText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateSurfaceTextEngine(void); + +/** + * Draw text to an SDL surface. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateSurfaceTextEngine(). + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \param surface the surface to draw on. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawSurfaceText(TTF_Text *text, int x, int y, SDL_Surface *surface); + +/** + * Destroy a text engine created for drawing text on SDL surfaces. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateSurfaceTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroySurfaceTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text on an SDL renderer. + * + * \param renderer the renderer to use for creating textures and drawing text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + * \sa TTF_CreateRendererTextEngineWithProperties + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngine(SDL_Renderer *renderer); + +/** + * Create a text engine for drawing text on an SDL renderer, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER`: the renderer to use for + * creating textures and drawing text + * - `TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the + * texture atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER "SDL_ttf.renderer_text_engine.create.renderer" +#define TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.renderer_text_engine.create.atlas_texture_size" + +/** + * Draw text to an SDL renderer. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateRendererTextEngine(), and will draw using the renderer passed to + * that function. + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawRendererText(TTF_Text *text, float x, float y); + +/** + * Destroy a text engine created for drawing text on an SDL renderer. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateRendererTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyRendererTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text with the SDL GPU API. + * + * \param device the SDL_GPUDevice to use for creating textures and drawing + * text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngineWithProperties + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngine(SDL_GPUDevice *device); + +/** + * Create a text engine for drawing text with the SDL GPU API, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_GPU_TEXT_ENGINE_DEVICE`: the SDL_GPUDevice to use for creating + * textures and drawing text. + * - `TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the texture + * atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_GPU_TEXT_ENGINE_DEVICE "SDL_ttf.gpu_text_engine.create.device" +#define TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.gpu_text_engine.create.atlas_texture_size" + +/** + * Draw sequence returned by TTF_GetGPUTextDrawData + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextDrawData + */ +typedef struct TTF_GPUAtlasDrawSequence +{ + SDL_GPUTexture *atlas_texture; /**< Texture atlas that stores the glyphs */ + SDL_FPoint *xy; /**< An array of vertex positions */ + SDL_FPoint *uv; /**< An array of normalized texture coordinates for each vertex */ + int num_vertices; /**< Number of vertices */ + int *indices; /**< An array of indices into the 'vertices' arrays */ + int num_indices; /**< Number of indices */ + TTF_ImageType image_type; /**< The image type of this draw sequence */ + + struct TTF_GPUAtlasDrawSequence *next; /**< The next sequence (will be NULL in case of the last sequence) */ +} TTF_GPUAtlasDrawSequence; + +/** + * Get the geometry data needed for drawing the text. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateGPUTextEngine(). + * + * The positive X-axis is taken towards the right and the positive Y-axis is + * taken upwards for both the vertex and the texture coordinates, i.e, it + * follows the same convention used by the SDL_GPU API. If you want to use a + * different coordinate system you will need to transform the vertices + * yourself. + * + * If the text looks blocky use linear filtering. + * + * \param text the text to draw. + * \returns a NULL terminated linked list of TTF_GPUAtlasDrawSequence objects + * or NULL if the passed text is empty or in case of failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC TTF_GPUAtlasDrawSequence * SDLCALL TTF_GetGPUTextDrawData(TTF_Text *text); + +/** + * Destroy a text engine created for drawing text with the SDL GPU API. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyGPUTextEngine(TTF_TextEngine *engine); + +/** + * The winding order of the vertices returned by TTF_GetGPUTextDrawData + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_GPUTextEngineWinding +{ + TTF_GPU_TEXTENGINE_WINDING_INVALID = -1, + TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE, + TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE +} TTF_GPUTextEngineWinding; + +/** + * Sets the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \param winding the new winding order option. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextEngineWinding + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetGPUTextEngineWinding(TTF_TextEngine *engine, TTF_GPUTextEngineWinding winding); + +/** + * Get the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \returns the winding order used by the GPU text engine or + * TTF_GPU_TEXTENGINE_WINDING_INVALID in case of error. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetGPUTextEngineWinding + */ +extern SDL_DECLSPEC TTF_GPUTextEngineWinding SDLCALL TTF_GetGPUTextEngineWinding(const TTF_TextEngine *engine); + +/** + * Create a text object from UTF-8 text and a text engine. + * + * \param engine the text engine to use when creating the text object, may be + * NULL. + * \param font the font to render with. + * \param text the text to use, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns a TTF_Text object or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font and text engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyText + */ +extern SDL_DECLSPEC TTF_Text * SDLCALL TTF_CreateText(TTF_TextEngine *engine, TTF_Font *font, const char *text, size_t length); + +/** + * Get the properties associated with a text object. + * + * \param text the TTF_Text to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetTextProperties(TTF_Text *text); + +/** + * Set the text engine used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param engine the text engine to use for drawing. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextEngine + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextEngine(TTF_Text *text, TTF_TextEngine *engine); + +/** + * Get the text engine used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_TextEngine used by the text on success or NULL on failure; + * call SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextEngine + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_GetTextEngine(TTF_Text *text); + +/** + * Set the font used by a text object. + * + * When a text object has a font, any changes to the font will automatically + * regenerate the text. If you set the font to NULL, the text will continue to + * render but changes to the font will no longer affect the text. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param font the font to use, may be NULL. + * \returns false if the text pointer is null; otherwise, true. call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextFont(TTF_Text *text, TTF_Font *font); + +/** + * Get the font used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_Font used by the text on success or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_GetTextFont(TTF_Text *text); + +/** + * Set the direction to be used for text shaping a text object. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * \param text the text to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextDirection(TTF_Text *text, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping a text object. + * + * This defaults to the direction of the font used by the text object. + * + * \param text the text to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetTextDirection(TTF_Text *text); + +/** + * Set the script to be used for text shaping a text object. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * \param text the text to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextScript(TTF_Text *text, Uint32 script); + +/** + * Get the script used for text shaping a text object. + * + * This defaults to the script of the font used by the text object. + * + * \param text the text to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set on either the text object or the + * font. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetTextScript(TTF_Text *text); + +/** + * Set the color of a text object. + * + * The default text color is white (255, 255, 255, 255). + * + * \param text the TTF_Text to modify. + * \param r the red color value in the range of 0-255. + * \param g the green color value in the range of 0-255. + * \param b the blue color value in the range of 0-255. + * \param a the alpha value in the range of 0-255. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColor(TTF_Text *text, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + +/** + * Set the color of a text object. + * + * The default text color is white (1.0f, 1.0f, 1.0f, 1.0f). + * + * \param text the TTF_Text to modify. + * \param r the red color value, normally in the range of 0-1. + * \param g the green color value, normally in the range of 0-1. + * \param b the blue color value, normally in the range of 0-1. + * \param a the alpha value in the range of 0-1. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColorFloat(TTF_Text *text, float r, float g, float b, float a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value in the range of + * 0-255, may be NULL. + * \param g a pointer filled in with the green color value in the range of + * 0-255, may be NULL. + * \param b a pointer filled in with the blue color value in the range of + * 0-255, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-255, + * may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColor(TTF_Text *text, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value, normally in the + * range of 0-1, may be NULL. + * \param g a pointer filled in with the green color value, normally in the + * range of 0-1, may be NULL. + * \param b a pointer filled in with the blue color value, normally in the + * range of 0-1, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-1, may + * be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColorFloat(TTF_Text *text, float *r, float *g, float *b, float *a); + +/** + * Set the position of a text object. + * + * This can be used to position multiple text objects within a single wrapping + * text area. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param x the x offset of the upper left corner of this text in pixels. + * \param y the y offset of the upper left corner of this text in pixels. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextPosition(TTF_Text *text, int x, int y); + +/** + * Get the position of a text object. + * + * \param text the TTF_Text to query. + * \param x a pointer filled in with the x offset of the upper left corner of + * this text in pixels, may be NULL. + * \param y a pointer filled in with the y offset of the upper left corner of + * this text in pixels, may be NULL. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextPosition(TTF_Text *text, int *x, int *y); + +/** + * Set whether wrapping is enabled on a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param wrap_width the maximum width in pixels, 0 to wrap on newline + * characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWidth(TTF_Text *text, int wrap_width); + +/** + * Get whether wrapping is enabled on a text object. + * + * \param text the TTF_Text to query. + * \param wrap_width a pointer filled in with the maximum width in pixels or 0 + * if the text is being wrapped on newline characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextWrapWidth(TTF_Text *text, int *wrap_width); + +/** + * Set whether whitespace should be visible when wrapping a text object. + * + * If the whitespace is visible, it will take up space for purposes of + * alignment and wrapping. This is good for editing, but looks better when + * centered or aligned if whitespace around line wrapping is hidden. This + * defaults false. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param visible true to show whitespace when wrapping text, false to hide + * it. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWhitespaceVisible(TTF_Text *text, bool visible); + +/** + * Return whether whitespace is shown when wrapping a text object. + * + * \param text the TTF_Text to query. + * \returns true if whitespace is shown when wrapping text, or false + * otherwise. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_TextWrapWhitespaceVisible(TTF_Text *text); + +/** + * Set the UTF-8 text used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to use, may be NULL. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Insert UTF-8 text into a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only insert + * at UTF-8 sequence boundaries. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_InsertTextString(TTF_Text *text, int offset, const char *string, size_t length); + +/** + * Append UTF-8 text to a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AppendTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Delete UTF-8 text from a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only delete + * at UTF-8 sequence boundaries. + * \param length the length of text to delete, in bytes, or -1 for the + * remainder of the string. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DeleteTextString(TTF_Text *text, int offset, int length); + +/** + * Get the size of a text object. + * + * The size of the text may change when the font or font style and size + * change. + * + * \param text the TTF_Text to query. + * \param w a pointer filled in with the width of the text, in pixels, may be + * NULL. + * \param h a pointer filled in with the height of the text, in pixels, may be + * NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSize(TTF_Text *text, int *w, int *h); + +/** + * Flags for TTF_SubString + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SubString + */ +typedef Uint32 TTF_SubStringFlags; + +#define TTF_SUBSTRING_DIRECTION_MASK 0x000000FF /**< The mask for the flow direction for this substring */ +#define TTF_SUBSTRING_TEXT_START 0x00000100 /**< This substring contains the beginning of the text */ +#define TTF_SUBSTRING_LINE_START 0x00000200 /**< This substring contains the beginning of line `line_index` */ +#define TTF_SUBSTRING_LINE_END 0x00000400 /**< This substring contains the end of line `line_index` */ +#define TTF_SUBSTRING_TEXT_END 0x00000800 /**< This substring contains the end of the text */ + +/** + * The representation of a substring within text. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetNextTextSubString + * \sa TTF_GetPreviousTextSubString + * \sa TTF_GetTextSubString + * \sa TTF_GetTextSubStringForLine + * \sa TTF_GetTextSubStringForPoint + * \sa TTF_GetTextSubStringsForRange + */ +typedef struct TTF_SubString +{ + TTF_SubStringFlags flags; /**< The flags for this substring */ + int offset; /**< The byte offset from the beginning of the text */ + int length; /**< The byte length starting at the offset */ + int line_index; /**< The index of the line that contains this substring */ + int cluster_index; /**< The internal cluster index, used for quickly iterating */ + SDL_Rect rect; /**< The rectangle, relative to the top left of the text, containing the substring */ +} TTF_SubString; + +/** + * Get the substring of a text object that surrounds a text offset. + * + * If `offset` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If + * `offset` is greater than or equal to the length of the text string, this + * will return a zero length substring at the end of the text with the + * TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubString(TTF_Text *text, int offset, TTF_SubString *substring); + +/** + * Get the substring of a text object that contains the given line. + * + * If `line` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If `line` + * is greater than or equal to `text->num_lines` this will return a zero + * length substring at the end of the text with the TTF_SUBSTRING_TEXT_END + * flag set. + * + * \param text the TTF_Text to query. + * \param line a zero-based line index, in the range [0 .. text->num_lines-1]. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForLine(TTF_Text *text, int line, TTF_SubString *substring); + +/** + * Get the substrings of a text object that contain a range of text. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param length the length of the range being queried, in bytes, or -1 for + * the remainder of the string. + * \param count a pointer filled in with the number of substrings returned, + * may be NULL. + * \returns a NULL terminated array of substring pointers or NULL on failure; + * call SDL_GetError() for more information. This is a single + * allocation that should be freed with SDL_free() when it is no + * longer needed. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_SubString ** SDLCALL TTF_GetTextSubStringsForRange(TTF_Text *text, int offset, int length, int *count); + +/** + * Get the portion of a text string that is closest to a point. + * + * This will return the closest substring of text to the given point. + * + * \param text the TTF_Text to query. + * \param x the x coordinate relative to the left side of the text, may be + * outside the bounds of the text area. + * \param y the y coordinate relative to the top side of the text, may be + * outside the bounds of the text area. + * \param substring a pointer filled in with the closest substring of text to + * the given point. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForPoint(TTF_Text *text, int x, int y, TTF_SubString *substring); + +/** + * Get the previous substring in a text object + * + * If called at the start of the text, this will return a zero length + * substring with the TTF_SUBSTRING_TEXT_START flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetPreviousTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *previous); + +/** + * Get the next substring in a text object + * + * If called at the end of the text, this will return a zero length substring + * with the TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \param next a pointer filled in with the next substring. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetNextTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *next); + +/** + * Update the layout of a text object. + * + * This is automatically done when the layout is requested or the text is + * rendered, but you can call this if you need more control over the timing of + * when the layout and text engine representation are updated. + * + * \param text the TTF_Text to update. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_UpdateText(TTF_Text *text); + +/** + * Destroy a text object created by a text engine. + * + * \param text the text to destroy. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyText(TTF_Text *text); + +/** + * Dispose of a previously-created font. + * + * Call this when done with a font. This function will free any resources + * associated with it. It is safe to call this function on NULL, for example + * on the result of a failed call to TTF_OpenFont(). + * + * The font is not valid after being passed to this function. String pointers + * from functions that return information on this font, such as + * TTF_GetFontFamilyName() and TTF_GetFontStyleName(), are no longer valid + * after this call, as well. + * + * \param font the font to dispose of. + * + * \threadsafety This function should not be called while any other thread is + * using the font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_OpenFont + * \sa TTF_OpenFontIO + */ +extern SDL_DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font); + +/** + * Deinitialize SDL_ttf. + * + * You must call this when done with the library, to free internal resources. + * It is safe to call this when the library isn't initialized, as it will just + * return immediately. + * + * Once you have as many quit calls as you have had successful calls to + * TTF_Init, the library will actually deinitialize. + * + * Please note that this does not automatically close any fonts that are still + * open at the time of deinitialization, and it is possibly not safe to close + * them afterwards, as parts of the library will no longer be initialized to + * deal with it. A well-written program should call TTF_CloseFont() on any + * open fonts before calling this function! + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_Quit(void); + +/** + * Check if SDL_ttf is initialized. + * + * This reports the number of times the library has been initialized by a call + * to TTF_Init(), without a paired deinitialization request from TTF_Quit(). + * + * In short: if it's greater than zero, the library is currently initialized + * and ready to work. If zero, it is not initialized. + * + * Despite the return value being a signed integer, this function should not + * return a negative number. + * + * \returns the current number of initialization calls, that need to + * eventually be paired with this many calls to TTF_Quit(). + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + * \sa TTF_Quit + */ +extern SDL_DECLSPEC int SDLCALL TTF_WasInit(void); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/INSTALL.md b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/INSTALL.md new file mode 100644 index 0000000..e11b671 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/INSTALL.md @@ -0,0 +1,35 @@ + +# Using this package + +This package contains SDL_ttf built for Xcode. + +To use this package in Xcode, drag `SDL3_ttf.framework` into your project. + +# Documentation + +An API reference and additional documentation is available at: + +https://wiki.libsdl.org/SDL3_ttf + +# Discussions + +## Discord + +You can join the official Discord server at: + +https://discord.com/invite/BwpFGBWsv8 + +## Forums/mailing lists + +You can join SDL development discussions at: + +https://discourse.libsdl.org/ + +Once you sign up, you can use the forum through the website or as a mailing list from your email client. + +## Announcement list + +You can sign up for the low traffic announcement list at: + +https://www.libsdl.org/mailing-list.php + diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/Info.plist b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/Info.plist new file mode 100644 index 0000000..f00653e Binary files /dev/null and b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/Info.plist differ diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/LICENSE.txt b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/LICENSE.txt new file mode 100644 index 0000000..52d0ed3 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/LICENSE.txt @@ -0,0 +1,17 @@ +Copyright (C) 1997-2025 Sam Lantinga + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/README.md b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/README.md new file mode 100644 index 0000000..3a6a1e9 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/README.md @@ -0,0 +1,23 @@ + +SDL_ttf 3.0 + +This library is a wrapper around the FreeType and Harfbuzz libraries, allowing you to use TrueType fonts to render text in SDL applications. + +The latest version of this library is available from GitHub: +https://github.com/libsdl-org/SDL_ttf/releases + +Installation instructions and a quick introduction is available in +[INSTALL.md](INSTALL.md) + +This library is distributed under the terms of the zlib license, +available in [LICENSE.txt](LICENSE.txt). + +This library also uses the following libraries: +- FreeType, licensed under the [FTL](https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT) +- HarfBuzz, licensed under the [MIT license](https://github.com/harfbuzz/harfbuzz/blob/main/COPYING) +- PlutoSVG, licensed under the [MIT license](https://github.com/sammycage/plutosvg/blob/master/LICENSE) +- PlutoVG, licensed under the [MIT license](https://github.com/sammycage/plutovg/blob/master/LICENSE) + +Enjoy! + +Sam Lantinga (slouken@libsdl.org) diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/SDL3_ttf b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/SDL3_ttf new file mode 100755 index 0000000..4ab354a Binary files /dev/null and b/release/frameworks/SDL3_ttf.xcframework/ios-arm64/SDL3_ttf.framework/SDL3_ttf differ diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_textengine.h b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_textengine.h new file mode 100644 index 0000000..9f5f1f0 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_textengine.h @@ -0,0 +1,181 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + + +/** + * \file SDL_textengine.h + * + * Definitions for implementations of the TTF_TextEngine interface. + */ +#ifndef SDL_TTF_TEXTENGINE_H_ +#define SDL_TTF_TEXTENGINE_H_ + +#include +#include + +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A font atlas draw command. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_DrawCommand +{ + TTF_DRAW_COMMAND_NOOP, + TTF_DRAW_COMMAND_FILL, + TTF_DRAW_COMMAND_COPY +} TTF_DrawCommand; + +/** + * A filled rectangle draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_FillOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_FILL */ + SDL_Rect rect; /**< The rectangle to fill, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ +} TTF_FillOperation; + +/** + * A texture copy draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_CopyOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_COPY */ + int text_offset; /**< The offset in the text corresponding to this glyph. + There may be multiple glyphs with the same text offset + and the next text offset might be several Unicode codepoints + later. In this case the glyphs and codepoints are grouped + together and the group bounding box is the union of the dst + rectangles for the corresponding glyphs. */ + TTF_Font *glyph_font; /**< The font containing the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + Uint32 glyph_index; /**< The glyph index of the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + SDL_Rect src; /**< The area within the glyph to be drawn */ + SDL_Rect dst; /**< The drawing coordinates of the glyph, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ + void *reserved; +} TTF_CopyOperation; + +/** + * A text engine draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef union TTF_DrawOperation +{ + TTF_DrawCommand cmd; + TTF_FillOperation fill; + TTF_CopyOperation copy; +} TTF_DrawOperation; + + +/* Private data in TTF_Text, to assist in text measurement and layout */ +typedef struct TTF_TextLayout TTF_TextLayout; + + +/* Private data in TTF_Text, available to implementations */ +struct TTF_TextData +{ + TTF_Font *font; /**< The font used by this text, read-only. */ + SDL_FColor color; /**< The color of the text, read-only. */ + + bool needs_layout_update; /**< True if the layout needs to be updated */ + TTF_TextLayout *layout; /**< Cached layout information, read-only. */ + int x; /**< The x offset of the upper left corner of this text, in pixels, read-only. */ + int y; /**< The y offset of the upper left corner of this text, in pixels, read-only. */ + int w; /**< The width of this text, in pixels, read-only. */ + int h; /**< The height of this text, in pixels, read-only. */ + int num_ops; /**< The number of drawing operations to render this text, read-only. */ + TTF_DrawOperation *ops; /**< The drawing operations used to render this text, read-only. */ + int num_clusters; /**< The number of substrings representing clusters of glyphs in the string, read-only */ + TTF_SubString *clusters; /**< Substrings representing clusters of glyphs in the string, read-only */ + + SDL_PropertiesID props; /**< Custom properties associated with this text, read-only. This field is created as-needed using TTF_GetTextProperties() and the properties may be then set and read normally */ + + bool needs_engine_update; /**< True if the engine text needs to be updated */ + TTF_TextEngine *engine; /**< The engine used to render this text, read-only. */ + void *engine_text; /**< The implementation-specific representation of this text */ +}; + +/** + * A text engine interface. + * + * This structure should be initialized using SDL_INIT_INTERFACE() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa SDL_INIT_INTERFACE + */ +struct TTF_TextEngine +{ + Uint32 version; /**< The version of this interface */ + + void *userdata; /**< User data pointer passed to callbacks */ + + /* Create a text representation from draw instructions. + * + * All fields of `text` except `internal->engine_text` will already be filled out. + * + * This function should set the `internal->engine_text` field to a non-NULL value. + * + * \param userdata the userdata pointer in this interface. + * \param text the text object being created. + */ + bool (SDLCALL *CreateText)(void *userdata, TTF_Text *text); + + /** + * Destroy a text representation. + */ + void (SDLCALL *DestroyText)(void *userdata, TTF_Text *text); + +}; + +/* Check the size of TTF_TextEngine + * + * If this assert fails, either the compiler is padding to an unexpected size, + * or the interface has been updated and this should be updated to match and + * the code using this interface should be updated to handle the old version. + */ +SDL_COMPILE_TIME_ASSERT(TTF_TextEngine_SIZE, + (sizeof(void *) == 4 && sizeof(TTF_TextEngine) == 16) || + (sizeof(void *) == 8 && sizeof(TTF_TextEngine) == 32)); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_TEXTENGINE_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_ttf.h b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_ttf.h new file mode 100644 index 0000000..b723bc7 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_ttf.h @@ -0,0 +1,2833 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* WIKI CATEGORY: SDLTTF */ + +/** + * # CategorySDLTTF + * + * Header file for SDL_ttf library + * + * This library is a wrapper around the excellent FreeType 2.0 library, + * available at: https://www.freetype.org/ + */ + +#ifndef SDL_TTF_H_ +#define SDL_TTF_H_ + +#include +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO + */ +#define SDL_TTF_MAJOR_VERSION 3 +#define SDL_TTF_MINOR_VERSION 2 +#define SDL_TTF_MICRO_VERSION 2 + +/** + * This is the version number macro for the current SDL_ttf version. + */ +#define SDL_TTF_VERSION \ + SDL_VERSIONNUM(SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION) + +/** + * This macro will evaluate to true if compiled with SDL_ttf at least X.Y.Z. + */ +#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \ + ((SDL_TTF_MAJOR_VERSION >= X) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || SDL_TTF_MICRO_VERSION >= Z)) + +/** + * This function gets the version of the dynamically linked SDL_ttf library. + * + * \returns SDL_ttf version. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_Version(void); + +/** + * Query the version of the FreeType library in use. + * + * TTF_Init() should be called before calling this function. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetFreeTypeVersion(int *major, int *minor, int *patch); + +/** + * Query the version of the HarfBuzz library in use. + * + * If HarfBuzz is not available, the version reported is 0.0.0. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetHarfBuzzVersion(int *major, int *minor, int *patch); + +/** + * The internal structure containing font information. + * + * Opaque data! + */ +typedef struct TTF_Font TTF_Font; + +/** + * Initialize SDL_ttf. + * + * You must successfully call this function before it is safe to call any + * other function in this library. + * + * It is safe to call this more than once, and each successful TTF_Init() call + * should be paired with a matching TTF_Quit() call. + * + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Quit + */ +extern SDL_DECLSPEC bool SDLCALL TTF_Init(void); + +/** + * Create a font from a file, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param file path to font file. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, float ptsize); + +/** + * Create a font from an SDL_IOStream, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * If `closeio` is true, `src` will be automatically closed once the font is + * closed. Otherwise you should close `src` yourself after closing the font. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param src an SDL_IOStream to provide a font file's data. + * \param closeio true to close `src` when the font is closed, false to leave + * it open. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIO(SDL_IOStream *src, bool closeio, float ptsize); + +/** + * Create a font with the specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_FONT_CREATE_FILENAME_STRING`: the font file to open, if an + * SDL_IOStream isn't being used. This is required if + * `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER`: an SDL_IOStream containing the + * font to be opened. This should not be closed until the font is closed. + * This is required if `TTF_PROP_FONT_CREATE_FILENAME_STRING` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER`: the offset in the iostream + * for the beginning of the font, defaults to 0. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN`: true if closing the + * font should also close the associated SDL_IOStream. + * - `TTF_PROP_FONT_CREATE_SIZE_FLOAT`: the point size of the font. Some .fon + * fonts will have several sizes embedded in the file, so the point size + * becomes the index of choosing which size. If the value is too high, the + * last indexed size will be the default. + * - `TTF_PROP_FONT_CREATE_FACE_NUMBER`: the face index of the font, if the + * font contains multiple font faces. + * - `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER`: the horizontal DPI to use + * for font rendering, defaults to + * `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER` if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER`: the vertical DPI to use for + * font rendering, defaults to `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER` + * if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_EXISTING_FONT`: an optional TTF_Font that, if set, + * will be used as the font data source and the initial size and style of + * the new font. + * + * \param props the properties to use. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_FONT_CREATE_FILENAME_STRING "SDL_ttf.font.create.filename" +#define TTF_PROP_FONT_CREATE_IOSTREAM_POINTER "SDL_ttf.font.create.iostream" +#define TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER "SDL_ttf.font.create.iostream.offset" +#define TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN "SDL_ttf.font.create.iostream.autoclose" +#define TTF_PROP_FONT_CREATE_SIZE_FLOAT "SDL_ttf.font.create.size" +#define TTF_PROP_FONT_CREATE_FACE_NUMBER "SDL_ttf.font.create.face" +#define TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER "SDL_ttf.font.create.hdpi" +#define TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER "SDL_ttf.font.create.vdpi" +#define TTF_PROP_FONT_CREATE_EXISTING_FONT "SDL_ttf.font.create.existing_font" + +/** + * Create a copy of an existing font. + * + * The copy will be distinct from the original, but will share the font file + * and have the same size and style as the original. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param existing_font the font to copy. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * original font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_CopyFont(TTF_Font *existing_font); + +/** + * Get the properties associated with a font. + * + * The following read-write properties are provided by SDL: + * + * - `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`: The FT_Stroker_LineCap value + * used when setting the font outline, defaults to + * `FT_STROKER_LINECAP_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`: The FT_Stroker_LineJoin value + * used when setting the font outline, defaults to + * `FT_STROKER_LINEJOIN_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER`: The FT_Fixed miter limit used + * when setting the font outline, defaults to 0. + * + * \param font the font to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetFontProperties(TTF_Font *font); + +#define TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER "SDL_ttf.font.outline.line_cap" +#define TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER "SDL_ttf.font.outline.line_join" +#define TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER "SDL_ttf.font.outline.miter_limit" + +/** + * Get the font generation. + * + * The generation is incremented each time font properties change that require + * rebuilding glyphs, such as style, size, etc. + * + * \param font the font to query. + * \returns the font generation or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontGeneration(TTF_Font *font); + +/** + * Add a fallback font. + * + * Add a font that will be used for glyphs that are not in the current font. + * The fallback font should have the same size and style as the current font. + * + * If there are multiple fallback fonts, they are used in the order added. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to add as a fallback. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_ClearFallbackFonts + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AddFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove a fallback font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to remove as a fallback. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_ClearFallbackFonts + */ +extern SDL_DECLSPEC void SDLCALL TTF_RemoveFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove all fallback fonts. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC void SDLCALL TTF_ClearFallbackFonts(TTF_Font *font); + +/** + * Set a font's size dynamically. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSize(TTF_Font *font, float ptsize); + +/** + * Set font size dynamically with target resolutions, in dots per inch. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + * \sa TTF_GetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSizeDPI(TTF_Font *font, float ptsize, int hdpi, int vdpi); + +/** + * Get the size of a font. + * + * \param font the font to query. + * \returns the size of the font, or 0.0f on failure; call SDL_GetError() for + * more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSize + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC float SDLCALL TTF_GetFontSize(TTF_Font *font); + +/** + * Get font target resolutions, in dots per inch. + * + * \param font the font to query. + * \param hdpi a pointer filled in with the target horizontal DPI. + * \param vdpi a pointer filled in with the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontDPI(TTF_Font *font, int *hdpi, int *vdpi); + +/** + * Font style flags for TTF_Font + * + * These are the flags which can be used to set the style of a font in + * SDL_ttf. A combination of these flags can be used with functions that set + * or query font style, such as TTF_SetFontStyle or TTF_GetFontStyle. + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + * \sa TTF_GetFontStyle + */ +typedef Uint32 TTF_FontStyleFlags; + +#define TTF_STYLE_NORMAL 0x00 /**< No special style */ +#define TTF_STYLE_BOLD 0x01 /**< Bold style */ +#define TTF_STYLE_ITALIC 0x02 /**< Italic style */ +#define TTF_STYLE_UNDERLINE 0x04 /**< Underlined text */ +#define TTF_STYLE_STRIKETHROUGH 0x08 /**< Strikethrough text */ + +/** + * Set a font's current style. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to set a new style on. + * \param style the new style values to set, OR'd together. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontStyle + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, TTF_FontStyleFlags style); + +/** + * Query a font's current style. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to query. + * \returns the current font style, as a set of bit flags. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + */ +extern SDL_DECLSPEC TTF_FontStyleFlags SDLCALL TTF_GetFontStyle(const TTF_Font *font); + +/** + * Set a font's current outline. + * + * This uses the font properties `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`, + * `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`, and + * `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER` when setting the font outline. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set a new outline on. + * \param outline positive outline value, 0 to default. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontOutline + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline); + +/** + * Query a font's current outline. + * + * \param font the font to query. + * \returns the font's current outline value. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontOutline + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font); + +/** + * Hinting flags for TTF (TrueType Fonts) + * + * This enum specifies the level of hinting to be applied to the font + * rendering. The hinting level determines how much the font's outlines are + * adjusted for better alignment on the pixel grid. + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + * \sa TTF_GetFontHinting + */ +typedef enum TTF_HintingFlags +{ + TTF_HINTING_INVALID = -1, + TTF_HINTING_NORMAL, /**< Normal hinting applies standard grid-fitting. */ + TTF_HINTING_LIGHT, /**< Light hinting applies subtle adjustments to improve rendering. */ + TTF_HINTING_MONO, /**< Monochrome hinting adjusts the font for better rendering at lower resolutions. */ + TTF_HINTING_NONE, /**< No hinting, the font is rendered without any grid-fitting. */ + TTF_HINTING_LIGHT_SUBPIXEL /**< Light hinting with subpixel rendering for more precise font edges. */ +} TTF_HintingFlags; + +/** + * Set a font's current hinter setting. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to set a new hinter setting on. + * \param hinting the new hinter setting. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontHinting + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, TTF_HintingFlags hinting); + +/** + * Query the number of faces of a font. + * + * \param font the font to query. + * \returns the number of FreeType font faces. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetNumFontFaces(const TTF_Font *font); + +/** + * Query a font's current FreeType hinter setting. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to query. + * \returns the font's current hinter value, or TTF_HINTING_INVALID if the + * font is invalid. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + */ +extern SDL_DECLSPEC TTF_HintingFlags SDLCALL TTF_GetFontHinting(const TTF_Font *font); + +/** + * Enable Signed Distance Field rendering for a font. + * + * SDF is a technique that helps fonts look sharp even when scaling and + * rotating, and requires special shader support for display. + * + * This works with Blended APIs, and generates the raw signed distance values + * in the alpha channel of the resulting texture. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set SDF support on. + * \param enabled true to enable SDF, false to disable. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSDF(TTF_Font *font, bool enabled); + +/** + * Query whether Signed Distance Field rendering is enabled for a font. + * + * \param font the font to query. + * \returns true if enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontSDF(const TTF_Font *font); + +/** + * Query a font's weight, in terms of the lightness/heaviness of the strokes. + * + * \param font the font to query. + * \returns the font's current weight. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.4.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontWeight(const TTF_Font *font); + +#define TTF_FONT_WEIGHT_THIN 100 /**< Thin (100) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_LIGHT 200 /**< ExtraLight (200) named font weight value */ +#define TTF_FONT_WEIGHT_LIGHT 300 /**< Light (300) named font weight value */ +#define TTF_FONT_WEIGHT_NORMAL 400 /**< Normal (400) named font weight value */ +#define TTF_FONT_WEIGHT_MEDIUM 500 /**< Medium (500) named font weight value */ +#define TTF_FONT_WEIGHT_SEMI_BOLD 600 /**< SemiBold (600) named font weight value */ +#define TTF_FONT_WEIGHT_BOLD 700 /**< Bold (700) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BOLD 800 /**< ExtraBold (800) named font weight value */ +#define TTF_FONT_WEIGHT_BLACK 900 /**< Black (900) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BLACK 950 /**< ExtraBlack (950) named font weight value */ + +/** + * The horizontal alignment used when rendering wrapped text. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_HorizontalAlignment +{ + TTF_HORIZONTAL_ALIGN_INVALID = -1, + TTF_HORIZONTAL_ALIGN_LEFT, + TTF_HORIZONTAL_ALIGN_CENTER, + TTF_HORIZONTAL_ALIGN_RIGHT +} TTF_HorizontalAlignment; + +/** + * Set a font's current wrap alignment option. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set a new wrap alignment option on. + * \param align the new wrap alignment option. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontWrapAlignment + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontWrapAlignment(TTF_Font *font, TTF_HorizontalAlignment align); + +/** + * Query a font's current wrap alignment option. + * + * \param font the font to query. + * \returns the font's current wrap alignment option. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontWrapAlignment + */ +extern SDL_DECLSPEC TTF_HorizontalAlignment SDLCALL TTF_GetFontWrapAlignment(const TTF_Font *font); + +/** + * Query the total height of a font. + * + * This is usually equal to point size. + * + * \param font the font to query. + * \returns the font's height. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontHeight(const TTF_Font *font); + +/** + * Query the offset from the baseline to the top of a font. + * + * This is a positive value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's ascent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontAscent(const TTF_Font *font); + +/** + * Query the offset from the baseline to the bottom of a font. + * + * This is a negative value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's descent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontDescent(const TTF_Font *font); + +/** + * Set the spacing between lines of text for a font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param lineskip the new line spacing for the font. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontLineSkip + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontLineSkip(TTF_Font *font, int lineskip); + +/** + * Query the spacing between lines of text for a font. + * + * \param font the font to query. + * \returns the font's recommended spacing. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontLineSkip + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontLineSkip(const TTF_Font *font); + +/** + * Set if kerning is enabled for a font. + * + * Newly-opened fonts default to allowing kerning. This is generally a good + * policy unless you have a strong reason to disable it, as it tends to + * produce better rendering (with kerning disabled, some fonts might render + * the word `kerning` as something that looks like `keming` for example). + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set kerning on. + * \param enabled true to enable kerning, false to disable. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontKerning + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, bool enabled); + +/** + * Query whether or not kerning is enabled for a font. + * + * \param font the font to query. + * \returns true if kerning is enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontKerning + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontKerning(const TTF_Font *font); + +/** + * Query whether a font is fixed-width. + * + * A "fixed-width" font means all glyphs are the same width across; a + * lowercase 'i' will be the same size across as a capital 'W', for example. + * This is common for terminals and text editors, and other apps that treat + * text as a grid. Most other things (WYSIWYG word processors, web pages, etc) + * are more likely to not be fixed-width in most cases. + * + * \param font the font to query. + * \returns true if the font is fixed-width, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsFixedWidth(const TTF_Font *font); + +/** + * Query whether a font is scalable or not. + * + * Scalability lets us distinguish between outline and bitmap fonts. + * + * \param font the font to query. + * \returns true if the font is scalable, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsScalable(const TTF_Font *font); + +/** + * Query a font's family name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's family name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontFamilyName(const TTF_Font *font); + +/** + * Query a font's style name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's style name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontStyleName(const TTF_Font *font); + +/** + * Direction flags + * + * The values here are chosen to match + * [hb_direction_t](https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-direction-t) + * . + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontDirection + */ +typedef enum TTF_Direction +{ + TTF_DIRECTION_INVALID = 0, + TTF_DIRECTION_LTR = 4, /**< Left to Right */ + TTF_DIRECTION_RTL, /**< Right to Left */ + TTF_DIRECTION_TTB, /**< Top to Bottom */ + TTF_DIRECTION_BTT /**< Bottom to Top */ +} TTF_Direction; + +/** + * Set the direction to be used for text shaping by a font. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping by a font. + * + * This defaults to TTF_DIRECTION_INVALID if it hasn't been set. + * + * \param font the font to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetFontDirection(TTF_Font *font); + +/** + * Convert from a 4 character string to a 32-bit tag. + * + * \param string the 4 character string to convert. + * \returns the 32-bit representation of the string. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_StringToTag(const char *string); + +/** + * Convert from a 32-bit tag to a 4 character string. + * + * \param tag the 32-bit tag to convert. + * \param string a pointer filled in with the 4 character representation of + * the tag. + * \param size the size of the buffer pointed at by string, should be at least + * 4. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC void SDLCALL TTF_TagToString(Uint32 tag, char *string, size_t size); + +/** + * Set the script to be used for text shaping by a font. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontScript(TTF_Font *font, Uint32 script); + +/** + * Get the script used for text shaping a font. + * + * \param font the font to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontScript(TTF_Font *font); + +/** + * Get the script used by a 32-bit codepoint. + * + * \param ch the character code to check. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * on success, or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function is thread-safe. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetGlyphScript(Uint32 ch); + +/** + * Set language to be used for text shaping by a font. + * + * If SDL_ttf was not built with HarfBuzz support, this function returns + * false. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to specify a language for. + * \param language_bcp47 a null-terminated string containing the desired + * language's BCP47 code. Or null to reset the value. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47); + +/** + * Check whether a glyph is provided by the font for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \returns true if font provides a glyph for this character, false if not. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontHasGlyph(TTF_Font *font, Uint32 ch); + +/** + * The type of data in a glyph image + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_ImageType +{ + TTF_IMAGE_INVALID, + TTF_IMAGE_ALPHA, /**< The color channels are white */ + TTF_IMAGE_COLOR, /**< The color channels have image data */ + TTF_IMAGE_SDF, /**< The alpha channel has signed distance field information */ +} TTF_ImageType; + +/** + * Get the pixel image for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImage(TTF_Font *font, Uint32 ch, TTF_ImageType *image_type); + +/** + * Get the pixel image for a character index. + * + * This is useful for text engine implementations, which can call this with + * the `glyph_index` in a TTF_CopyOperation + * + * \param font the font to query. + * \param glyph_index the index of the glyph to return. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImageForIndex(TTF_Font *font, Uint32 glyph_index, TTF_ImageType *image_type); + +/** + * Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint. + * + * To understand what these metrics mean, here is a useful link: + * + * https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param minx a pointer filled in with the minimum x coordinate of the glyph + * from the left edge of its bounding box. This value may be + * negative. + * \param maxx a pointer filled in with the maximum x coordinate of the glyph + * from the left edge of its bounding box. + * \param miny a pointer filled in with the minimum y coordinate of the glyph + * from the bottom edge of its bounding box. This value may be + * negative. + * \param maxy a pointer filled in with the maximum y coordinate of the glyph + * from the bottom edge of its bounding box. + * \param advance a pointer filled in with the distance to the next glyph from + * the left edge of this glyph's bounding box. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphMetrics(TTF_Font *font, Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance); + +/** + * Query the kerning size between the glyphs of two UNICODE codepoints. + * + * \param font the font to query. + * \param previous_ch the previous codepoint. + * \param ch the current codepoint. + * \param kerning a pointer filled in with the kerning size between the two + * glyphs, in pixels, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphKerning(TTF_Font *font, Uint32 previous_ch, Uint32 ch, int *kerning); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSize(TTF_Font *font, const char *text, size_t length, int *w, int *h); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param wrap_width the maximum width or 0 to wrap on newline characters. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSizeWrapped(TTF_Font *font, const char *text, size_t length, int wrap_width, int *w, int *h); + +/** + * Calculate how much of a UTF-8 string will fit in a given width. + * + * This reports the number of characters that can be rendered before reaching + * `max_width`. + * + * This does not need to render the string to do this calculation. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param max_width maximum width, in pixels, available for the string, or 0 + * for unbounded width. + * \param measured_width a pointer filled in with the width, in pixels, of the + * string that will fit, may be NULL. + * \param measured_length a pointer filled in with the length, in bytes, of + * the string that will fit, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_MeasureString(TTF_Font *font, const char *text, size_t length, int max_width, int *measured_width, size_t *measured_length); + +/** + * Render UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Solid_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrapLength the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrapLength); + +/** + * Render a single 32-bit glyph at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Shaded, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Shaded_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + +/** + * Render UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Blended_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_LCD_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_Blended. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_Blended_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_Blended. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_LCD(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + + +/** + * A text engine used to create text objects. + * + * This is a public interface that can be used by applications and libraries + * to perform customize rendering with text objects. See + * for details. + * + * There are three text engines provided with the library: + * + * - Drawing to an SDL_Surface, created with TTF_CreateSurfaceTextEngine() + * - Drawing with an SDL 2D renderer, created with + * TTF_CreateRendererTextEngine() + * - Drawing with the SDL GPU API, created with TTF_CreateGPUTextEngine() + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextEngine TTF_TextEngine; + +/** + * Internal data for TTF_Text + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextData TTF_TextData; + +/** + * Text created with TTF_CreateText() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + * \sa TTF_GetTextProperties + * \sa TTF_DestroyText + */ +typedef struct TTF_Text +{ + char *text; /**< A copy of the UTF-8 string that this text object represents, useful for layout, debugging and retrieving substring text. This is updated when the text object is modified and will be freed automatically when the object is destroyed. */ + int num_lines; /**< The number of lines in the text, 0 if it's empty */ + + int refcount; /**< Application reference count, used when freeing surface */ + + TTF_TextData *internal; /**< Private */ + +} TTF_Text; + +/** + * Create a text engine for drawing text on SDL surfaces. + * + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroySurfaceTextEngine + * \sa TTF_DrawSurfaceText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateSurfaceTextEngine(void); + +/** + * Draw text to an SDL surface. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateSurfaceTextEngine(). + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \param surface the surface to draw on. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawSurfaceText(TTF_Text *text, int x, int y, SDL_Surface *surface); + +/** + * Destroy a text engine created for drawing text on SDL surfaces. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateSurfaceTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroySurfaceTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text on an SDL renderer. + * + * \param renderer the renderer to use for creating textures and drawing text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + * \sa TTF_CreateRendererTextEngineWithProperties + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngine(SDL_Renderer *renderer); + +/** + * Create a text engine for drawing text on an SDL renderer, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER`: the renderer to use for + * creating textures and drawing text + * - `TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the + * texture atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER "SDL_ttf.renderer_text_engine.create.renderer" +#define TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.renderer_text_engine.create.atlas_texture_size" + +/** + * Draw text to an SDL renderer. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateRendererTextEngine(), and will draw using the renderer passed to + * that function. + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawRendererText(TTF_Text *text, float x, float y); + +/** + * Destroy a text engine created for drawing text on an SDL renderer. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateRendererTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyRendererTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text with the SDL GPU API. + * + * \param device the SDL_GPUDevice to use for creating textures and drawing + * text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngineWithProperties + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngine(SDL_GPUDevice *device); + +/** + * Create a text engine for drawing text with the SDL GPU API, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_GPU_TEXT_ENGINE_DEVICE`: the SDL_GPUDevice to use for creating + * textures and drawing text. + * - `TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the texture + * atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_GPU_TEXT_ENGINE_DEVICE "SDL_ttf.gpu_text_engine.create.device" +#define TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.gpu_text_engine.create.atlas_texture_size" + +/** + * Draw sequence returned by TTF_GetGPUTextDrawData + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextDrawData + */ +typedef struct TTF_GPUAtlasDrawSequence +{ + SDL_GPUTexture *atlas_texture; /**< Texture atlas that stores the glyphs */ + SDL_FPoint *xy; /**< An array of vertex positions */ + SDL_FPoint *uv; /**< An array of normalized texture coordinates for each vertex */ + int num_vertices; /**< Number of vertices */ + int *indices; /**< An array of indices into the 'vertices' arrays */ + int num_indices; /**< Number of indices */ + TTF_ImageType image_type; /**< The image type of this draw sequence */ + + struct TTF_GPUAtlasDrawSequence *next; /**< The next sequence (will be NULL in case of the last sequence) */ +} TTF_GPUAtlasDrawSequence; + +/** + * Get the geometry data needed for drawing the text. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateGPUTextEngine(). + * + * The positive X-axis is taken towards the right and the positive Y-axis is + * taken upwards for both the vertex and the texture coordinates, i.e, it + * follows the same convention used by the SDL_GPU API. If you want to use a + * different coordinate system you will need to transform the vertices + * yourself. + * + * If the text looks blocky use linear filtering. + * + * \param text the text to draw. + * \returns a NULL terminated linked list of TTF_GPUAtlasDrawSequence objects + * or NULL if the passed text is empty or in case of failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC TTF_GPUAtlasDrawSequence * SDLCALL TTF_GetGPUTextDrawData(TTF_Text *text); + +/** + * Destroy a text engine created for drawing text with the SDL GPU API. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyGPUTextEngine(TTF_TextEngine *engine); + +/** + * The winding order of the vertices returned by TTF_GetGPUTextDrawData + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_GPUTextEngineWinding +{ + TTF_GPU_TEXTENGINE_WINDING_INVALID = -1, + TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE, + TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE +} TTF_GPUTextEngineWinding; + +/** + * Sets the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \param winding the new winding order option. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextEngineWinding + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetGPUTextEngineWinding(TTF_TextEngine *engine, TTF_GPUTextEngineWinding winding); + +/** + * Get the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \returns the winding order used by the GPU text engine or + * TTF_GPU_TEXTENGINE_WINDING_INVALID in case of error. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetGPUTextEngineWinding + */ +extern SDL_DECLSPEC TTF_GPUTextEngineWinding SDLCALL TTF_GetGPUTextEngineWinding(const TTF_TextEngine *engine); + +/** + * Create a text object from UTF-8 text and a text engine. + * + * \param engine the text engine to use when creating the text object, may be + * NULL. + * \param font the font to render with. + * \param text the text to use, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns a TTF_Text object or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font and text engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyText + */ +extern SDL_DECLSPEC TTF_Text * SDLCALL TTF_CreateText(TTF_TextEngine *engine, TTF_Font *font, const char *text, size_t length); + +/** + * Get the properties associated with a text object. + * + * \param text the TTF_Text to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetTextProperties(TTF_Text *text); + +/** + * Set the text engine used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param engine the text engine to use for drawing. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextEngine + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextEngine(TTF_Text *text, TTF_TextEngine *engine); + +/** + * Get the text engine used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_TextEngine used by the text on success or NULL on failure; + * call SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextEngine + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_GetTextEngine(TTF_Text *text); + +/** + * Set the font used by a text object. + * + * When a text object has a font, any changes to the font will automatically + * regenerate the text. If you set the font to NULL, the text will continue to + * render but changes to the font will no longer affect the text. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param font the font to use, may be NULL. + * \returns false if the text pointer is null; otherwise, true. call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextFont(TTF_Text *text, TTF_Font *font); + +/** + * Get the font used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_Font used by the text on success or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_GetTextFont(TTF_Text *text); + +/** + * Set the direction to be used for text shaping a text object. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * \param text the text to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextDirection(TTF_Text *text, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping a text object. + * + * This defaults to the direction of the font used by the text object. + * + * \param text the text to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetTextDirection(TTF_Text *text); + +/** + * Set the script to be used for text shaping a text object. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * \param text the text to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextScript(TTF_Text *text, Uint32 script); + +/** + * Get the script used for text shaping a text object. + * + * This defaults to the script of the font used by the text object. + * + * \param text the text to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set on either the text object or the + * font. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetTextScript(TTF_Text *text); + +/** + * Set the color of a text object. + * + * The default text color is white (255, 255, 255, 255). + * + * \param text the TTF_Text to modify. + * \param r the red color value in the range of 0-255. + * \param g the green color value in the range of 0-255. + * \param b the blue color value in the range of 0-255. + * \param a the alpha value in the range of 0-255. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColor(TTF_Text *text, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + +/** + * Set the color of a text object. + * + * The default text color is white (1.0f, 1.0f, 1.0f, 1.0f). + * + * \param text the TTF_Text to modify. + * \param r the red color value, normally in the range of 0-1. + * \param g the green color value, normally in the range of 0-1. + * \param b the blue color value, normally in the range of 0-1. + * \param a the alpha value in the range of 0-1. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColorFloat(TTF_Text *text, float r, float g, float b, float a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value in the range of + * 0-255, may be NULL. + * \param g a pointer filled in with the green color value in the range of + * 0-255, may be NULL. + * \param b a pointer filled in with the blue color value in the range of + * 0-255, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-255, + * may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColor(TTF_Text *text, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value, normally in the + * range of 0-1, may be NULL. + * \param g a pointer filled in with the green color value, normally in the + * range of 0-1, may be NULL. + * \param b a pointer filled in with the blue color value, normally in the + * range of 0-1, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-1, may + * be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColorFloat(TTF_Text *text, float *r, float *g, float *b, float *a); + +/** + * Set the position of a text object. + * + * This can be used to position multiple text objects within a single wrapping + * text area. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param x the x offset of the upper left corner of this text in pixels. + * \param y the y offset of the upper left corner of this text in pixels. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextPosition(TTF_Text *text, int x, int y); + +/** + * Get the position of a text object. + * + * \param text the TTF_Text to query. + * \param x a pointer filled in with the x offset of the upper left corner of + * this text in pixels, may be NULL. + * \param y a pointer filled in with the y offset of the upper left corner of + * this text in pixels, may be NULL. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextPosition(TTF_Text *text, int *x, int *y); + +/** + * Set whether wrapping is enabled on a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param wrap_width the maximum width in pixels, 0 to wrap on newline + * characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWidth(TTF_Text *text, int wrap_width); + +/** + * Get whether wrapping is enabled on a text object. + * + * \param text the TTF_Text to query. + * \param wrap_width a pointer filled in with the maximum width in pixels or 0 + * if the text is being wrapped on newline characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextWrapWidth(TTF_Text *text, int *wrap_width); + +/** + * Set whether whitespace should be visible when wrapping a text object. + * + * If the whitespace is visible, it will take up space for purposes of + * alignment and wrapping. This is good for editing, but looks better when + * centered or aligned if whitespace around line wrapping is hidden. This + * defaults false. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param visible true to show whitespace when wrapping text, false to hide + * it. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWhitespaceVisible(TTF_Text *text, bool visible); + +/** + * Return whether whitespace is shown when wrapping a text object. + * + * \param text the TTF_Text to query. + * \returns true if whitespace is shown when wrapping text, or false + * otherwise. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_TextWrapWhitespaceVisible(TTF_Text *text); + +/** + * Set the UTF-8 text used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to use, may be NULL. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Insert UTF-8 text into a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only insert + * at UTF-8 sequence boundaries. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_InsertTextString(TTF_Text *text, int offset, const char *string, size_t length); + +/** + * Append UTF-8 text to a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AppendTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Delete UTF-8 text from a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only delete + * at UTF-8 sequence boundaries. + * \param length the length of text to delete, in bytes, or -1 for the + * remainder of the string. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DeleteTextString(TTF_Text *text, int offset, int length); + +/** + * Get the size of a text object. + * + * The size of the text may change when the font or font style and size + * change. + * + * \param text the TTF_Text to query. + * \param w a pointer filled in with the width of the text, in pixels, may be + * NULL. + * \param h a pointer filled in with the height of the text, in pixels, may be + * NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSize(TTF_Text *text, int *w, int *h); + +/** + * Flags for TTF_SubString + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SubString + */ +typedef Uint32 TTF_SubStringFlags; + +#define TTF_SUBSTRING_DIRECTION_MASK 0x000000FF /**< The mask for the flow direction for this substring */ +#define TTF_SUBSTRING_TEXT_START 0x00000100 /**< This substring contains the beginning of the text */ +#define TTF_SUBSTRING_LINE_START 0x00000200 /**< This substring contains the beginning of line `line_index` */ +#define TTF_SUBSTRING_LINE_END 0x00000400 /**< This substring contains the end of line `line_index` */ +#define TTF_SUBSTRING_TEXT_END 0x00000800 /**< This substring contains the end of the text */ + +/** + * The representation of a substring within text. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetNextTextSubString + * \sa TTF_GetPreviousTextSubString + * \sa TTF_GetTextSubString + * \sa TTF_GetTextSubStringForLine + * \sa TTF_GetTextSubStringForPoint + * \sa TTF_GetTextSubStringsForRange + */ +typedef struct TTF_SubString +{ + TTF_SubStringFlags flags; /**< The flags for this substring */ + int offset; /**< The byte offset from the beginning of the text */ + int length; /**< The byte length starting at the offset */ + int line_index; /**< The index of the line that contains this substring */ + int cluster_index; /**< The internal cluster index, used for quickly iterating */ + SDL_Rect rect; /**< The rectangle, relative to the top left of the text, containing the substring */ +} TTF_SubString; + +/** + * Get the substring of a text object that surrounds a text offset. + * + * If `offset` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If + * `offset` is greater than or equal to the length of the text string, this + * will return a zero length substring at the end of the text with the + * TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubString(TTF_Text *text, int offset, TTF_SubString *substring); + +/** + * Get the substring of a text object that contains the given line. + * + * If `line` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If `line` + * is greater than or equal to `text->num_lines` this will return a zero + * length substring at the end of the text with the TTF_SUBSTRING_TEXT_END + * flag set. + * + * \param text the TTF_Text to query. + * \param line a zero-based line index, in the range [0 .. text->num_lines-1]. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForLine(TTF_Text *text, int line, TTF_SubString *substring); + +/** + * Get the substrings of a text object that contain a range of text. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param length the length of the range being queried, in bytes, or -1 for + * the remainder of the string. + * \param count a pointer filled in with the number of substrings returned, + * may be NULL. + * \returns a NULL terminated array of substring pointers or NULL on failure; + * call SDL_GetError() for more information. This is a single + * allocation that should be freed with SDL_free() when it is no + * longer needed. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_SubString ** SDLCALL TTF_GetTextSubStringsForRange(TTF_Text *text, int offset, int length, int *count); + +/** + * Get the portion of a text string that is closest to a point. + * + * This will return the closest substring of text to the given point. + * + * \param text the TTF_Text to query. + * \param x the x coordinate relative to the left side of the text, may be + * outside the bounds of the text area. + * \param y the y coordinate relative to the top side of the text, may be + * outside the bounds of the text area. + * \param substring a pointer filled in with the closest substring of text to + * the given point. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForPoint(TTF_Text *text, int x, int y, TTF_SubString *substring); + +/** + * Get the previous substring in a text object + * + * If called at the start of the text, this will return a zero length + * substring with the TTF_SUBSTRING_TEXT_START flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetPreviousTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *previous); + +/** + * Get the next substring in a text object + * + * If called at the end of the text, this will return a zero length substring + * with the TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \param next a pointer filled in with the next substring. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetNextTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *next); + +/** + * Update the layout of a text object. + * + * This is automatically done when the layout is requested or the text is + * rendered, but you can call this if you need more control over the timing of + * when the layout and text engine representation are updated. + * + * \param text the TTF_Text to update. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_UpdateText(TTF_Text *text); + +/** + * Destroy a text object created by a text engine. + * + * \param text the text to destroy. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyText(TTF_Text *text); + +/** + * Dispose of a previously-created font. + * + * Call this when done with a font. This function will free any resources + * associated with it. It is safe to call this function on NULL, for example + * on the result of a failed call to TTF_OpenFont(). + * + * The font is not valid after being passed to this function. String pointers + * from functions that return information on this font, such as + * TTF_GetFontFamilyName() and TTF_GetFontStyleName(), are no longer valid + * after this call, as well. + * + * \param font the font to dispose of. + * + * \threadsafety This function should not be called while any other thread is + * using the font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_OpenFont + * \sa TTF_OpenFontIO + */ +extern SDL_DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font); + +/** + * Deinitialize SDL_ttf. + * + * You must call this when done with the library, to free internal resources. + * It is safe to call this when the library isn't initialized, as it will just + * return immediately. + * + * Once you have as many quit calls as you have had successful calls to + * TTF_Init, the library will actually deinitialize. + * + * Please note that this does not automatically close any fonts that are still + * open at the time of deinitialization, and it is possibly not safe to close + * them afterwards, as parts of the library will no longer be initialized to + * deal with it. A well-written program should call TTF_CloseFont() on any + * open fonts before calling this function! + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_Quit(void); + +/** + * Check if SDL_ttf is initialized. + * + * This reports the number of times the library has been initialized by a call + * to TTF_Init(), without a paired deinitialization request from TTF_Quit(). + * + * In short: if it's greater than zero, the library is currently initialized + * and ready to work. If zero, it is not initialized. + * + * Despite the return value being a signed integer, this function should not + * return a negative number. + * + * \returns the current number of initialization calls, that need to + * eventually be paired with this many calls to TTF_Quit(). + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + * \sa TTF_Quit + */ +extern SDL_DECLSPEC int SDLCALL TTF_WasInit(void); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/INSTALL.md b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/INSTALL.md new file mode 100644 index 0000000..e11b671 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/INSTALL.md @@ -0,0 +1,35 @@ + +# Using this package + +This package contains SDL_ttf built for Xcode. + +To use this package in Xcode, drag `SDL3_ttf.framework` into your project. + +# Documentation + +An API reference and additional documentation is available at: + +https://wiki.libsdl.org/SDL3_ttf + +# Discussions + +## Discord + +You can join the official Discord server at: + +https://discord.com/invite/BwpFGBWsv8 + +## Forums/mailing lists + +You can join SDL development discussions at: + +https://discourse.libsdl.org/ + +Once you sign up, you can use the forum through the website or as a mailing list from your email client. + +## Announcement list + +You can sign up for the low traffic announcement list at: + +https://www.libsdl.org/mailing-list.php + diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/Info.plist b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/Info.plist new file mode 100644 index 0000000..7de83f2 Binary files /dev/null and b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/Info.plist differ diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/LICENSE.txt b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/LICENSE.txt new file mode 100644 index 0000000..52d0ed3 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/LICENSE.txt @@ -0,0 +1,17 @@ +Copyright (C) 1997-2025 Sam Lantinga + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/README.md b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/README.md new file mode 100644 index 0000000..3a6a1e9 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/README.md @@ -0,0 +1,23 @@ + +SDL_ttf 3.0 + +This library is a wrapper around the FreeType and Harfbuzz libraries, allowing you to use TrueType fonts to render text in SDL applications. + +The latest version of this library is available from GitHub: +https://github.com/libsdl-org/SDL_ttf/releases + +Installation instructions and a quick introduction is available in +[INSTALL.md](INSTALL.md) + +This library is distributed under the terms of the zlib license, +available in [LICENSE.txt](LICENSE.txt). + +This library also uses the following libraries: +- FreeType, licensed under the [FTL](https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT) +- HarfBuzz, licensed under the [MIT license](https://github.com/harfbuzz/harfbuzz/blob/main/COPYING) +- PlutoSVG, licensed under the [MIT license](https://github.com/sammycage/plutosvg/blob/master/LICENSE) +- PlutoVG, licensed under the [MIT license](https://github.com/sammycage/plutovg/blob/master/LICENSE) + +Enjoy! + +Sam Lantinga (slouken@libsdl.org) diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/SDL3_ttf b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/SDL3_ttf new file mode 100755 index 0000000..f4efd68 Binary files /dev/null and b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/SDL3_ttf differ diff --git a/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/_CodeSignature/CodeResources b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/_CodeSignature/CodeResources new file mode 100644 index 0000000..87350d0 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/ios-arm64_x86_64-simulator/SDL3_ttf.framework/_CodeSignature/CodeResources @@ -0,0 +1,179 @@ + + + + + files + + CMake/SDL3_ttfConfig.cmake + + V6UpWQTvr/puOrlm1sgAs6fktNA= + + CMake/SDL3_ttfConfigVersion.cmake + + WW2xmNHZyYr9y3/8uAylJuutcPw= + + Headers/SDL_textengine.h + + 7QAtKpC/pLIq6TK3F59Ax1hg3tc= + + Headers/SDL_ttf.h + + 90S4SFzJy1lUuMotaCRWpTbzRa4= + + INSTALL.md + + 3kA+9HE5dF7+nyypVt5YOfU+Uho= + + Info.plist + + 9F72T63xvwi9u+kC0p9N011q3IM= + + LICENSE.txt + + dp6e8JHkl0CrYD+oe2IXZfWB/iw= + + README.md + + lm034L4zWKPElKb9O2dmehurfFQ= + + + files2 + + CMake/SDL3_ttfConfig.cmake + + hash2 + + VpwUT/D8TjpLXBguVImWqsMkqni9HXiIzx91C92Krqc= + + + CMake/SDL3_ttfConfigVersion.cmake + + hash2 + + tb1RnDTj72GQOzcXp6FPtiqW8tSD886UyUY09c1Ms/U= + + + Headers/SDL_textengine.h + + hash2 + + Uk27FTzsWoYySpKM1gkwCB/svSxscGViuMzca93gLP8= + + + Headers/SDL_ttf.h + + hash2 + + 6bsCCUp3Uc3tCp+0Xxw7Tt01+UV8bra5YN1dFjpRBL0= + + + INSTALL.md + + hash2 + + Jq9GEmdnFRmUTNnYYZZ+5mFqqrMelD86Gthhyi2kGJQ= + + + LICENSE.txt + + hash2 + + eCbsoKD35ZHzjdhE4geiAKrIGlmyDYoww6+MYoKvE+Y= + + + README.md + + hash2 + + 6aipppbEU7MEd3x9OHnKqAGyFXVYiSAL8X8lm271U00= + + + + rules + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^version.plist$ + + + rules2 + + .*\.dSYM($|/) + + weight + 11 + + ^(.*/)?\.DS_Store$ + + omit + + weight + 2000 + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^Info\.plist$ + + omit + + weight + 20 + + ^PkgInfo$ + + omit + + weight + 20 + + ^embedded\.provisionprofile$ + + weight + 20 + + ^version\.plist$ + + weight + 20 + + + + diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Headers b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Headers new file mode 120000 index 0000000..a177d2a --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers \ No newline at end of file diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Resources b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Resources new file mode 120000 index 0000000..953ee36 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Resources @@ -0,0 +1 @@ +Versions/Current/Resources \ No newline at end of file diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/SDL3_ttf b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/SDL3_ttf new file mode 120000 index 0000000..aaa76e3 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/SDL3_ttf @@ -0,0 +1 @@ +Versions/Current/SDL3_ttf \ No newline at end of file diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Headers/SDL_textengine.h b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Headers/SDL_textengine.h new file mode 100644 index 0000000..9f5f1f0 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Headers/SDL_textengine.h @@ -0,0 +1,181 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + + +/** + * \file SDL_textengine.h + * + * Definitions for implementations of the TTF_TextEngine interface. + */ +#ifndef SDL_TTF_TEXTENGINE_H_ +#define SDL_TTF_TEXTENGINE_H_ + +#include +#include + +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A font atlas draw command. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_DrawCommand +{ + TTF_DRAW_COMMAND_NOOP, + TTF_DRAW_COMMAND_FILL, + TTF_DRAW_COMMAND_COPY +} TTF_DrawCommand; + +/** + * A filled rectangle draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_FillOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_FILL */ + SDL_Rect rect; /**< The rectangle to fill, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ +} TTF_FillOperation; + +/** + * A texture copy draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_CopyOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_COPY */ + int text_offset; /**< The offset in the text corresponding to this glyph. + There may be multiple glyphs with the same text offset + and the next text offset might be several Unicode codepoints + later. In this case the glyphs and codepoints are grouped + together and the group bounding box is the union of the dst + rectangles for the corresponding glyphs. */ + TTF_Font *glyph_font; /**< The font containing the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + Uint32 glyph_index; /**< The glyph index of the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + SDL_Rect src; /**< The area within the glyph to be drawn */ + SDL_Rect dst; /**< The drawing coordinates of the glyph, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ + void *reserved; +} TTF_CopyOperation; + +/** + * A text engine draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef union TTF_DrawOperation +{ + TTF_DrawCommand cmd; + TTF_FillOperation fill; + TTF_CopyOperation copy; +} TTF_DrawOperation; + + +/* Private data in TTF_Text, to assist in text measurement and layout */ +typedef struct TTF_TextLayout TTF_TextLayout; + + +/* Private data in TTF_Text, available to implementations */ +struct TTF_TextData +{ + TTF_Font *font; /**< The font used by this text, read-only. */ + SDL_FColor color; /**< The color of the text, read-only. */ + + bool needs_layout_update; /**< True if the layout needs to be updated */ + TTF_TextLayout *layout; /**< Cached layout information, read-only. */ + int x; /**< The x offset of the upper left corner of this text, in pixels, read-only. */ + int y; /**< The y offset of the upper left corner of this text, in pixels, read-only. */ + int w; /**< The width of this text, in pixels, read-only. */ + int h; /**< The height of this text, in pixels, read-only. */ + int num_ops; /**< The number of drawing operations to render this text, read-only. */ + TTF_DrawOperation *ops; /**< The drawing operations used to render this text, read-only. */ + int num_clusters; /**< The number of substrings representing clusters of glyphs in the string, read-only */ + TTF_SubString *clusters; /**< Substrings representing clusters of glyphs in the string, read-only */ + + SDL_PropertiesID props; /**< Custom properties associated with this text, read-only. This field is created as-needed using TTF_GetTextProperties() and the properties may be then set and read normally */ + + bool needs_engine_update; /**< True if the engine text needs to be updated */ + TTF_TextEngine *engine; /**< The engine used to render this text, read-only. */ + void *engine_text; /**< The implementation-specific representation of this text */ +}; + +/** + * A text engine interface. + * + * This structure should be initialized using SDL_INIT_INTERFACE() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa SDL_INIT_INTERFACE + */ +struct TTF_TextEngine +{ + Uint32 version; /**< The version of this interface */ + + void *userdata; /**< User data pointer passed to callbacks */ + + /* Create a text representation from draw instructions. + * + * All fields of `text` except `internal->engine_text` will already be filled out. + * + * This function should set the `internal->engine_text` field to a non-NULL value. + * + * \param userdata the userdata pointer in this interface. + * \param text the text object being created. + */ + bool (SDLCALL *CreateText)(void *userdata, TTF_Text *text); + + /** + * Destroy a text representation. + */ + void (SDLCALL *DestroyText)(void *userdata, TTF_Text *text); + +}; + +/* Check the size of TTF_TextEngine + * + * If this assert fails, either the compiler is padding to an unexpected size, + * or the interface has been updated and this should be updated to match and + * the code using this interface should be updated to handle the old version. + */ +SDL_COMPILE_TIME_ASSERT(TTF_TextEngine_SIZE, + (sizeof(void *) == 4 && sizeof(TTF_TextEngine) == 16) || + (sizeof(void *) == 8 && sizeof(TTF_TextEngine) == 32)); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_TEXTENGINE_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Headers/SDL_ttf.h b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Headers/SDL_ttf.h new file mode 100644 index 0000000..b723bc7 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Headers/SDL_ttf.h @@ -0,0 +1,2833 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* WIKI CATEGORY: SDLTTF */ + +/** + * # CategorySDLTTF + * + * Header file for SDL_ttf library + * + * This library is a wrapper around the excellent FreeType 2.0 library, + * available at: https://www.freetype.org/ + */ + +#ifndef SDL_TTF_H_ +#define SDL_TTF_H_ + +#include +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO + */ +#define SDL_TTF_MAJOR_VERSION 3 +#define SDL_TTF_MINOR_VERSION 2 +#define SDL_TTF_MICRO_VERSION 2 + +/** + * This is the version number macro for the current SDL_ttf version. + */ +#define SDL_TTF_VERSION \ + SDL_VERSIONNUM(SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION) + +/** + * This macro will evaluate to true if compiled with SDL_ttf at least X.Y.Z. + */ +#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \ + ((SDL_TTF_MAJOR_VERSION >= X) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || SDL_TTF_MICRO_VERSION >= Z)) + +/** + * This function gets the version of the dynamically linked SDL_ttf library. + * + * \returns SDL_ttf version. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_Version(void); + +/** + * Query the version of the FreeType library in use. + * + * TTF_Init() should be called before calling this function. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetFreeTypeVersion(int *major, int *minor, int *patch); + +/** + * Query the version of the HarfBuzz library in use. + * + * If HarfBuzz is not available, the version reported is 0.0.0. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetHarfBuzzVersion(int *major, int *minor, int *patch); + +/** + * The internal structure containing font information. + * + * Opaque data! + */ +typedef struct TTF_Font TTF_Font; + +/** + * Initialize SDL_ttf. + * + * You must successfully call this function before it is safe to call any + * other function in this library. + * + * It is safe to call this more than once, and each successful TTF_Init() call + * should be paired with a matching TTF_Quit() call. + * + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Quit + */ +extern SDL_DECLSPEC bool SDLCALL TTF_Init(void); + +/** + * Create a font from a file, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param file path to font file. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, float ptsize); + +/** + * Create a font from an SDL_IOStream, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * If `closeio` is true, `src` will be automatically closed once the font is + * closed. Otherwise you should close `src` yourself after closing the font. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param src an SDL_IOStream to provide a font file's data. + * \param closeio true to close `src` when the font is closed, false to leave + * it open. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIO(SDL_IOStream *src, bool closeio, float ptsize); + +/** + * Create a font with the specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_FONT_CREATE_FILENAME_STRING`: the font file to open, if an + * SDL_IOStream isn't being used. This is required if + * `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER`: an SDL_IOStream containing the + * font to be opened. This should not be closed until the font is closed. + * This is required if `TTF_PROP_FONT_CREATE_FILENAME_STRING` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER`: the offset in the iostream + * for the beginning of the font, defaults to 0. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN`: true if closing the + * font should also close the associated SDL_IOStream. + * - `TTF_PROP_FONT_CREATE_SIZE_FLOAT`: the point size of the font. Some .fon + * fonts will have several sizes embedded in the file, so the point size + * becomes the index of choosing which size. If the value is too high, the + * last indexed size will be the default. + * - `TTF_PROP_FONT_CREATE_FACE_NUMBER`: the face index of the font, if the + * font contains multiple font faces. + * - `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER`: the horizontal DPI to use + * for font rendering, defaults to + * `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER` if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER`: the vertical DPI to use for + * font rendering, defaults to `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER` + * if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_EXISTING_FONT`: an optional TTF_Font that, if set, + * will be used as the font data source and the initial size and style of + * the new font. + * + * \param props the properties to use. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_FONT_CREATE_FILENAME_STRING "SDL_ttf.font.create.filename" +#define TTF_PROP_FONT_CREATE_IOSTREAM_POINTER "SDL_ttf.font.create.iostream" +#define TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER "SDL_ttf.font.create.iostream.offset" +#define TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN "SDL_ttf.font.create.iostream.autoclose" +#define TTF_PROP_FONT_CREATE_SIZE_FLOAT "SDL_ttf.font.create.size" +#define TTF_PROP_FONT_CREATE_FACE_NUMBER "SDL_ttf.font.create.face" +#define TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER "SDL_ttf.font.create.hdpi" +#define TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER "SDL_ttf.font.create.vdpi" +#define TTF_PROP_FONT_CREATE_EXISTING_FONT "SDL_ttf.font.create.existing_font" + +/** + * Create a copy of an existing font. + * + * The copy will be distinct from the original, but will share the font file + * and have the same size and style as the original. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param existing_font the font to copy. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * original font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_CopyFont(TTF_Font *existing_font); + +/** + * Get the properties associated with a font. + * + * The following read-write properties are provided by SDL: + * + * - `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`: The FT_Stroker_LineCap value + * used when setting the font outline, defaults to + * `FT_STROKER_LINECAP_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`: The FT_Stroker_LineJoin value + * used when setting the font outline, defaults to + * `FT_STROKER_LINEJOIN_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER`: The FT_Fixed miter limit used + * when setting the font outline, defaults to 0. + * + * \param font the font to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetFontProperties(TTF_Font *font); + +#define TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER "SDL_ttf.font.outline.line_cap" +#define TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER "SDL_ttf.font.outline.line_join" +#define TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER "SDL_ttf.font.outline.miter_limit" + +/** + * Get the font generation. + * + * The generation is incremented each time font properties change that require + * rebuilding glyphs, such as style, size, etc. + * + * \param font the font to query. + * \returns the font generation or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontGeneration(TTF_Font *font); + +/** + * Add a fallback font. + * + * Add a font that will be used for glyphs that are not in the current font. + * The fallback font should have the same size and style as the current font. + * + * If there are multiple fallback fonts, they are used in the order added. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to add as a fallback. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_ClearFallbackFonts + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AddFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove a fallback font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to remove as a fallback. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_ClearFallbackFonts + */ +extern SDL_DECLSPEC void SDLCALL TTF_RemoveFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove all fallback fonts. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC void SDLCALL TTF_ClearFallbackFonts(TTF_Font *font); + +/** + * Set a font's size dynamically. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSize(TTF_Font *font, float ptsize); + +/** + * Set font size dynamically with target resolutions, in dots per inch. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + * \sa TTF_GetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSizeDPI(TTF_Font *font, float ptsize, int hdpi, int vdpi); + +/** + * Get the size of a font. + * + * \param font the font to query. + * \returns the size of the font, or 0.0f on failure; call SDL_GetError() for + * more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSize + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC float SDLCALL TTF_GetFontSize(TTF_Font *font); + +/** + * Get font target resolutions, in dots per inch. + * + * \param font the font to query. + * \param hdpi a pointer filled in with the target horizontal DPI. + * \param vdpi a pointer filled in with the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontDPI(TTF_Font *font, int *hdpi, int *vdpi); + +/** + * Font style flags for TTF_Font + * + * These are the flags which can be used to set the style of a font in + * SDL_ttf. A combination of these flags can be used with functions that set + * or query font style, such as TTF_SetFontStyle or TTF_GetFontStyle. + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + * \sa TTF_GetFontStyle + */ +typedef Uint32 TTF_FontStyleFlags; + +#define TTF_STYLE_NORMAL 0x00 /**< No special style */ +#define TTF_STYLE_BOLD 0x01 /**< Bold style */ +#define TTF_STYLE_ITALIC 0x02 /**< Italic style */ +#define TTF_STYLE_UNDERLINE 0x04 /**< Underlined text */ +#define TTF_STYLE_STRIKETHROUGH 0x08 /**< Strikethrough text */ + +/** + * Set a font's current style. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to set a new style on. + * \param style the new style values to set, OR'd together. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontStyle + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, TTF_FontStyleFlags style); + +/** + * Query a font's current style. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to query. + * \returns the current font style, as a set of bit flags. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + */ +extern SDL_DECLSPEC TTF_FontStyleFlags SDLCALL TTF_GetFontStyle(const TTF_Font *font); + +/** + * Set a font's current outline. + * + * This uses the font properties `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`, + * `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`, and + * `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER` when setting the font outline. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set a new outline on. + * \param outline positive outline value, 0 to default. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontOutline + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline); + +/** + * Query a font's current outline. + * + * \param font the font to query. + * \returns the font's current outline value. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontOutline + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font); + +/** + * Hinting flags for TTF (TrueType Fonts) + * + * This enum specifies the level of hinting to be applied to the font + * rendering. The hinting level determines how much the font's outlines are + * adjusted for better alignment on the pixel grid. + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + * \sa TTF_GetFontHinting + */ +typedef enum TTF_HintingFlags +{ + TTF_HINTING_INVALID = -1, + TTF_HINTING_NORMAL, /**< Normal hinting applies standard grid-fitting. */ + TTF_HINTING_LIGHT, /**< Light hinting applies subtle adjustments to improve rendering. */ + TTF_HINTING_MONO, /**< Monochrome hinting adjusts the font for better rendering at lower resolutions. */ + TTF_HINTING_NONE, /**< No hinting, the font is rendered without any grid-fitting. */ + TTF_HINTING_LIGHT_SUBPIXEL /**< Light hinting with subpixel rendering for more precise font edges. */ +} TTF_HintingFlags; + +/** + * Set a font's current hinter setting. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to set a new hinter setting on. + * \param hinting the new hinter setting. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontHinting + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, TTF_HintingFlags hinting); + +/** + * Query the number of faces of a font. + * + * \param font the font to query. + * \returns the number of FreeType font faces. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetNumFontFaces(const TTF_Font *font); + +/** + * Query a font's current FreeType hinter setting. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to query. + * \returns the font's current hinter value, or TTF_HINTING_INVALID if the + * font is invalid. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + */ +extern SDL_DECLSPEC TTF_HintingFlags SDLCALL TTF_GetFontHinting(const TTF_Font *font); + +/** + * Enable Signed Distance Field rendering for a font. + * + * SDF is a technique that helps fonts look sharp even when scaling and + * rotating, and requires special shader support for display. + * + * This works with Blended APIs, and generates the raw signed distance values + * in the alpha channel of the resulting texture. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set SDF support on. + * \param enabled true to enable SDF, false to disable. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSDF(TTF_Font *font, bool enabled); + +/** + * Query whether Signed Distance Field rendering is enabled for a font. + * + * \param font the font to query. + * \returns true if enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontSDF(const TTF_Font *font); + +/** + * Query a font's weight, in terms of the lightness/heaviness of the strokes. + * + * \param font the font to query. + * \returns the font's current weight. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.4.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontWeight(const TTF_Font *font); + +#define TTF_FONT_WEIGHT_THIN 100 /**< Thin (100) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_LIGHT 200 /**< ExtraLight (200) named font weight value */ +#define TTF_FONT_WEIGHT_LIGHT 300 /**< Light (300) named font weight value */ +#define TTF_FONT_WEIGHT_NORMAL 400 /**< Normal (400) named font weight value */ +#define TTF_FONT_WEIGHT_MEDIUM 500 /**< Medium (500) named font weight value */ +#define TTF_FONT_WEIGHT_SEMI_BOLD 600 /**< SemiBold (600) named font weight value */ +#define TTF_FONT_WEIGHT_BOLD 700 /**< Bold (700) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BOLD 800 /**< ExtraBold (800) named font weight value */ +#define TTF_FONT_WEIGHT_BLACK 900 /**< Black (900) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BLACK 950 /**< ExtraBlack (950) named font weight value */ + +/** + * The horizontal alignment used when rendering wrapped text. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_HorizontalAlignment +{ + TTF_HORIZONTAL_ALIGN_INVALID = -1, + TTF_HORIZONTAL_ALIGN_LEFT, + TTF_HORIZONTAL_ALIGN_CENTER, + TTF_HORIZONTAL_ALIGN_RIGHT +} TTF_HorizontalAlignment; + +/** + * Set a font's current wrap alignment option. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set a new wrap alignment option on. + * \param align the new wrap alignment option. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontWrapAlignment + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontWrapAlignment(TTF_Font *font, TTF_HorizontalAlignment align); + +/** + * Query a font's current wrap alignment option. + * + * \param font the font to query. + * \returns the font's current wrap alignment option. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontWrapAlignment + */ +extern SDL_DECLSPEC TTF_HorizontalAlignment SDLCALL TTF_GetFontWrapAlignment(const TTF_Font *font); + +/** + * Query the total height of a font. + * + * This is usually equal to point size. + * + * \param font the font to query. + * \returns the font's height. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontHeight(const TTF_Font *font); + +/** + * Query the offset from the baseline to the top of a font. + * + * This is a positive value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's ascent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontAscent(const TTF_Font *font); + +/** + * Query the offset from the baseline to the bottom of a font. + * + * This is a negative value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's descent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontDescent(const TTF_Font *font); + +/** + * Set the spacing between lines of text for a font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param lineskip the new line spacing for the font. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontLineSkip + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontLineSkip(TTF_Font *font, int lineskip); + +/** + * Query the spacing between lines of text for a font. + * + * \param font the font to query. + * \returns the font's recommended spacing. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontLineSkip + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontLineSkip(const TTF_Font *font); + +/** + * Set if kerning is enabled for a font. + * + * Newly-opened fonts default to allowing kerning. This is generally a good + * policy unless you have a strong reason to disable it, as it tends to + * produce better rendering (with kerning disabled, some fonts might render + * the word `kerning` as something that looks like `keming` for example). + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set kerning on. + * \param enabled true to enable kerning, false to disable. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontKerning + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, bool enabled); + +/** + * Query whether or not kerning is enabled for a font. + * + * \param font the font to query. + * \returns true if kerning is enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontKerning + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontKerning(const TTF_Font *font); + +/** + * Query whether a font is fixed-width. + * + * A "fixed-width" font means all glyphs are the same width across; a + * lowercase 'i' will be the same size across as a capital 'W', for example. + * This is common for terminals and text editors, and other apps that treat + * text as a grid. Most other things (WYSIWYG word processors, web pages, etc) + * are more likely to not be fixed-width in most cases. + * + * \param font the font to query. + * \returns true if the font is fixed-width, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsFixedWidth(const TTF_Font *font); + +/** + * Query whether a font is scalable or not. + * + * Scalability lets us distinguish between outline and bitmap fonts. + * + * \param font the font to query. + * \returns true if the font is scalable, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsScalable(const TTF_Font *font); + +/** + * Query a font's family name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's family name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontFamilyName(const TTF_Font *font); + +/** + * Query a font's style name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's style name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontStyleName(const TTF_Font *font); + +/** + * Direction flags + * + * The values here are chosen to match + * [hb_direction_t](https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-direction-t) + * . + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontDirection + */ +typedef enum TTF_Direction +{ + TTF_DIRECTION_INVALID = 0, + TTF_DIRECTION_LTR = 4, /**< Left to Right */ + TTF_DIRECTION_RTL, /**< Right to Left */ + TTF_DIRECTION_TTB, /**< Top to Bottom */ + TTF_DIRECTION_BTT /**< Bottom to Top */ +} TTF_Direction; + +/** + * Set the direction to be used for text shaping by a font. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping by a font. + * + * This defaults to TTF_DIRECTION_INVALID if it hasn't been set. + * + * \param font the font to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetFontDirection(TTF_Font *font); + +/** + * Convert from a 4 character string to a 32-bit tag. + * + * \param string the 4 character string to convert. + * \returns the 32-bit representation of the string. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_StringToTag(const char *string); + +/** + * Convert from a 32-bit tag to a 4 character string. + * + * \param tag the 32-bit tag to convert. + * \param string a pointer filled in with the 4 character representation of + * the tag. + * \param size the size of the buffer pointed at by string, should be at least + * 4. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC void SDLCALL TTF_TagToString(Uint32 tag, char *string, size_t size); + +/** + * Set the script to be used for text shaping by a font. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontScript(TTF_Font *font, Uint32 script); + +/** + * Get the script used for text shaping a font. + * + * \param font the font to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontScript(TTF_Font *font); + +/** + * Get the script used by a 32-bit codepoint. + * + * \param ch the character code to check. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * on success, or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function is thread-safe. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetGlyphScript(Uint32 ch); + +/** + * Set language to be used for text shaping by a font. + * + * If SDL_ttf was not built with HarfBuzz support, this function returns + * false. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to specify a language for. + * \param language_bcp47 a null-terminated string containing the desired + * language's BCP47 code. Or null to reset the value. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47); + +/** + * Check whether a glyph is provided by the font for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \returns true if font provides a glyph for this character, false if not. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontHasGlyph(TTF_Font *font, Uint32 ch); + +/** + * The type of data in a glyph image + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_ImageType +{ + TTF_IMAGE_INVALID, + TTF_IMAGE_ALPHA, /**< The color channels are white */ + TTF_IMAGE_COLOR, /**< The color channels have image data */ + TTF_IMAGE_SDF, /**< The alpha channel has signed distance field information */ +} TTF_ImageType; + +/** + * Get the pixel image for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImage(TTF_Font *font, Uint32 ch, TTF_ImageType *image_type); + +/** + * Get the pixel image for a character index. + * + * This is useful for text engine implementations, which can call this with + * the `glyph_index` in a TTF_CopyOperation + * + * \param font the font to query. + * \param glyph_index the index of the glyph to return. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImageForIndex(TTF_Font *font, Uint32 glyph_index, TTF_ImageType *image_type); + +/** + * Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint. + * + * To understand what these metrics mean, here is a useful link: + * + * https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param minx a pointer filled in with the minimum x coordinate of the glyph + * from the left edge of its bounding box. This value may be + * negative. + * \param maxx a pointer filled in with the maximum x coordinate of the glyph + * from the left edge of its bounding box. + * \param miny a pointer filled in with the minimum y coordinate of the glyph + * from the bottom edge of its bounding box. This value may be + * negative. + * \param maxy a pointer filled in with the maximum y coordinate of the glyph + * from the bottom edge of its bounding box. + * \param advance a pointer filled in with the distance to the next glyph from + * the left edge of this glyph's bounding box. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphMetrics(TTF_Font *font, Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance); + +/** + * Query the kerning size between the glyphs of two UNICODE codepoints. + * + * \param font the font to query. + * \param previous_ch the previous codepoint. + * \param ch the current codepoint. + * \param kerning a pointer filled in with the kerning size between the two + * glyphs, in pixels, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphKerning(TTF_Font *font, Uint32 previous_ch, Uint32 ch, int *kerning); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSize(TTF_Font *font, const char *text, size_t length, int *w, int *h); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param wrap_width the maximum width or 0 to wrap on newline characters. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSizeWrapped(TTF_Font *font, const char *text, size_t length, int wrap_width, int *w, int *h); + +/** + * Calculate how much of a UTF-8 string will fit in a given width. + * + * This reports the number of characters that can be rendered before reaching + * `max_width`. + * + * This does not need to render the string to do this calculation. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param max_width maximum width, in pixels, available for the string, or 0 + * for unbounded width. + * \param measured_width a pointer filled in with the width, in pixels, of the + * string that will fit, may be NULL. + * \param measured_length a pointer filled in with the length, in bytes, of + * the string that will fit, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_MeasureString(TTF_Font *font, const char *text, size_t length, int max_width, int *measured_width, size_t *measured_length); + +/** + * Render UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Solid_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrapLength the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrapLength); + +/** + * Render a single 32-bit glyph at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Shaded, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Shaded_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + +/** + * Render UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Blended_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_LCD_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_Blended. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_Blended_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_Blended. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_LCD(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + + +/** + * A text engine used to create text objects. + * + * This is a public interface that can be used by applications and libraries + * to perform customize rendering with text objects. See + * for details. + * + * There are three text engines provided with the library: + * + * - Drawing to an SDL_Surface, created with TTF_CreateSurfaceTextEngine() + * - Drawing with an SDL 2D renderer, created with + * TTF_CreateRendererTextEngine() + * - Drawing with the SDL GPU API, created with TTF_CreateGPUTextEngine() + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextEngine TTF_TextEngine; + +/** + * Internal data for TTF_Text + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextData TTF_TextData; + +/** + * Text created with TTF_CreateText() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + * \sa TTF_GetTextProperties + * \sa TTF_DestroyText + */ +typedef struct TTF_Text +{ + char *text; /**< A copy of the UTF-8 string that this text object represents, useful for layout, debugging and retrieving substring text. This is updated when the text object is modified and will be freed automatically when the object is destroyed. */ + int num_lines; /**< The number of lines in the text, 0 if it's empty */ + + int refcount; /**< Application reference count, used when freeing surface */ + + TTF_TextData *internal; /**< Private */ + +} TTF_Text; + +/** + * Create a text engine for drawing text on SDL surfaces. + * + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroySurfaceTextEngine + * \sa TTF_DrawSurfaceText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateSurfaceTextEngine(void); + +/** + * Draw text to an SDL surface. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateSurfaceTextEngine(). + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \param surface the surface to draw on. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawSurfaceText(TTF_Text *text, int x, int y, SDL_Surface *surface); + +/** + * Destroy a text engine created for drawing text on SDL surfaces. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateSurfaceTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroySurfaceTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text on an SDL renderer. + * + * \param renderer the renderer to use for creating textures and drawing text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + * \sa TTF_CreateRendererTextEngineWithProperties + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngine(SDL_Renderer *renderer); + +/** + * Create a text engine for drawing text on an SDL renderer, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER`: the renderer to use for + * creating textures and drawing text + * - `TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the + * texture atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER "SDL_ttf.renderer_text_engine.create.renderer" +#define TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.renderer_text_engine.create.atlas_texture_size" + +/** + * Draw text to an SDL renderer. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateRendererTextEngine(), and will draw using the renderer passed to + * that function. + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawRendererText(TTF_Text *text, float x, float y); + +/** + * Destroy a text engine created for drawing text on an SDL renderer. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateRendererTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyRendererTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text with the SDL GPU API. + * + * \param device the SDL_GPUDevice to use for creating textures and drawing + * text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngineWithProperties + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngine(SDL_GPUDevice *device); + +/** + * Create a text engine for drawing text with the SDL GPU API, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_GPU_TEXT_ENGINE_DEVICE`: the SDL_GPUDevice to use for creating + * textures and drawing text. + * - `TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the texture + * atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_GPU_TEXT_ENGINE_DEVICE "SDL_ttf.gpu_text_engine.create.device" +#define TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.gpu_text_engine.create.atlas_texture_size" + +/** + * Draw sequence returned by TTF_GetGPUTextDrawData + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextDrawData + */ +typedef struct TTF_GPUAtlasDrawSequence +{ + SDL_GPUTexture *atlas_texture; /**< Texture atlas that stores the glyphs */ + SDL_FPoint *xy; /**< An array of vertex positions */ + SDL_FPoint *uv; /**< An array of normalized texture coordinates for each vertex */ + int num_vertices; /**< Number of vertices */ + int *indices; /**< An array of indices into the 'vertices' arrays */ + int num_indices; /**< Number of indices */ + TTF_ImageType image_type; /**< The image type of this draw sequence */ + + struct TTF_GPUAtlasDrawSequence *next; /**< The next sequence (will be NULL in case of the last sequence) */ +} TTF_GPUAtlasDrawSequence; + +/** + * Get the geometry data needed for drawing the text. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateGPUTextEngine(). + * + * The positive X-axis is taken towards the right and the positive Y-axis is + * taken upwards for both the vertex and the texture coordinates, i.e, it + * follows the same convention used by the SDL_GPU API. If you want to use a + * different coordinate system you will need to transform the vertices + * yourself. + * + * If the text looks blocky use linear filtering. + * + * \param text the text to draw. + * \returns a NULL terminated linked list of TTF_GPUAtlasDrawSequence objects + * or NULL if the passed text is empty or in case of failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC TTF_GPUAtlasDrawSequence * SDLCALL TTF_GetGPUTextDrawData(TTF_Text *text); + +/** + * Destroy a text engine created for drawing text with the SDL GPU API. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyGPUTextEngine(TTF_TextEngine *engine); + +/** + * The winding order of the vertices returned by TTF_GetGPUTextDrawData + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_GPUTextEngineWinding +{ + TTF_GPU_TEXTENGINE_WINDING_INVALID = -1, + TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE, + TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE +} TTF_GPUTextEngineWinding; + +/** + * Sets the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \param winding the new winding order option. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextEngineWinding + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetGPUTextEngineWinding(TTF_TextEngine *engine, TTF_GPUTextEngineWinding winding); + +/** + * Get the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \returns the winding order used by the GPU text engine or + * TTF_GPU_TEXTENGINE_WINDING_INVALID in case of error. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetGPUTextEngineWinding + */ +extern SDL_DECLSPEC TTF_GPUTextEngineWinding SDLCALL TTF_GetGPUTextEngineWinding(const TTF_TextEngine *engine); + +/** + * Create a text object from UTF-8 text and a text engine. + * + * \param engine the text engine to use when creating the text object, may be + * NULL. + * \param font the font to render with. + * \param text the text to use, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns a TTF_Text object or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font and text engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyText + */ +extern SDL_DECLSPEC TTF_Text * SDLCALL TTF_CreateText(TTF_TextEngine *engine, TTF_Font *font, const char *text, size_t length); + +/** + * Get the properties associated with a text object. + * + * \param text the TTF_Text to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetTextProperties(TTF_Text *text); + +/** + * Set the text engine used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param engine the text engine to use for drawing. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextEngine + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextEngine(TTF_Text *text, TTF_TextEngine *engine); + +/** + * Get the text engine used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_TextEngine used by the text on success or NULL on failure; + * call SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextEngine + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_GetTextEngine(TTF_Text *text); + +/** + * Set the font used by a text object. + * + * When a text object has a font, any changes to the font will automatically + * regenerate the text. If you set the font to NULL, the text will continue to + * render but changes to the font will no longer affect the text. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param font the font to use, may be NULL. + * \returns false if the text pointer is null; otherwise, true. call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextFont(TTF_Text *text, TTF_Font *font); + +/** + * Get the font used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_Font used by the text on success or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_GetTextFont(TTF_Text *text); + +/** + * Set the direction to be used for text shaping a text object. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * \param text the text to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextDirection(TTF_Text *text, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping a text object. + * + * This defaults to the direction of the font used by the text object. + * + * \param text the text to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetTextDirection(TTF_Text *text); + +/** + * Set the script to be used for text shaping a text object. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * \param text the text to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextScript(TTF_Text *text, Uint32 script); + +/** + * Get the script used for text shaping a text object. + * + * This defaults to the script of the font used by the text object. + * + * \param text the text to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set on either the text object or the + * font. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetTextScript(TTF_Text *text); + +/** + * Set the color of a text object. + * + * The default text color is white (255, 255, 255, 255). + * + * \param text the TTF_Text to modify. + * \param r the red color value in the range of 0-255. + * \param g the green color value in the range of 0-255. + * \param b the blue color value in the range of 0-255. + * \param a the alpha value in the range of 0-255. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColor(TTF_Text *text, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + +/** + * Set the color of a text object. + * + * The default text color is white (1.0f, 1.0f, 1.0f, 1.0f). + * + * \param text the TTF_Text to modify. + * \param r the red color value, normally in the range of 0-1. + * \param g the green color value, normally in the range of 0-1. + * \param b the blue color value, normally in the range of 0-1. + * \param a the alpha value in the range of 0-1. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColorFloat(TTF_Text *text, float r, float g, float b, float a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value in the range of + * 0-255, may be NULL. + * \param g a pointer filled in with the green color value in the range of + * 0-255, may be NULL. + * \param b a pointer filled in with the blue color value in the range of + * 0-255, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-255, + * may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColor(TTF_Text *text, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value, normally in the + * range of 0-1, may be NULL. + * \param g a pointer filled in with the green color value, normally in the + * range of 0-1, may be NULL. + * \param b a pointer filled in with the blue color value, normally in the + * range of 0-1, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-1, may + * be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColorFloat(TTF_Text *text, float *r, float *g, float *b, float *a); + +/** + * Set the position of a text object. + * + * This can be used to position multiple text objects within a single wrapping + * text area. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param x the x offset of the upper left corner of this text in pixels. + * \param y the y offset of the upper left corner of this text in pixels. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextPosition(TTF_Text *text, int x, int y); + +/** + * Get the position of a text object. + * + * \param text the TTF_Text to query. + * \param x a pointer filled in with the x offset of the upper left corner of + * this text in pixels, may be NULL. + * \param y a pointer filled in with the y offset of the upper left corner of + * this text in pixels, may be NULL. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextPosition(TTF_Text *text, int *x, int *y); + +/** + * Set whether wrapping is enabled on a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param wrap_width the maximum width in pixels, 0 to wrap on newline + * characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWidth(TTF_Text *text, int wrap_width); + +/** + * Get whether wrapping is enabled on a text object. + * + * \param text the TTF_Text to query. + * \param wrap_width a pointer filled in with the maximum width in pixels or 0 + * if the text is being wrapped on newline characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextWrapWidth(TTF_Text *text, int *wrap_width); + +/** + * Set whether whitespace should be visible when wrapping a text object. + * + * If the whitespace is visible, it will take up space for purposes of + * alignment and wrapping. This is good for editing, but looks better when + * centered or aligned if whitespace around line wrapping is hidden. This + * defaults false. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param visible true to show whitespace when wrapping text, false to hide + * it. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWhitespaceVisible(TTF_Text *text, bool visible); + +/** + * Return whether whitespace is shown when wrapping a text object. + * + * \param text the TTF_Text to query. + * \returns true if whitespace is shown when wrapping text, or false + * otherwise. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_TextWrapWhitespaceVisible(TTF_Text *text); + +/** + * Set the UTF-8 text used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to use, may be NULL. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Insert UTF-8 text into a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only insert + * at UTF-8 sequence boundaries. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_InsertTextString(TTF_Text *text, int offset, const char *string, size_t length); + +/** + * Append UTF-8 text to a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AppendTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Delete UTF-8 text from a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only delete + * at UTF-8 sequence boundaries. + * \param length the length of text to delete, in bytes, or -1 for the + * remainder of the string. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DeleteTextString(TTF_Text *text, int offset, int length); + +/** + * Get the size of a text object. + * + * The size of the text may change when the font or font style and size + * change. + * + * \param text the TTF_Text to query. + * \param w a pointer filled in with the width of the text, in pixels, may be + * NULL. + * \param h a pointer filled in with the height of the text, in pixels, may be + * NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSize(TTF_Text *text, int *w, int *h); + +/** + * Flags for TTF_SubString + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SubString + */ +typedef Uint32 TTF_SubStringFlags; + +#define TTF_SUBSTRING_DIRECTION_MASK 0x000000FF /**< The mask for the flow direction for this substring */ +#define TTF_SUBSTRING_TEXT_START 0x00000100 /**< This substring contains the beginning of the text */ +#define TTF_SUBSTRING_LINE_START 0x00000200 /**< This substring contains the beginning of line `line_index` */ +#define TTF_SUBSTRING_LINE_END 0x00000400 /**< This substring contains the end of line `line_index` */ +#define TTF_SUBSTRING_TEXT_END 0x00000800 /**< This substring contains the end of the text */ + +/** + * The representation of a substring within text. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetNextTextSubString + * \sa TTF_GetPreviousTextSubString + * \sa TTF_GetTextSubString + * \sa TTF_GetTextSubStringForLine + * \sa TTF_GetTextSubStringForPoint + * \sa TTF_GetTextSubStringsForRange + */ +typedef struct TTF_SubString +{ + TTF_SubStringFlags flags; /**< The flags for this substring */ + int offset; /**< The byte offset from the beginning of the text */ + int length; /**< The byte length starting at the offset */ + int line_index; /**< The index of the line that contains this substring */ + int cluster_index; /**< The internal cluster index, used for quickly iterating */ + SDL_Rect rect; /**< The rectangle, relative to the top left of the text, containing the substring */ +} TTF_SubString; + +/** + * Get the substring of a text object that surrounds a text offset. + * + * If `offset` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If + * `offset` is greater than or equal to the length of the text string, this + * will return a zero length substring at the end of the text with the + * TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubString(TTF_Text *text, int offset, TTF_SubString *substring); + +/** + * Get the substring of a text object that contains the given line. + * + * If `line` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If `line` + * is greater than or equal to `text->num_lines` this will return a zero + * length substring at the end of the text with the TTF_SUBSTRING_TEXT_END + * flag set. + * + * \param text the TTF_Text to query. + * \param line a zero-based line index, in the range [0 .. text->num_lines-1]. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForLine(TTF_Text *text, int line, TTF_SubString *substring); + +/** + * Get the substrings of a text object that contain a range of text. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param length the length of the range being queried, in bytes, or -1 for + * the remainder of the string. + * \param count a pointer filled in with the number of substrings returned, + * may be NULL. + * \returns a NULL terminated array of substring pointers or NULL on failure; + * call SDL_GetError() for more information. This is a single + * allocation that should be freed with SDL_free() when it is no + * longer needed. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_SubString ** SDLCALL TTF_GetTextSubStringsForRange(TTF_Text *text, int offset, int length, int *count); + +/** + * Get the portion of a text string that is closest to a point. + * + * This will return the closest substring of text to the given point. + * + * \param text the TTF_Text to query. + * \param x the x coordinate relative to the left side of the text, may be + * outside the bounds of the text area. + * \param y the y coordinate relative to the top side of the text, may be + * outside the bounds of the text area. + * \param substring a pointer filled in with the closest substring of text to + * the given point. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForPoint(TTF_Text *text, int x, int y, TTF_SubString *substring); + +/** + * Get the previous substring in a text object + * + * If called at the start of the text, this will return a zero length + * substring with the TTF_SUBSTRING_TEXT_START flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetPreviousTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *previous); + +/** + * Get the next substring in a text object + * + * If called at the end of the text, this will return a zero length substring + * with the TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \param next a pointer filled in with the next substring. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetNextTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *next); + +/** + * Update the layout of a text object. + * + * This is automatically done when the layout is requested or the text is + * rendered, but you can call this if you need more control over the timing of + * when the layout and text engine representation are updated. + * + * \param text the TTF_Text to update. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_UpdateText(TTF_Text *text); + +/** + * Destroy a text object created by a text engine. + * + * \param text the text to destroy. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyText(TTF_Text *text); + +/** + * Dispose of a previously-created font. + * + * Call this when done with a font. This function will free any resources + * associated with it. It is safe to call this function on NULL, for example + * on the result of a failed call to TTF_OpenFont(). + * + * The font is not valid after being passed to this function. String pointers + * from functions that return information on this font, such as + * TTF_GetFontFamilyName() and TTF_GetFontStyleName(), are no longer valid + * after this call, as well. + * + * \param font the font to dispose of. + * + * \threadsafety This function should not be called while any other thread is + * using the font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_OpenFont + * \sa TTF_OpenFontIO + */ +extern SDL_DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font); + +/** + * Deinitialize SDL_ttf. + * + * You must call this when done with the library, to free internal resources. + * It is safe to call this when the library isn't initialized, as it will just + * return immediately. + * + * Once you have as many quit calls as you have had successful calls to + * TTF_Init, the library will actually deinitialize. + * + * Please note that this does not automatically close any fonts that are still + * open at the time of deinitialization, and it is possibly not safe to close + * them afterwards, as parts of the library will no longer be initialized to + * deal with it. A well-written program should call TTF_CloseFont() on any + * open fonts before calling this function! + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_Quit(void); + +/** + * Check if SDL_ttf is initialized. + * + * This reports the number of times the library has been initialized by a call + * to TTF_Init(), without a paired deinitialization request from TTF_Quit(). + * + * In short: if it's greater than zero, the library is currently initialized + * and ready to work. If zero, it is not initialized. + * + * Despite the return value being a signed integer, this function should not + * return a negative number. + * + * \returns the current number of initialization calls, that need to + * eventually be paired with this many calls to TTF_Quit(). + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + * \sa TTF_Quit + */ +extern SDL_DECLSPEC int SDLCALL TTF_WasInit(void); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/INSTALL.md b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/INSTALL.md new file mode 100644 index 0000000..e11b671 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/INSTALL.md @@ -0,0 +1,35 @@ + +# Using this package + +This package contains SDL_ttf built for Xcode. + +To use this package in Xcode, drag `SDL3_ttf.framework` into your project. + +# Documentation + +An API reference and additional documentation is available at: + +https://wiki.libsdl.org/SDL3_ttf + +# Discussions + +## Discord + +You can join the official Discord server at: + +https://discord.com/invite/BwpFGBWsv8 + +## Forums/mailing lists + +You can join SDL development discussions at: + +https://discourse.libsdl.org/ + +Once you sign up, you can use the forum through the website or as a mailing list from your email client. + +## Announcement list + +You can sign up for the low traffic announcement list at: + +https://www.libsdl.org/mailing-list.php + diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/Info.plist b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/Info.plist new file mode 100644 index 0000000..7bf708c --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/Info.plist @@ -0,0 +1,46 @@ + + + + + BuildMachineOSBuild + 23H420 + CFBundleDevelopmentRegion + English + CFBundleExecutable + SDL3_ttf + CFBundleIdentifier + org.libsdl.SDL3-ttf + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + SDL3_ttf + CFBundlePackageType + FMWK + CFBundleShortVersionString + 3.2.2 + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 3.2.2 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + + DTPlatformName + macosx + DTPlatformVersion + 14.5 + DTSDKBuild + 23F73 + DTSDKName + macosx14.5 + DTXcode + 1540 + DTXcodeBuild + 15F31d + LSMinimumSystemVersion + 10.13 + + diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/LICENSE.txt b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/LICENSE.txt new file mode 100644 index 0000000..52d0ed3 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/LICENSE.txt @@ -0,0 +1,17 @@ +Copyright (C) 1997-2025 Sam Lantinga + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/README.md b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/README.md new file mode 100644 index 0000000..3a6a1e9 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/Resources/README.md @@ -0,0 +1,23 @@ + +SDL_ttf 3.0 + +This library is a wrapper around the FreeType and Harfbuzz libraries, allowing you to use TrueType fonts to render text in SDL applications. + +The latest version of this library is available from GitHub: +https://github.com/libsdl-org/SDL_ttf/releases + +Installation instructions and a quick introduction is available in +[INSTALL.md](INSTALL.md) + +This library is distributed under the terms of the zlib license, +available in [LICENSE.txt](LICENSE.txt). + +This library also uses the following libraries: +- FreeType, licensed under the [FTL](https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT) +- HarfBuzz, licensed under the [MIT license](https://github.com/harfbuzz/harfbuzz/blob/main/COPYING) +- PlutoSVG, licensed under the [MIT license](https://github.com/sammycage/plutosvg/blob/master/LICENSE) +- PlutoVG, licensed under the [MIT license](https://github.com/sammycage/plutovg/blob/master/LICENSE) + +Enjoy! + +Sam Lantinga (slouken@libsdl.org) diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/SDL3_ttf b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/SDL3_ttf new file mode 100755 index 0000000..90a6311 Binary files /dev/null and b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/SDL3_ttf differ diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/_CodeSignature/CodeResources b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/_CodeSignature/CodeResources new file mode 100644 index 0000000..fb2abb5 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/A/_CodeSignature/CodeResources @@ -0,0 +1,197 @@ + + + + + files + + Resources/CMake/SDL3_ttfConfig.cmake + + V6UpWQTvr/puOrlm1sgAs6fktNA= + + Resources/CMake/SDL3_ttfConfigVersion.cmake + + WW2xmNHZyYr9y3/8uAylJuutcPw= + + Resources/INSTALL.md + + 3kA+9HE5dF7+nyypVt5YOfU+Uho= + + Resources/Info.plist + + Q+NCd9YwE/D/Y4ptVnrhOldXz6U= + + Resources/LICENSE.txt + + dp6e8JHkl0CrYD+oe2IXZfWB/iw= + + Resources/README.md + + lm034L4zWKPElKb9O2dmehurfFQ= + + + files2 + + Headers/SDL_textengine.h + + hash2 + + Uk27FTzsWoYySpKM1gkwCB/svSxscGViuMzca93gLP8= + + + Headers/SDL_ttf.h + + hash2 + + 6bsCCUp3Uc3tCp+0Xxw7Tt01+UV8bra5YN1dFjpRBL0= + + + Resources/CMake/SDL3_ttfConfig.cmake + + hash2 + + VpwUT/D8TjpLXBguVImWqsMkqni9HXiIzx91C92Krqc= + + + Resources/CMake/SDL3_ttfConfigVersion.cmake + + hash2 + + tb1RnDTj72GQOzcXp6FPtiqW8tSD886UyUY09c1Ms/U= + + + Resources/INSTALL.md + + hash2 + + Jq9GEmdnFRmUTNnYYZZ+5mFqqrMelD86Gthhyi2kGJQ= + + + Resources/Info.plist + + hash2 + + LwUSgLeBsUUT/M3w+W5AAfTziViNTWX1o7Ly+x3J2u0= + + + Resources/LICENSE.txt + + hash2 + + eCbsoKD35ZHzjdhE4geiAKrIGlmyDYoww6+MYoKvE+Y= + + + Resources/README.md + + hash2 + + 6aipppbEU7MEd3x9OHnKqAGyFXVYiSAL8X8lm271U00= + + + + rules + + ^Resources/ + + ^Resources/.*\.lproj/ + + optional + + weight + 1000 + + ^Resources/.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Resources/Base\.lproj/ + + weight + 1010 + + ^version.plist$ + + + rules2 + + .*\.dSYM($|/) + + weight + 11 + + ^(.*/)?\.DS_Store$ + + omit + + weight + 2000 + + ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ + + nested + + weight + 10 + + ^.* + + ^Info\.plist$ + + omit + + weight + 20 + + ^PkgInfo$ + + omit + + weight + 20 + + ^Resources/ + + weight + 20 + + ^Resources/.*\.lproj/ + + optional + + weight + 1000 + + ^Resources/.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Resources/Base\.lproj/ + + weight + 1010 + + ^[^/]+$ + + nested + + weight + 10 + + ^embedded\.provisionprofile$ + + weight + 20 + + ^version\.plist$ + + weight + 20 + + + + diff --git a/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/Current b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/Current new file mode 120000 index 0000000..8c7e5a6 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/macos-arm64_x86_64/SDL3_ttf.framework/Versions/Current @@ -0,0 +1 @@ +A \ No newline at end of file diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/Headers/SDL_textengine.h b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/Headers/SDL_textengine.h new file mode 100644 index 0000000..9f5f1f0 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/Headers/SDL_textengine.h @@ -0,0 +1,181 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + + +/** + * \file SDL_textengine.h + * + * Definitions for implementations of the TTF_TextEngine interface. + */ +#ifndef SDL_TTF_TEXTENGINE_H_ +#define SDL_TTF_TEXTENGINE_H_ + +#include +#include + +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A font atlas draw command. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_DrawCommand +{ + TTF_DRAW_COMMAND_NOOP, + TTF_DRAW_COMMAND_FILL, + TTF_DRAW_COMMAND_COPY +} TTF_DrawCommand; + +/** + * A filled rectangle draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_FillOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_FILL */ + SDL_Rect rect; /**< The rectangle to fill, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ +} TTF_FillOperation; + +/** + * A texture copy draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_CopyOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_COPY */ + int text_offset; /**< The offset in the text corresponding to this glyph. + There may be multiple glyphs with the same text offset + and the next text offset might be several Unicode codepoints + later. In this case the glyphs and codepoints are grouped + together and the group bounding box is the union of the dst + rectangles for the corresponding glyphs. */ + TTF_Font *glyph_font; /**< The font containing the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + Uint32 glyph_index; /**< The glyph index of the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + SDL_Rect src; /**< The area within the glyph to be drawn */ + SDL_Rect dst; /**< The drawing coordinates of the glyph, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ + void *reserved; +} TTF_CopyOperation; + +/** + * A text engine draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef union TTF_DrawOperation +{ + TTF_DrawCommand cmd; + TTF_FillOperation fill; + TTF_CopyOperation copy; +} TTF_DrawOperation; + + +/* Private data in TTF_Text, to assist in text measurement and layout */ +typedef struct TTF_TextLayout TTF_TextLayout; + + +/* Private data in TTF_Text, available to implementations */ +struct TTF_TextData +{ + TTF_Font *font; /**< The font used by this text, read-only. */ + SDL_FColor color; /**< The color of the text, read-only. */ + + bool needs_layout_update; /**< True if the layout needs to be updated */ + TTF_TextLayout *layout; /**< Cached layout information, read-only. */ + int x; /**< The x offset of the upper left corner of this text, in pixels, read-only. */ + int y; /**< The y offset of the upper left corner of this text, in pixels, read-only. */ + int w; /**< The width of this text, in pixels, read-only. */ + int h; /**< The height of this text, in pixels, read-only. */ + int num_ops; /**< The number of drawing operations to render this text, read-only. */ + TTF_DrawOperation *ops; /**< The drawing operations used to render this text, read-only. */ + int num_clusters; /**< The number of substrings representing clusters of glyphs in the string, read-only */ + TTF_SubString *clusters; /**< Substrings representing clusters of glyphs in the string, read-only */ + + SDL_PropertiesID props; /**< Custom properties associated with this text, read-only. This field is created as-needed using TTF_GetTextProperties() and the properties may be then set and read normally */ + + bool needs_engine_update; /**< True if the engine text needs to be updated */ + TTF_TextEngine *engine; /**< The engine used to render this text, read-only. */ + void *engine_text; /**< The implementation-specific representation of this text */ +}; + +/** + * A text engine interface. + * + * This structure should be initialized using SDL_INIT_INTERFACE() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa SDL_INIT_INTERFACE + */ +struct TTF_TextEngine +{ + Uint32 version; /**< The version of this interface */ + + void *userdata; /**< User data pointer passed to callbacks */ + + /* Create a text representation from draw instructions. + * + * All fields of `text` except `internal->engine_text` will already be filled out. + * + * This function should set the `internal->engine_text` field to a non-NULL value. + * + * \param userdata the userdata pointer in this interface. + * \param text the text object being created. + */ + bool (SDLCALL *CreateText)(void *userdata, TTF_Text *text); + + /** + * Destroy a text representation. + */ + void (SDLCALL *DestroyText)(void *userdata, TTF_Text *text); + +}; + +/* Check the size of TTF_TextEngine + * + * If this assert fails, either the compiler is padding to an unexpected size, + * or the interface has been updated and this should be updated to match and + * the code using this interface should be updated to handle the old version. + */ +SDL_COMPILE_TIME_ASSERT(TTF_TextEngine_SIZE, + (sizeof(void *) == 4 && sizeof(TTF_TextEngine) == 16) || + (sizeof(void *) == 8 && sizeof(TTF_TextEngine) == 32)); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_TEXTENGINE_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/Headers/SDL_ttf.h b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/Headers/SDL_ttf.h new file mode 100644 index 0000000..b723bc7 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/Headers/SDL_ttf.h @@ -0,0 +1,2833 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* WIKI CATEGORY: SDLTTF */ + +/** + * # CategorySDLTTF + * + * Header file for SDL_ttf library + * + * This library is a wrapper around the excellent FreeType 2.0 library, + * available at: https://www.freetype.org/ + */ + +#ifndef SDL_TTF_H_ +#define SDL_TTF_H_ + +#include +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO + */ +#define SDL_TTF_MAJOR_VERSION 3 +#define SDL_TTF_MINOR_VERSION 2 +#define SDL_TTF_MICRO_VERSION 2 + +/** + * This is the version number macro for the current SDL_ttf version. + */ +#define SDL_TTF_VERSION \ + SDL_VERSIONNUM(SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION) + +/** + * This macro will evaluate to true if compiled with SDL_ttf at least X.Y.Z. + */ +#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \ + ((SDL_TTF_MAJOR_VERSION >= X) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || SDL_TTF_MICRO_VERSION >= Z)) + +/** + * This function gets the version of the dynamically linked SDL_ttf library. + * + * \returns SDL_ttf version. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_Version(void); + +/** + * Query the version of the FreeType library in use. + * + * TTF_Init() should be called before calling this function. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetFreeTypeVersion(int *major, int *minor, int *patch); + +/** + * Query the version of the HarfBuzz library in use. + * + * If HarfBuzz is not available, the version reported is 0.0.0. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetHarfBuzzVersion(int *major, int *minor, int *patch); + +/** + * The internal structure containing font information. + * + * Opaque data! + */ +typedef struct TTF_Font TTF_Font; + +/** + * Initialize SDL_ttf. + * + * You must successfully call this function before it is safe to call any + * other function in this library. + * + * It is safe to call this more than once, and each successful TTF_Init() call + * should be paired with a matching TTF_Quit() call. + * + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Quit + */ +extern SDL_DECLSPEC bool SDLCALL TTF_Init(void); + +/** + * Create a font from a file, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param file path to font file. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, float ptsize); + +/** + * Create a font from an SDL_IOStream, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * If `closeio` is true, `src` will be automatically closed once the font is + * closed. Otherwise you should close `src` yourself after closing the font. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param src an SDL_IOStream to provide a font file's data. + * \param closeio true to close `src` when the font is closed, false to leave + * it open. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIO(SDL_IOStream *src, bool closeio, float ptsize); + +/** + * Create a font with the specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_FONT_CREATE_FILENAME_STRING`: the font file to open, if an + * SDL_IOStream isn't being used. This is required if + * `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER`: an SDL_IOStream containing the + * font to be opened. This should not be closed until the font is closed. + * This is required if `TTF_PROP_FONT_CREATE_FILENAME_STRING` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER`: the offset in the iostream + * for the beginning of the font, defaults to 0. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN`: true if closing the + * font should also close the associated SDL_IOStream. + * - `TTF_PROP_FONT_CREATE_SIZE_FLOAT`: the point size of the font. Some .fon + * fonts will have several sizes embedded in the file, so the point size + * becomes the index of choosing which size. If the value is too high, the + * last indexed size will be the default. + * - `TTF_PROP_FONT_CREATE_FACE_NUMBER`: the face index of the font, if the + * font contains multiple font faces. + * - `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER`: the horizontal DPI to use + * for font rendering, defaults to + * `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER` if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER`: the vertical DPI to use for + * font rendering, defaults to `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER` + * if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_EXISTING_FONT`: an optional TTF_Font that, if set, + * will be used as the font data source and the initial size and style of + * the new font. + * + * \param props the properties to use. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_FONT_CREATE_FILENAME_STRING "SDL_ttf.font.create.filename" +#define TTF_PROP_FONT_CREATE_IOSTREAM_POINTER "SDL_ttf.font.create.iostream" +#define TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER "SDL_ttf.font.create.iostream.offset" +#define TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN "SDL_ttf.font.create.iostream.autoclose" +#define TTF_PROP_FONT_CREATE_SIZE_FLOAT "SDL_ttf.font.create.size" +#define TTF_PROP_FONT_CREATE_FACE_NUMBER "SDL_ttf.font.create.face" +#define TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER "SDL_ttf.font.create.hdpi" +#define TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER "SDL_ttf.font.create.vdpi" +#define TTF_PROP_FONT_CREATE_EXISTING_FONT "SDL_ttf.font.create.existing_font" + +/** + * Create a copy of an existing font. + * + * The copy will be distinct from the original, but will share the font file + * and have the same size and style as the original. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param existing_font the font to copy. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * original font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_CopyFont(TTF_Font *existing_font); + +/** + * Get the properties associated with a font. + * + * The following read-write properties are provided by SDL: + * + * - `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`: The FT_Stroker_LineCap value + * used when setting the font outline, defaults to + * `FT_STROKER_LINECAP_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`: The FT_Stroker_LineJoin value + * used when setting the font outline, defaults to + * `FT_STROKER_LINEJOIN_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER`: The FT_Fixed miter limit used + * when setting the font outline, defaults to 0. + * + * \param font the font to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetFontProperties(TTF_Font *font); + +#define TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER "SDL_ttf.font.outline.line_cap" +#define TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER "SDL_ttf.font.outline.line_join" +#define TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER "SDL_ttf.font.outline.miter_limit" + +/** + * Get the font generation. + * + * The generation is incremented each time font properties change that require + * rebuilding glyphs, such as style, size, etc. + * + * \param font the font to query. + * \returns the font generation or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontGeneration(TTF_Font *font); + +/** + * Add a fallback font. + * + * Add a font that will be used for glyphs that are not in the current font. + * The fallback font should have the same size and style as the current font. + * + * If there are multiple fallback fonts, they are used in the order added. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to add as a fallback. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_ClearFallbackFonts + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AddFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove a fallback font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to remove as a fallback. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_ClearFallbackFonts + */ +extern SDL_DECLSPEC void SDLCALL TTF_RemoveFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove all fallback fonts. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC void SDLCALL TTF_ClearFallbackFonts(TTF_Font *font); + +/** + * Set a font's size dynamically. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSize(TTF_Font *font, float ptsize); + +/** + * Set font size dynamically with target resolutions, in dots per inch. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + * \sa TTF_GetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSizeDPI(TTF_Font *font, float ptsize, int hdpi, int vdpi); + +/** + * Get the size of a font. + * + * \param font the font to query. + * \returns the size of the font, or 0.0f on failure; call SDL_GetError() for + * more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSize + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC float SDLCALL TTF_GetFontSize(TTF_Font *font); + +/** + * Get font target resolutions, in dots per inch. + * + * \param font the font to query. + * \param hdpi a pointer filled in with the target horizontal DPI. + * \param vdpi a pointer filled in with the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontDPI(TTF_Font *font, int *hdpi, int *vdpi); + +/** + * Font style flags for TTF_Font + * + * These are the flags which can be used to set the style of a font in + * SDL_ttf. A combination of these flags can be used with functions that set + * or query font style, such as TTF_SetFontStyle or TTF_GetFontStyle. + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + * \sa TTF_GetFontStyle + */ +typedef Uint32 TTF_FontStyleFlags; + +#define TTF_STYLE_NORMAL 0x00 /**< No special style */ +#define TTF_STYLE_BOLD 0x01 /**< Bold style */ +#define TTF_STYLE_ITALIC 0x02 /**< Italic style */ +#define TTF_STYLE_UNDERLINE 0x04 /**< Underlined text */ +#define TTF_STYLE_STRIKETHROUGH 0x08 /**< Strikethrough text */ + +/** + * Set a font's current style. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to set a new style on. + * \param style the new style values to set, OR'd together. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontStyle + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, TTF_FontStyleFlags style); + +/** + * Query a font's current style. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to query. + * \returns the current font style, as a set of bit flags. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + */ +extern SDL_DECLSPEC TTF_FontStyleFlags SDLCALL TTF_GetFontStyle(const TTF_Font *font); + +/** + * Set a font's current outline. + * + * This uses the font properties `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`, + * `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`, and + * `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER` when setting the font outline. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set a new outline on. + * \param outline positive outline value, 0 to default. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontOutline + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline); + +/** + * Query a font's current outline. + * + * \param font the font to query. + * \returns the font's current outline value. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontOutline + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font); + +/** + * Hinting flags for TTF (TrueType Fonts) + * + * This enum specifies the level of hinting to be applied to the font + * rendering. The hinting level determines how much the font's outlines are + * adjusted for better alignment on the pixel grid. + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + * \sa TTF_GetFontHinting + */ +typedef enum TTF_HintingFlags +{ + TTF_HINTING_INVALID = -1, + TTF_HINTING_NORMAL, /**< Normal hinting applies standard grid-fitting. */ + TTF_HINTING_LIGHT, /**< Light hinting applies subtle adjustments to improve rendering. */ + TTF_HINTING_MONO, /**< Monochrome hinting adjusts the font for better rendering at lower resolutions. */ + TTF_HINTING_NONE, /**< No hinting, the font is rendered without any grid-fitting. */ + TTF_HINTING_LIGHT_SUBPIXEL /**< Light hinting with subpixel rendering for more precise font edges. */ +} TTF_HintingFlags; + +/** + * Set a font's current hinter setting. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to set a new hinter setting on. + * \param hinting the new hinter setting. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontHinting + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, TTF_HintingFlags hinting); + +/** + * Query the number of faces of a font. + * + * \param font the font to query. + * \returns the number of FreeType font faces. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetNumFontFaces(const TTF_Font *font); + +/** + * Query a font's current FreeType hinter setting. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to query. + * \returns the font's current hinter value, or TTF_HINTING_INVALID if the + * font is invalid. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + */ +extern SDL_DECLSPEC TTF_HintingFlags SDLCALL TTF_GetFontHinting(const TTF_Font *font); + +/** + * Enable Signed Distance Field rendering for a font. + * + * SDF is a technique that helps fonts look sharp even when scaling and + * rotating, and requires special shader support for display. + * + * This works with Blended APIs, and generates the raw signed distance values + * in the alpha channel of the resulting texture. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set SDF support on. + * \param enabled true to enable SDF, false to disable. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSDF(TTF_Font *font, bool enabled); + +/** + * Query whether Signed Distance Field rendering is enabled for a font. + * + * \param font the font to query. + * \returns true if enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontSDF(const TTF_Font *font); + +/** + * Query a font's weight, in terms of the lightness/heaviness of the strokes. + * + * \param font the font to query. + * \returns the font's current weight. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.4.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontWeight(const TTF_Font *font); + +#define TTF_FONT_WEIGHT_THIN 100 /**< Thin (100) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_LIGHT 200 /**< ExtraLight (200) named font weight value */ +#define TTF_FONT_WEIGHT_LIGHT 300 /**< Light (300) named font weight value */ +#define TTF_FONT_WEIGHT_NORMAL 400 /**< Normal (400) named font weight value */ +#define TTF_FONT_WEIGHT_MEDIUM 500 /**< Medium (500) named font weight value */ +#define TTF_FONT_WEIGHT_SEMI_BOLD 600 /**< SemiBold (600) named font weight value */ +#define TTF_FONT_WEIGHT_BOLD 700 /**< Bold (700) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BOLD 800 /**< ExtraBold (800) named font weight value */ +#define TTF_FONT_WEIGHT_BLACK 900 /**< Black (900) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BLACK 950 /**< ExtraBlack (950) named font weight value */ + +/** + * The horizontal alignment used when rendering wrapped text. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_HorizontalAlignment +{ + TTF_HORIZONTAL_ALIGN_INVALID = -1, + TTF_HORIZONTAL_ALIGN_LEFT, + TTF_HORIZONTAL_ALIGN_CENTER, + TTF_HORIZONTAL_ALIGN_RIGHT +} TTF_HorizontalAlignment; + +/** + * Set a font's current wrap alignment option. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set a new wrap alignment option on. + * \param align the new wrap alignment option. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontWrapAlignment + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontWrapAlignment(TTF_Font *font, TTF_HorizontalAlignment align); + +/** + * Query a font's current wrap alignment option. + * + * \param font the font to query. + * \returns the font's current wrap alignment option. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontWrapAlignment + */ +extern SDL_DECLSPEC TTF_HorizontalAlignment SDLCALL TTF_GetFontWrapAlignment(const TTF_Font *font); + +/** + * Query the total height of a font. + * + * This is usually equal to point size. + * + * \param font the font to query. + * \returns the font's height. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontHeight(const TTF_Font *font); + +/** + * Query the offset from the baseline to the top of a font. + * + * This is a positive value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's ascent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontAscent(const TTF_Font *font); + +/** + * Query the offset from the baseline to the bottom of a font. + * + * This is a negative value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's descent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontDescent(const TTF_Font *font); + +/** + * Set the spacing between lines of text for a font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param lineskip the new line spacing for the font. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontLineSkip + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontLineSkip(TTF_Font *font, int lineskip); + +/** + * Query the spacing between lines of text for a font. + * + * \param font the font to query. + * \returns the font's recommended spacing. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontLineSkip + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontLineSkip(const TTF_Font *font); + +/** + * Set if kerning is enabled for a font. + * + * Newly-opened fonts default to allowing kerning. This is generally a good + * policy unless you have a strong reason to disable it, as it tends to + * produce better rendering (with kerning disabled, some fonts might render + * the word `kerning` as something that looks like `keming` for example). + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set kerning on. + * \param enabled true to enable kerning, false to disable. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontKerning + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, bool enabled); + +/** + * Query whether or not kerning is enabled for a font. + * + * \param font the font to query. + * \returns true if kerning is enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontKerning + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontKerning(const TTF_Font *font); + +/** + * Query whether a font is fixed-width. + * + * A "fixed-width" font means all glyphs are the same width across; a + * lowercase 'i' will be the same size across as a capital 'W', for example. + * This is common for terminals and text editors, and other apps that treat + * text as a grid. Most other things (WYSIWYG word processors, web pages, etc) + * are more likely to not be fixed-width in most cases. + * + * \param font the font to query. + * \returns true if the font is fixed-width, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsFixedWidth(const TTF_Font *font); + +/** + * Query whether a font is scalable or not. + * + * Scalability lets us distinguish between outline and bitmap fonts. + * + * \param font the font to query. + * \returns true if the font is scalable, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsScalable(const TTF_Font *font); + +/** + * Query a font's family name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's family name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontFamilyName(const TTF_Font *font); + +/** + * Query a font's style name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's style name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontStyleName(const TTF_Font *font); + +/** + * Direction flags + * + * The values here are chosen to match + * [hb_direction_t](https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-direction-t) + * . + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontDirection + */ +typedef enum TTF_Direction +{ + TTF_DIRECTION_INVALID = 0, + TTF_DIRECTION_LTR = 4, /**< Left to Right */ + TTF_DIRECTION_RTL, /**< Right to Left */ + TTF_DIRECTION_TTB, /**< Top to Bottom */ + TTF_DIRECTION_BTT /**< Bottom to Top */ +} TTF_Direction; + +/** + * Set the direction to be used for text shaping by a font. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping by a font. + * + * This defaults to TTF_DIRECTION_INVALID if it hasn't been set. + * + * \param font the font to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetFontDirection(TTF_Font *font); + +/** + * Convert from a 4 character string to a 32-bit tag. + * + * \param string the 4 character string to convert. + * \returns the 32-bit representation of the string. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_StringToTag(const char *string); + +/** + * Convert from a 32-bit tag to a 4 character string. + * + * \param tag the 32-bit tag to convert. + * \param string a pointer filled in with the 4 character representation of + * the tag. + * \param size the size of the buffer pointed at by string, should be at least + * 4. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC void SDLCALL TTF_TagToString(Uint32 tag, char *string, size_t size); + +/** + * Set the script to be used for text shaping by a font. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontScript(TTF_Font *font, Uint32 script); + +/** + * Get the script used for text shaping a font. + * + * \param font the font to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontScript(TTF_Font *font); + +/** + * Get the script used by a 32-bit codepoint. + * + * \param ch the character code to check. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * on success, or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function is thread-safe. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetGlyphScript(Uint32 ch); + +/** + * Set language to be used for text shaping by a font. + * + * If SDL_ttf was not built with HarfBuzz support, this function returns + * false. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to specify a language for. + * \param language_bcp47 a null-terminated string containing the desired + * language's BCP47 code. Or null to reset the value. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47); + +/** + * Check whether a glyph is provided by the font for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \returns true if font provides a glyph for this character, false if not. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontHasGlyph(TTF_Font *font, Uint32 ch); + +/** + * The type of data in a glyph image + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_ImageType +{ + TTF_IMAGE_INVALID, + TTF_IMAGE_ALPHA, /**< The color channels are white */ + TTF_IMAGE_COLOR, /**< The color channels have image data */ + TTF_IMAGE_SDF, /**< The alpha channel has signed distance field information */ +} TTF_ImageType; + +/** + * Get the pixel image for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImage(TTF_Font *font, Uint32 ch, TTF_ImageType *image_type); + +/** + * Get the pixel image for a character index. + * + * This is useful for text engine implementations, which can call this with + * the `glyph_index` in a TTF_CopyOperation + * + * \param font the font to query. + * \param glyph_index the index of the glyph to return. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImageForIndex(TTF_Font *font, Uint32 glyph_index, TTF_ImageType *image_type); + +/** + * Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint. + * + * To understand what these metrics mean, here is a useful link: + * + * https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param minx a pointer filled in with the minimum x coordinate of the glyph + * from the left edge of its bounding box. This value may be + * negative. + * \param maxx a pointer filled in with the maximum x coordinate of the glyph + * from the left edge of its bounding box. + * \param miny a pointer filled in with the minimum y coordinate of the glyph + * from the bottom edge of its bounding box. This value may be + * negative. + * \param maxy a pointer filled in with the maximum y coordinate of the glyph + * from the bottom edge of its bounding box. + * \param advance a pointer filled in with the distance to the next glyph from + * the left edge of this glyph's bounding box. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphMetrics(TTF_Font *font, Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance); + +/** + * Query the kerning size between the glyphs of two UNICODE codepoints. + * + * \param font the font to query. + * \param previous_ch the previous codepoint. + * \param ch the current codepoint. + * \param kerning a pointer filled in with the kerning size between the two + * glyphs, in pixels, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphKerning(TTF_Font *font, Uint32 previous_ch, Uint32 ch, int *kerning); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSize(TTF_Font *font, const char *text, size_t length, int *w, int *h); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param wrap_width the maximum width or 0 to wrap on newline characters. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSizeWrapped(TTF_Font *font, const char *text, size_t length, int wrap_width, int *w, int *h); + +/** + * Calculate how much of a UTF-8 string will fit in a given width. + * + * This reports the number of characters that can be rendered before reaching + * `max_width`. + * + * This does not need to render the string to do this calculation. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param max_width maximum width, in pixels, available for the string, or 0 + * for unbounded width. + * \param measured_width a pointer filled in with the width, in pixels, of the + * string that will fit, may be NULL. + * \param measured_length a pointer filled in with the length, in bytes, of + * the string that will fit, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_MeasureString(TTF_Font *font, const char *text, size_t length, int max_width, int *measured_width, size_t *measured_length); + +/** + * Render UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Solid_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrapLength the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrapLength); + +/** + * Render a single 32-bit glyph at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Shaded, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Shaded_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + +/** + * Render UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Blended_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_LCD_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_Blended. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_Blended_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_Blended. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_LCD(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + + +/** + * A text engine used to create text objects. + * + * This is a public interface that can be used by applications and libraries + * to perform customize rendering with text objects. See + * for details. + * + * There are three text engines provided with the library: + * + * - Drawing to an SDL_Surface, created with TTF_CreateSurfaceTextEngine() + * - Drawing with an SDL 2D renderer, created with + * TTF_CreateRendererTextEngine() + * - Drawing with the SDL GPU API, created with TTF_CreateGPUTextEngine() + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextEngine TTF_TextEngine; + +/** + * Internal data for TTF_Text + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextData TTF_TextData; + +/** + * Text created with TTF_CreateText() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + * \sa TTF_GetTextProperties + * \sa TTF_DestroyText + */ +typedef struct TTF_Text +{ + char *text; /**< A copy of the UTF-8 string that this text object represents, useful for layout, debugging and retrieving substring text. This is updated when the text object is modified and will be freed automatically when the object is destroyed. */ + int num_lines; /**< The number of lines in the text, 0 if it's empty */ + + int refcount; /**< Application reference count, used when freeing surface */ + + TTF_TextData *internal; /**< Private */ + +} TTF_Text; + +/** + * Create a text engine for drawing text on SDL surfaces. + * + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroySurfaceTextEngine + * \sa TTF_DrawSurfaceText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateSurfaceTextEngine(void); + +/** + * Draw text to an SDL surface. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateSurfaceTextEngine(). + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \param surface the surface to draw on. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawSurfaceText(TTF_Text *text, int x, int y, SDL_Surface *surface); + +/** + * Destroy a text engine created for drawing text on SDL surfaces. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateSurfaceTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroySurfaceTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text on an SDL renderer. + * + * \param renderer the renderer to use for creating textures and drawing text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + * \sa TTF_CreateRendererTextEngineWithProperties + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngine(SDL_Renderer *renderer); + +/** + * Create a text engine for drawing text on an SDL renderer, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER`: the renderer to use for + * creating textures and drawing text + * - `TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the + * texture atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER "SDL_ttf.renderer_text_engine.create.renderer" +#define TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.renderer_text_engine.create.atlas_texture_size" + +/** + * Draw text to an SDL renderer. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateRendererTextEngine(), and will draw using the renderer passed to + * that function. + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawRendererText(TTF_Text *text, float x, float y); + +/** + * Destroy a text engine created for drawing text on an SDL renderer. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateRendererTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyRendererTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text with the SDL GPU API. + * + * \param device the SDL_GPUDevice to use for creating textures and drawing + * text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngineWithProperties + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngine(SDL_GPUDevice *device); + +/** + * Create a text engine for drawing text with the SDL GPU API, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_GPU_TEXT_ENGINE_DEVICE`: the SDL_GPUDevice to use for creating + * textures and drawing text. + * - `TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the texture + * atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_GPU_TEXT_ENGINE_DEVICE "SDL_ttf.gpu_text_engine.create.device" +#define TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.gpu_text_engine.create.atlas_texture_size" + +/** + * Draw sequence returned by TTF_GetGPUTextDrawData + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextDrawData + */ +typedef struct TTF_GPUAtlasDrawSequence +{ + SDL_GPUTexture *atlas_texture; /**< Texture atlas that stores the glyphs */ + SDL_FPoint *xy; /**< An array of vertex positions */ + SDL_FPoint *uv; /**< An array of normalized texture coordinates for each vertex */ + int num_vertices; /**< Number of vertices */ + int *indices; /**< An array of indices into the 'vertices' arrays */ + int num_indices; /**< Number of indices */ + TTF_ImageType image_type; /**< The image type of this draw sequence */ + + struct TTF_GPUAtlasDrawSequence *next; /**< The next sequence (will be NULL in case of the last sequence) */ +} TTF_GPUAtlasDrawSequence; + +/** + * Get the geometry data needed for drawing the text. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateGPUTextEngine(). + * + * The positive X-axis is taken towards the right and the positive Y-axis is + * taken upwards for both the vertex and the texture coordinates, i.e, it + * follows the same convention used by the SDL_GPU API. If you want to use a + * different coordinate system you will need to transform the vertices + * yourself. + * + * If the text looks blocky use linear filtering. + * + * \param text the text to draw. + * \returns a NULL terminated linked list of TTF_GPUAtlasDrawSequence objects + * or NULL if the passed text is empty or in case of failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC TTF_GPUAtlasDrawSequence * SDLCALL TTF_GetGPUTextDrawData(TTF_Text *text); + +/** + * Destroy a text engine created for drawing text with the SDL GPU API. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyGPUTextEngine(TTF_TextEngine *engine); + +/** + * The winding order of the vertices returned by TTF_GetGPUTextDrawData + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_GPUTextEngineWinding +{ + TTF_GPU_TEXTENGINE_WINDING_INVALID = -1, + TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE, + TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE +} TTF_GPUTextEngineWinding; + +/** + * Sets the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \param winding the new winding order option. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextEngineWinding + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetGPUTextEngineWinding(TTF_TextEngine *engine, TTF_GPUTextEngineWinding winding); + +/** + * Get the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \returns the winding order used by the GPU text engine or + * TTF_GPU_TEXTENGINE_WINDING_INVALID in case of error. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetGPUTextEngineWinding + */ +extern SDL_DECLSPEC TTF_GPUTextEngineWinding SDLCALL TTF_GetGPUTextEngineWinding(const TTF_TextEngine *engine); + +/** + * Create a text object from UTF-8 text and a text engine. + * + * \param engine the text engine to use when creating the text object, may be + * NULL. + * \param font the font to render with. + * \param text the text to use, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns a TTF_Text object or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font and text engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyText + */ +extern SDL_DECLSPEC TTF_Text * SDLCALL TTF_CreateText(TTF_TextEngine *engine, TTF_Font *font, const char *text, size_t length); + +/** + * Get the properties associated with a text object. + * + * \param text the TTF_Text to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetTextProperties(TTF_Text *text); + +/** + * Set the text engine used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param engine the text engine to use for drawing. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextEngine + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextEngine(TTF_Text *text, TTF_TextEngine *engine); + +/** + * Get the text engine used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_TextEngine used by the text on success or NULL on failure; + * call SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextEngine + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_GetTextEngine(TTF_Text *text); + +/** + * Set the font used by a text object. + * + * When a text object has a font, any changes to the font will automatically + * regenerate the text. If you set the font to NULL, the text will continue to + * render but changes to the font will no longer affect the text. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param font the font to use, may be NULL. + * \returns false if the text pointer is null; otherwise, true. call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextFont(TTF_Text *text, TTF_Font *font); + +/** + * Get the font used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_Font used by the text on success or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_GetTextFont(TTF_Text *text); + +/** + * Set the direction to be used for text shaping a text object. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * \param text the text to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextDirection(TTF_Text *text, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping a text object. + * + * This defaults to the direction of the font used by the text object. + * + * \param text the text to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetTextDirection(TTF_Text *text); + +/** + * Set the script to be used for text shaping a text object. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * \param text the text to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextScript(TTF_Text *text, Uint32 script); + +/** + * Get the script used for text shaping a text object. + * + * This defaults to the script of the font used by the text object. + * + * \param text the text to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set on either the text object or the + * font. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetTextScript(TTF_Text *text); + +/** + * Set the color of a text object. + * + * The default text color is white (255, 255, 255, 255). + * + * \param text the TTF_Text to modify. + * \param r the red color value in the range of 0-255. + * \param g the green color value in the range of 0-255. + * \param b the blue color value in the range of 0-255. + * \param a the alpha value in the range of 0-255. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColor(TTF_Text *text, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + +/** + * Set the color of a text object. + * + * The default text color is white (1.0f, 1.0f, 1.0f, 1.0f). + * + * \param text the TTF_Text to modify. + * \param r the red color value, normally in the range of 0-1. + * \param g the green color value, normally in the range of 0-1. + * \param b the blue color value, normally in the range of 0-1. + * \param a the alpha value in the range of 0-1. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColorFloat(TTF_Text *text, float r, float g, float b, float a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value in the range of + * 0-255, may be NULL. + * \param g a pointer filled in with the green color value in the range of + * 0-255, may be NULL. + * \param b a pointer filled in with the blue color value in the range of + * 0-255, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-255, + * may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColor(TTF_Text *text, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value, normally in the + * range of 0-1, may be NULL. + * \param g a pointer filled in with the green color value, normally in the + * range of 0-1, may be NULL. + * \param b a pointer filled in with the blue color value, normally in the + * range of 0-1, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-1, may + * be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColorFloat(TTF_Text *text, float *r, float *g, float *b, float *a); + +/** + * Set the position of a text object. + * + * This can be used to position multiple text objects within a single wrapping + * text area. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param x the x offset of the upper left corner of this text in pixels. + * \param y the y offset of the upper left corner of this text in pixels. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextPosition(TTF_Text *text, int x, int y); + +/** + * Get the position of a text object. + * + * \param text the TTF_Text to query. + * \param x a pointer filled in with the x offset of the upper left corner of + * this text in pixels, may be NULL. + * \param y a pointer filled in with the y offset of the upper left corner of + * this text in pixels, may be NULL. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextPosition(TTF_Text *text, int *x, int *y); + +/** + * Set whether wrapping is enabled on a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param wrap_width the maximum width in pixels, 0 to wrap on newline + * characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWidth(TTF_Text *text, int wrap_width); + +/** + * Get whether wrapping is enabled on a text object. + * + * \param text the TTF_Text to query. + * \param wrap_width a pointer filled in with the maximum width in pixels or 0 + * if the text is being wrapped on newline characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextWrapWidth(TTF_Text *text, int *wrap_width); + +/** + * Set whether whitespace should be visible when wrapping a text object. + * + * If the whitespace is visible, it will take up space for purposes of + * alignment and wrapping. This is good for editing, but looks better when + * centered or aligned if whitespace around line wrapping is hidden. This + * defaults false. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param visible true to show whitespace when wrapping text, false to hide + * it. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWhitespaceVisible(TTF_Text *text, bool visible); + +/** + * Return whether whitespace is shown when wrapping a text object. + * + * \param text the TTF_Text to query. + * \returns true if whitespace is shown when wrapping text, or false + * otherwise. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_TextWrapWhitespaceVisible(TTF_Text *text); + +/** + * Set the UTF-8 text used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to use, may be NULL. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Insert UTF-8 text into a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only insert + * at UTF-8 sequence boundaries. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_InsertTextString(TTF_Text *text, int offset, const char *string, size_t length); + +/** + * Append UTF-8 text to a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AppendTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Delete UTF-8 text from a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only delete + * at UTF-8 sequence boundaries. + * \param length the length of text to delete, in bytes, or -1 for the + * remainder of the string. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DeleteTextString(TTF_Text *text, int offset, int length); + +/** + * Get the size of a text object. + * + * The size of the text may change when the font or font style and size + * change. + * + * \param text the TTF_Text to query. + * \param w a pointer filled in with the width of the text, in pixels, may be + * NULL. + * \param h a pointer filled in with the height of the text, in pixels, may be + * NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSize(TTF_Text *text, int *w, int *h); + +/** + * Flags for TTF_SubString + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SubString + */ +typedef Uint32 TTF_SubStringFlags; + +#define TTF_SUBSTRING_DIRECTION_MASK 0x000000FF /**< The mask for the flow direction for this substring */ +#define TTF_SUBSTRING_TEXT_START 0x00000100 /**< This substring contains the beginning of the text */ +#define TTF_SUBSTRING_LINE_START 0x00000200 /**< This substring contains the beginning of line `line_index` */ +#define TTF_SUBSTRING_LINE_END 0x00000400 /**< This substring contains the end of line `line_index` */ +#define TTF_SUBSTRING_TEXT_END 0x00000800 /**< This substring contains the end of the text */ + +/** + * The representation of a substring within text. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetNextTextSubString + * \sa TTF_GetPreviousTextSubString + * \sa TTF_GetTextSubString + * \sa TTF_GetTextSubStringForLine + * \sa TTF_GetTextSubStringForPoint + * \sa TTF_GetTextSubStringsForRange + */ +typedef struct TTF_SubString +{ + TTF_SubStringFlags flags; /**< The flags for this substring */ + int offset; /**< The byte offset from the beginning of the text */ + int length; /**< The byte length starting at the offset */ + int line_index; /**< The index of the line that contains this substring */ + int cluster_index; /**< The internal cluster index, used for quickly iterating */ + SDL_Rect rect; /**< The rectangle, relative to the top left of the text, containing the substring */ +} TTF_SubString; + +/** + * Get the substring of a text object that surrounds a text offset. + * + * If `offset` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If + * `offset` is greater than or equal to the length of the text string, this + * will return a zero length substring at the end of the text with the + * TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubString(TTF_Text *text, int offset, TTF_SubString *substring); + +/** + * Get the substring of a text object that contains the given line. + * + * If `line` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If `line` + * is greater than or equal to `text->num_lines` this will return a zero + * length substring at the end of the text with the TTF_SUBSTRING_TEXT_END + * flag set. + * + * \param text the TTF_Text to query. + * \param line a zero-based line index, in the range [0 .. text->num_lines-1]. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForLine(TTF_Text *text, int line, TTF_SubString *substring); + +/** + * Get the substrings of a text object that contain a range of text. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param length the length of the range being queried, in bytes, or -1 for + * the remainder of the string. + * \param count a pointer filled in with the number of substrings returned, + * may be NULL. + * \returns a NULL terminated array of substring pointers or NULL on failure; + * call SDL_GetError() for more information. This is a single + * allocation that should be freed with SDL_free() when it is no + * longer needed. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_SubString ** SDLCALL TTF_GetTextSubStringsForRange(TTF_Text *text, int offset, int length, int *count); + +/** + * Get the portion of a text string that is closest to a point. + * + * This will return the closest substring of text to the given point. + * + * \param text the TTF_Text to query. + * \param x the x coordinate relative to the left side of the text, may be + * outside the bounds of the text area. + * \param y the y coordinate relative to the top side of the text, may be + * outside the bounds of the text area. + * \param substring a pointer filled in with the closest substring of text to + * the given point. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForPoint(TTF_Text *text, int x, int y, TTF_SubString *substring); + +/** + * Get the previous substring in a text object + * + * If called at the start of the text, this will return a zero length + * substring with the TTF_SUBSTRING_TEXT_START flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetPreviousTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *previous); + +/** + * Get the next substring in a text object + * + * If called at the end of the text, this will return a zero length substring + * with the TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \param next a pointer filled in with the next substring. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetNextTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *next); + +/** + * Update the layout of a text object. + * + * This is automatically done when the layout is requested or the text is + * rendered, but you can call this if you need more control over the timing of + * when the layout and text engine representation are updated. + * + * \param text the TTF_Text to update. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_UpdateText(TTF_Text *text); + +/** + * Destroy a text object created by a text engine. + * + * \param text the text to destroy. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyText(TTF_Text *text); + +/** + * Dispose of a previously-created font. + * + * Call this when done with a font. This function will free any resources + * associated with it. It is safe to call this function on NULL, for example + * on the result of a failed call to TTF_OpenFont(). + * + * The font is not valid after being passed to this function. String pointers + * from functions that return information on this font, such as + * TTF_GetFontFamilyName() and TTF_GetFontStyleName(), are no longer valid + * after this call, as well. + * + * \param font the font to dispose of. + * + * \threadsafety This function should not be called while any other thread is + * using the font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_OpenFont + * \sa TTF_OpenFontIO + */ +extern SDL_DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font); + +/** + * Deinitialize SDL_ttf. + * + * You must call this when done with the library, to free internal resources. + * It is safe to call this when the library isn't initialized, as it will just + * return immediately. + * + * Once you have as many quit calls as you have had successful calls to + * TTF_Init, the library will actually deinitialize. + * + * Please note that this does not automatically close any fonts that are still + * open at the time of deinitialization, and it is possibly not safe to close + * them afterwards, as parts of the library will no longer be initialized to + * deal with it. A well-written program should call TTF_CloseFont() on any + * open fonts before calling this function! + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_Quit(void); + +/** + * Check if SDL_ttf is initialized. + * + * This reports the number of times the library has been initialized by a call + * to TTF_Init(), without a paired deinitialization request from TTF_Quit(). + * + * In short: if it's greater than zero, the library is currently initialized + * and ready to work. If zero, it is not initialized. + * + * Despite the return value being a signed integer, this function should not + * return a negative number. + * + * \returns the current number of initialization calls, that need to + * eventually be paired with this many calls to TTF_Quit(). + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + * \sa TTF_Quit + */ +extern SDL_DECLSPEC int SDLCALL TTF_WasInit(void); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/INSTALL.md b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/INSTALL.md new file mode 100644 index 0000000..e11b671 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/INSTALL.md @@ -0,0 +1,35 @@ + +# Using this package + +This package contains SDL_ttf built for Xcode. + +To use this package in Xcode, drag `SDL3_ttf.framework` into your project. + +# Documentation + +An API reference and additional documentation is available at: + +https://wiki.libsdl.org/SDL3_ttf + +# Discussions + +## Discord + +You can join the official Discord server at: + +https://discord.com/invite/BwpFGBWsv8 + +## Forums/mailing lists + +You can join SDL development discussions at: + +https://discourse.libsdl.org/ + +Once you sign up, you can use the forum through the website or as a mailing list from your email client. + +## Announcement list + +You can sign up for the low traffic announcement list at: + +https://www.libsdl.org/mailing-list.php + diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/Info.plist b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/Info.plist new file mode 100644 index 0000000..56ab2e2 Binary files /dev/null and b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/Info.plist differ diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/LICENSE.txt b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/LICENSE.txt new file mode 100644 index 0000000..52d0ed3 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/LICENSE.txt @@ -0,0 +1,17 @@ +Copyright (C) 1997-2025 Sam Lantinga + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/README.md b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/README.md new file mode 100644 index 0000000..3a6a1e9 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/README.md @@ -0,0 +1,23 @@ + +SDL_ttf 3.0 + +This library is a wrapper around the FreeType and Harfbuzz libraries, allowing you to use TrueType fonts to render text in SDL applications. + +The latest version of this library is available from GitHub: +https://github.com/libsdl-org/SDL_ttf/releases + +Installation instructions and a quick introduction is available in +[INSTALL.md](INSTALL.md) + +This library is distributed under the terms of the zlib license, +available in [LICENSE.txt](LICENSE.txt). + +This library also uses the following libraries: +- FreeType, licensed under the [FTL](https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT) +- HarfBuzz, licensed under the [MIT license](https://github.com/harfbuzz/harfbuzz/blob/main/COPYING) +- PlutoSVG, licensed under the [MIT license](https://github.com/sammycage/plutosvg/blob/master/LICENSE) +- PlutoVG, licensed under the [MIT license](https://github.com/sammycage/plutovg/blob/master/LICENSE) + +Enjoy! + +Sam Lantinga (slouken@libsdl.org) diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/SDL3_ttf b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/SDL3_ttf new file mode 100755 index 0000000..d1b1f58 Binary files /dev/null and b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64/SDL3_ttf.framework/SDL3_ttf differ diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_textengine.h b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_textengine.h new file mode 100644 index 0000000..9f5f1f0 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_textengine.h @@ -0,0 +1,181 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + + +/** + * \file SDL_textengine.h + * + * Definitions for implementations of the TTF_TextEngine interface. + */ +#ifndef SDL_TTF_TEXTENGINE_H_ +#define SDL_TTF_TEXTENGINE_H_ + +#include +#include + +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A font atlas draw command. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_DrawCommand +{ + TTF_DRAW_COMMAND_NOOP, + TTF_DRAW_COMMAND_FILL, + TTF_DRAW_COMMAND_COPY +} TTF_DrawCommand; + +/** + * A filled rectangle draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_FillOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_FILL */ + SDL_Rect rect; /**< The rectangle to fill, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ +} TTF_FillOperation; + +/** + * A texture copy draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_DrawOperation + */ +typedef struct TTF_CopyOperation +{ + TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_COPY */ + int text_offset; /**< The offset in the text corresponding to this glyph. + There may be multiple glyphs with the same text offset + and the next text offset might be several Unicode codepoints + later. In this case the glyphs and codepoints are grouped + together and the group bounding box is the union of the dst + rectangles for the corresponding glyphs. */ + TTF_Font *glyph_font; /**< The font containing the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + Uint32 glyph_index; /**< The glyph index of the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */ + SDL_Rect src; /**< The area within the glyph to be drawn */ + SDL_Rect dst; /**< The drawing coordinates of the glyph, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */ + void *reserved; +} TTF_CopyOperation; + +/** + * A text engine draw operation. + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef union TTF_DrawOperation +{ + TTF_DrawCommand cmd; + TTF_FillOperation fill; + TTF_CopyOperation copy; +} TTF_DrawOperation; + + +/* Private data in TTF_Text, to assist in text measurement and layout */ +typedef struct TTF_TextLayout TTF_TextLayout; + + +/* Private data in TTF_Text, available to implementations */ +struct TTF_TextData +{ + TTF_Font *font; /**< The font used by this text, read-only. */ + SDL_FColor color; /**< The color of the text, read-only. */ + + bool needs_layout_update; /**< True if the layout needs to be updated */ + TTF_TextLayout *layout; /**< Cached layout information, read-only. */ + int x; /**< The x offset of the upper left corner of this text, in pixels, read-only. */ + int y; /**< The y offset of the upper left corner of this text, in pixels, read-only. */ + int w; /**< The width of this text, in pixels, read-only. */ + int h; /**< The height of this text, in pixels, read-only. */ + int num_ops; /**< The number of drawing operations to render this text, read-only. */ + TTF_DrawOperation *ops; /**< The drawing operations used to render this text, read-only. */ + int num_clusters; /**< The number of substrings representing clusters of glyphs in the string, read-only */ + TTF_SubString *clusters; /**< Substrings representing clusters of glyphs in the string, read-only */ + + SDL_PropertiesID props; /**< Custom properties associated with this text, read-only. This field is created as-needed using TTF_GetTextProperties() and the properties may be then set and read normally */ + + bool needs_engine_update; /**< True if the engine text needs to be updated */ + TTF_TextEngine *engine; /**< The engine used to render this text, read-only. */ + void *engine_text; /**< The implementation-specific representation of this text */ +}; + +/** + * A text engine interface. + * + * This structure should be initialized using SDL_INIT_INTERFACE() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa SDL_INIT_INTERFACE + */ +struct TTF_TextEngine +{ + Uint32 version; /**< The version of this interface */ + + void *userdata; /**< User data pointer passed to callbacks */ + + /* Create a text representation from draw instructions. + * + * All fields of `text` except `internal->engine_text` will already be filled out. + * + * This function should set the `internal->engine_text` field to a non-NULL value. + * + * \param userdata the userdata pointer in this interface. + * \param text the text object being created. + */ + bool (SDLCALL *CreateText)(void *userdata, TTF_Text *text); + + /** + * Destroy a text representation. + */ + void (SDLCALL *DestroyText)(void *userdata, TTF_Text *text); + +}; + +/* Check the size of TTF_TextEngine + * + * If this assert fails, either the compiler is padding to an unexpected size, + * or the interface has been updated and this should be updated to match and + * the code using this interface should be updated to handle the old version. + */ +SDL_COMPILE_TIME_ASSERT(TTF_TextEngine_SIZE, + (sizeof(void *) == 4 && sizeof(TTF_TextEngine) == 16) || + (sizeof(void *) == 8 && sizeof(TTF_TextEngine) == 32)); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_TEXTENGINE_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_ttf.h b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_ttf.h new file mode 100644 index 0000000..b723bc7 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/Headers/SDL_ttf.h @@ -0,0 +1,2833 @@ +/* + SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts + Copyright (C) 2001-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* WIKI CATEGORY: SDLTTF */ + +/** + * # CategorySDLTTF + * + * Header file for SDL_ttf library + * + * This library is a wrapper around the excellent FreeType 2.0 library, + * available at: https://www.freetype.org/ + */ + +#ifndef SDL_TTF_H_ +#define SDL_TTF_H_ + +#include +#include + +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO + */ +#define SDL_TTF_MAJOR_VERSION 3 +#define SDL_TTF_MINOR_VERSION 2 +#define SDL_TTF_MICRO_VERSION 2 + +/** + * This is the version number macro for the current SDL_ttf version. + */ +#define SDL_TTF_VERSION \ + SDL_VERSIONNUM(SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION) + +/** + * This macro will evaluate to true if compiled with SDL_ttf at least X.Y.Z. + */ +#define SDL_TTF_VERSION_ATLEAST(X, Y, Z) \ + ((SDL_TTF_MAJOR_VERSION >= X) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION >= Y) && \ + (SDL_TTF_MAJOR_VERSION > X || SDL_TTF_MINOR_VERSION > Y || SDL_TTF_MICRO_VERSION >= Z)) + +/** + * This function gets the version of the dynamically linked SDL_ttf library. + * + * \returns SDL_ttf version. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_Version(void); + +/** + * Query the version of the FreeType library in use. + * + * TTF_Init() should be called before calling this function. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetFreeTypeVersion(int *major, int *minor, int *patch); + +/** + * Query the version of the HarfBuzz library in use. + * + * If HarfBuzz is not available, the version reported is 0.0.0. + * + * \param major to be filled in with the major version number. Can be NULL. + * \param minor to be filled in with the minor version number. Can be NULL. + * \param patch to be filled in with the param version number. Can be NULL. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_GetHarfBuzzVersion(int *major, int *minor, int *patch); + +/** + * The internal structure containing font information. + * + * Opaque data! + */ +typedef struct TTF_Font TTF_Font; + +/** + * Initialize SDL_ttf. + * + * You must successfully call this function before it is safe to call any + * other function in this library. + * + * It is safe to call this more than once, and each successful TTF_Init() call + * should be paired with a matching TTF_Quit() call. + * + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Quit + */ +extern SDL_DECLSPEC bool SDLCALL TTF_Init(void); + +/** + * Create a font from a file, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param file path to font file. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFont(const char *file, float ptsize); + +/** + * Create a font from an SDL_IOStream, using a specified point size. + * + * Some .fon fonts will have several sizes embedded in the file, so the point + * size becomes the index of choosing which size. If the value is too high, + * the last indexed size will be the default. + * + * If `closeio` is true, `src` will be automatically closed once the font is + * closed. Otherwise you should close `src` yourself after closing the font. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param src an SDL_IOStream to provide a font file's data. + * \param closeio true to close `src` when the font is closed, false to leave + * it open. + * \param ptsize point size to use for the newly-opened font. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontIO(SDL_IOStream *src, bool closeio, float ptsize); + +/** + * Create a font with the specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_FONT_CREATE_FILENAME_STRING`: the font file to open, if an + * SDL_IOStream isn't being used. This is required if + * `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_POINTER`: an SDL_IOStream containing the + * font to be opened. This should not be closed until the font is closed. + * This is required if `TTF_PROP_FONT_CREATE_FILENAME_STRING` and + * `TTF_PROP_FONT_CREATE_EXISTING_FONT` aren't set. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER`: the offset in the iostream + * for the beginning of the font, defaults to 0. + * - `TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN`: true if closing the + * font should also close the associated SDL_IOStream. + * - `TTF_PROP_FONT_CREATE_SIZE_FLOAT`: the point size of the font. Some .fon + * fonts will have several sizes embedded in the file, so the point size + * becomes the index of choosing which size. If the value is too high, the + * last indexed size will be the default. + * - `TTF_PROP_FONT_CREATE_FACE_NUMBER`: the face index of the font, if the + * font contains multiple font faces. + * - `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER`: the horizontal DPI to use + * for font rendering, defaults to + * `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER` if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER`: the vertical DPI to use for + * font rendering, defaults to `TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER` + * if set, or 72 otherwise. + * - `TTF_PROP_FONT_CREATE_EXISTING_FONT`: an optional TTF_Font that, if set, + * will be used as the font data source and the initial size and style of + * the new font. + * + * \param props the properties to use. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_FONT_CREATE_FILENAME_STRING "SDL_ttf.font.create.filename" +#define TTF_PROP_FONT_CREATE_IOSTREAM_POINTER "SDL_ttf.font.create.iostream" +#define TTF_PROP_FONT_CREATE_IOSTREAM_OFFSET_NUMBER "SDL_ttf.font.create.iostream.offset" +#define TTF_PROP_FONT_CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN "SDL_ttf.font.create.iostream.autoclose" +#define TTF_PROP_FONT_CREATE_SIZE_FLOAT "SDL_ttf.font.create.size" +#define TTF_PROP_FONT_CREATE_FACE_NUMBER "SDL_ttf.font.create.face" +#define TTF_PROP_FONT_CREATE_HORIZONTAL_DPI_NUMBER "SDL_ttf.font.create.hdpi" +#define TTF_PROP_FONT_CREATE_VERTICAL_DPI_NUMBER "SDL_ttf.font.create.vdpi" +#define TTF_PROP_FONT_CREATE_EXISTING_FONT "SDL_ttf.font.create.existing_font" + +/** + * Create a copy of an existing font. + * + * The copy will be distinct from the original, but will share the font file + * and have the same size and style as the original. + * + * When done with the returned TTF_Font, use TTF_CloseFont() to dispose of it. + * + * \param existing_font the font to copy. + * \returns a valid TTF_Font, or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * original font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CloseFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_CopyFont(TTF_Font *existing_font); + +/** + * Get the properties associated with a font. + * + * The following read-write properties are provided by SDL: + * + * - `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`: The FT_Stroker_LineCap value + * used when setting the font outline, defaults to + * `FT_STROKER_LINECAP_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`: The FT_Stroker_LineJoin value + * used when setting the font outline, defaults to + * `FT_STROKER_LINEJOIN_ROUND`. + * - `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER`: The FT_Fixed miter limit used + * when setting the font outline, defaults to 0. + * + * \param font the font to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetFontProperties(TTF_Font *font); + +#define TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER "SDL_ttf.font.outline.line_cap" +#define TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER "SDL_ttf.font.outline.line_join" +#define TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER "SDL_ttf.font.outline.miter_limit" + +/** + * Get the font generation. + * + * The generation is incremented each time font properties change that require + * rebuilding glyphs, such as style, size, etc. + * + * \param font the font to query. + * \returns the font generation or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontGeneration(TTF_Font *font); + +/** + * Add a fallback font. + * + * Add a font that will be used for glyphs that are not in the current font. + * The fallback font should have the same size and style as the current font. + * + * If there are multiple fallback fonts, they are used in the order added. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to add as a fallback. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_ClearFallbackFonts + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AddFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove a fallback font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param fallback the font to remove as a fallback. + * + * \threadsafety This function should be called on the thread that created + * both fonts. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_ClearFallbackFonts + */ +extern SDL_DECLSPEC void SDLCALL TTF_RemoveFallbackFont(TTF_Font *font, TTF_Font *fallback); + +/** + * Remove all fallback fonts. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AddFallbackFont + * \sa TTF_RemoveFallbackFont + */ +extern SDL_DECLSPEC void SDLCALL TTF_ClearFallbackFonts(TTF_Font *font); + +/** + * Set a font's size dynamically. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSize(TTF_Font *font, float ptsize); + +/** + * Set font size dynamically with target resolutions, in dots per inch. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to resize. + * \param ptsize the new point size. + * \param hdpi the target horizontal DPI. + * \param vdpi the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSize + * \sa TTF_GetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSizeDPI(TTF_Font *font, float ptsize, int hdpi, int vdpi); + +/** + * Get the size of a font. + * + * \param font the font to query. + * \returns the size of the font, or 0.0f on failure; call SDL_GetError() for + * more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSize + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC float SDLCALL TTF_GetFontSize(TTF_Font *font); + +/** + * Get font target resolutions, in dots per inch. + * + * \param font the font to query. + * \param hdpi a pointer filled in with the target horizontal DPI. + * \param vdpi a pointer filled in with the target vertical DPI. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSizeDPI + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontDPI(TTF_Font *font, int *hdpi, int *vdpi); + +/** + * Font style flags for TTF_Font + * + * These are the flags which can be used to set the style of a font in + * SDL_ttf. A combination of these flags can be used with functions that set + * or query font style, such as TTF_SetFontStyle or TTF_GetFontStyle. + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + * \sa TTF_GetFontStyle + */ +typedef Uint32 TTF_FontStyleFlags; + +#define TTF_STYLE_NORMAL 0x00 /**< No special style */ +#define TTF_STYLE_BOLD 0x01 /**< Bold style */ +#define TTF_STYLE_ITALIC 0x02 /**< Italic style */ +#define TTF_STYLE_UNDERLINE 0x04 /**< Underlined text */ +#define TTF_STYLE_STRIKETHROUGH 0x08 /**< Strikethrough text */ + +/** + * Set a font's current style. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to set a new style on. + * \param style the new style values to set, OR'd together. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontStyle + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontStyle(TTF_Font *font, TTF_FontStyleFlags style); + +/** + * Query a font's current style. + * + * The font styles are a set of bit flags, OR'd together: + * + * - `TTF_STYLE_NORMAL` (is zero) + * - `TTF_STYLE_BOLD` + * - `TTF_STYLE_ITALIC` + * - `TTF_STYLE_UNDERLINE` + * - `TTF_STYLE_STRIKETHROUGH` + * + * \param font the font to query. + * \returns the current font style, as a set of bit flags. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontStyle + */ +extern SDL_DECLSPEC TTF_FontStyleFlags SDLCALL TTF_GetFontStyle(const TTF_Font *font); + +/** + * Set a font's current outline. + * + * This uses the font properties `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`, + * `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`, and + * `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER` when setting the font outline. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set a new outline on. + * \param outline positive outline value, 0 to default. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontOutline + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontOutline(TTF_Font *font, int outline); + +/** + * Query a font's current outline. + * + * \param font the font to query. + * \returns the font's current outline value. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontOutline + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontOutline(const TTF_Font *font); + +/** + * Hinting flags for TTF (TrueType Fonts) + * + * This enum specifies the level of hinting to be applied to the font + * rendering. The hinting level determines how much the font's outlines are + * adjusted for better alignment on the pixel grid. + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + * \sa TTF_GetFontHinting + */ +typedef enum TTF_HintingFlags +{ + TTF_HINTING_INVALID = -1, + TTF_HINTING_NORMAL, /**< Normal hinting applies standard grid-fitting. */ + TTF_HINTING_LIGHT, /**< Light hinting applies subtle adjustments to improve rendering. */ + TTF_HINTING_MONO, /**< Monochrome hinting adjusts the font for better rendering at lower resolutions. */ + TTF_HINTING_NONE, /**< No hinting, the font is rendered without any grid-fitting. */ + TTF_HINTING_LIGHT_SUBPIXEL /**< Light hinting with subpixel rendering for more precise font edges. */ +} TTF_HintingFlags; + +/** + * Set a font's current hinter setting. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to set a new hinter setting on. + * \param hinting the new hinter setting. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontHinting + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontHinting(TTF_Font *font, TTF_HintingFlags hinting); + +/** + * Query the number of faces of a font. + * + * \param font the font to query. + * \returns the number of FreeType font faces. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetNumFontFaces(const TTF_Font *font); + +/** + * Query a font's current FreeType hinter setting. + * + * The hinter setting is a single value: + * + * - `TTF_HINTING_NORMAL` + * - `TTF_HINTING_LIGHT` + * - `TTF_HINTING_MONO` + * - `TTF_HINTING_NONE` + * - `TTF_HINTING_LIGHT_SUBPIXEL` (available in SDL_ttf 3.0.0 and later) + * + * \param font the font to query. + * \returns the font's current hinter value, or TTF_HINTING_INVALID if the + * font is invalid. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontHinting + */ +extern SDL_DECLSPEC TTF_HintingFlags SDLCALL TTF_GetFontHinting(const TTF_Font *font); + +/** + * Enable Signed Distance Field rendering for a font. + * + * SDF is a technique that helps fonts look sharp even when scaling and + * rotating, and requires special shader support for display. + * + * This works with Blended APIs, and generates the raw signed distance values + * in the alpha channel of the resulting texture. + * + * This updates any TTF_Text objects using this font, and clears + * already-generated glyphs, if any, from the cache. + * + * \param font the font to set SDF support on. + * \param enabled true to enable SDF, false to disable. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontSDF(TTF_Font *font, bool enabled); + +/** + * Query whether Signed Distance Field rendering is enabled for a font. + * + * \param font the font to query. + * \returns true if enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontSDF(const TTF_Font *font); + +/** + * Query a font's weight, in terms of the lightness/heaviness of the strokes. + * + * \param font the font to query. + * \returns the font's current weight. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.4.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontWeight(const TTF_Font *font); + +#define TTF_FONT_WEIGHT_THIN 100 /**< Thin (100) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_LIGHT 200 /**< ExtraLight (200) named font weight value */ +#define TTF_FONT_WEIGHT_LIGHT 300 /**< Light (300) named font weight value */ +#define TTF_FONT_WEIGHT_NORMAL 400 /**< Normal (400) named font weight value */ +#define TTF_FONT_WEIGHT_MEDIUM 500 /**< Medium (500) named font weight value */ +#define TTF_FONT_WEIGHT_SEMI_BOLD 600 /**< SemiBold (600) named font weight value */ +#define TTF_FONT_WEIGHT_BOLD 700 /**< Bold (700) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BOLD 800 /**< ExtraBold (800) named font weight value */ +#define TTF_FONT_WEIGHT_BLACK 900 /**< Black (900) named font weight value */ +#define TTF_FONT_WEIGHT_EXTRA_BLACK 950 /**< ExtraBlack (950) named font weight value */ + +/** + * The horizontal alignment used when rendering wrapped text. + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_HorizontalAlignment +{ + TTF_HORIZONTAL_ALIGN_INVALID = -1, + TTF_HORIZONTAL_ALIGN_LEFT, + TTF_HORIZONTAL_ALIGN_CENTER, + TTF_HORIZONTAL_ALIGN_RIGHT +} TTF_HorizontalAlignment; + +/** + * Set a font's current wrap alignment option. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set a new wrap alignment option on. + * \param align the new wrap alignment option. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontWrapAlignment + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontWrapAlignment(TTF_Font *font, TTF_HorizontalAlignment align); + +/** + * Query a font's current wrap alignment option. + * + * \param font the font to query. + * \returns the font's current wrap alignment option. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontWrapAlignment + */ +extern SDL_DECLSPEC TTF_HorizontalAlignment SDLCALL TTF_GetFontWrapAlignment(const TTF_Font *font); + +/** + * Query the total height of a font. + * + * This is usually equal to point size. + * + * \param font the font to query. + * \returns the font's height. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontHeight(const TTF_Font *font); + +/** + * Query the offset from the baseline to the top of a font. + * + * This is a positive value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's ascent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontAscent(const TTF_Font *font); + +/** + * Query the offset from the baseline to the bottom of a font. + * + * This is a negative value, relative to the baseline. + * + * \param font the font to query. + * \returns the font's descent. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontDescent(const TTF_Font *font); + +/** + * Set the spacing between lines of text for a font. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param lineskip the new line spacing for the font. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontLineSkip + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontLineSkip(TTF_Font *font, int lineskip); + +/** + * Query the spacing between lines of text for a font. + * + * \param font the font to query. + * \returns the font's recommended spacing. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontLineSkip + */ +extern SDL_DECLSPEC int SDLCALL TTF_GetFontLineSkip(const TTF_Font *font); + +/** + * Set if kerning is enabled for a font. + * + * Newly-opened fonts default to allowing kerning. This is generally a good + * policy unless you have a strong reason to disable it, as it tends to + * produce better rendering (with kerning disabled, some fonts might render + * the word `kerning` as something that looks like `keming` for example). + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to set kerning on. + * \param enabled true to enable kerning, false to disable. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetFontKerning + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetFontKerning(TTF_Font *font, bool enabled); + +/** + * Query whether or not kerning is enabled for a font. + * + * \param font the font to query. + * \returns true if kerning is enabled, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontKerning + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetFontKerning(const TTF_Font *font); + +/** + * Query whether a font is fixed-width. + * + * A "fixed-width" font means all glyphs are the same width across; a + * lowercase 'i' will be the same size across as a capital 'W', for example. + * This is common for terminals and text editors, and other apps that treat + * text as a grid. Most other things (WYSIWYG word processors, web pages, etc) + * are more likely to not be fixed-width in most cases. + * + * \param font the font to query. + * \returns true if the font is fixed-width, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsFixedWidth(const TTF_Font *font); + +/** + * Query whether a font is scalable or not. + * + * Scalability lets us distinguish between outline and bitmap fonts. + * + * \param font the font to query. + * \returns true if the font is scalable, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontSDF + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontIsScalable(const TTF_Font *font); + +/** + * Query a font's family name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's family name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontFamilyName(const TTF_Font *font); + +/** + * Query a font's style name. + * + * This string is dictated by the contents of the font file. + * + * Note that the returned string is to internal storage, and should not be + * modified or free'd by the caller. The string becomes invalid, with the rest + * of the font, when `font` is handed to TTF_CloseFont(). + * + * \param font the font to query. + * \returns the font's style name. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC const char * SDLCALL TTF_GetFontStyleName(const TTF_Font *font); + +/** + * Direction flags + * + * The values here are chosen to match + * [hb_direction_t](https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-direction-t) + * . + * + * \since This enum is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetFontDirection + */ +typedef enum TTF_Direction +{ + TTF_DIRECTION_INVALID = 0, + TTF_DIRECTION_LTR = 4, /**< Left to Right */ + TTF_DIRECTION_RTL, /**< Right to Left */ + TTF_DIRECTION_TTB, /**< Top to Bottom */ + TTF_DIRECTION_BTT /**< Bottom to Top */ +} TTF_Direction; + +/** + * Set the direction to be used for text shaping by a font. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping by a font. + * + * This defaults to TTF_DIRECTION_INVALID if it hasn't been set. + * + * \param font the font to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetFontDirection(TTF_Font *font); + +/** + * Convert from a 4 character string to a 32-bit tag. + * + * \param string the 4 character string to convert. + * \returns the 32-bit representation of the string. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_StringToTag(const char *string); + +/** + * Convert from a 32-bit tag to a 4 character string. + * + * \param tag the 32-bit tag to convert. + * \param string a pointer filled in with the 4 character representation of + * the tag. + * \param size the size of the buffer pointed at by string, should be at least + * 4. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC void SDLCALL TTF_TagToString(Uint32 tag, char *string, size_t size); + +/** + * Set the script to be used for text shaping by a font. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontScript(TTF_Font *font, Uint32 script); + +/** + * Get the script used for text shaping a font. + * + * \param font the font to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetFontScript(TTF_Font *font); + +/** + * Get the script used by a 32-bit codepoint. + * + * \param ch the character code to check. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * on success, or 0 on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function is thread-safe. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetGlyphScript(Uint32 ch); + +/** + * Set language to be used for text shaping by a font. + * + * If SDL_ttf was not built with HarfBuzz support, this function returns + * false. + * + * This updates any TTF_Text objects using this font. + * + * \param font the font to specify a language for. + * \param language_bcp47 a null-terminated string containing the desired + * language's BCP47 code. Or null to reset the value. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47); + +/** + * Check whether a glyph is provided by the font for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \returns true if font provides a glyph for this character, false if not. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_FontHasGlyph(TTF_Font *font, Uint32 ch); + +/** + * The type of data in a glyph image + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_ImageType +{ + TTF_IMAGE_INVALID, + TTF_IMAGE_ALPHA, /**< The color channels are white */ + TTF_IMAGE_COLOR, /**< The color channels have image data */ + TTF_IMAGE_SDF, /**< The alpha channel has signed distance field information */ +} TTF_ImageType; + +/** + * Get the pixel image for a UNICODE codepoint. + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImage(TTF_Font *font, Uint32 ch, TTF_ImageType *image_type); + +/** + * Get the pixel image for a character index. + * + * This is useful for text engine implementations, which can call this with + * the `glyph_index` in a TTF_CopyOperation + * + * \param font the font to query. + * \param glyph_index the index of the glyph to return. + * \param image_type a pointer filled in with the glyph image type, may be + * NULL. + * \returns an SDL_Surface containing the glyph, or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_GetGlyphImageForIndex(TTF_Font *font, Uint32 glyph_index, TTF_ImageType *image_type); + +/** + * Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint. + * + * To understand what these metrics mean, here is a useful link: + * + * https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html + * + * \param font the font to query. + * \param ch the codepoint to check. + * \param minx a pointer filled in with the minimum x coordinate of the glyph + * from the left edge of its bounding box. This value may be + * negative. + * \param maxx a pointer filled in with the maximum x coordinate of the glyph + * from the left edge of its bounding box. + * \param miny a pointer filled in with the minimum y coordinate of the glyph + * from the bottom edge of its bounding box. This value may be + * negative. + * \param maxy a pointer filled in with the maximum y coordinate of the glyph + * from the bottom edge of its bounding box. + * \param advance a pointer filled in with the distance to the next glyph from + * the left edge of this glyph's bounding box. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphMetrics(TTF_Font *font, Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance); + +/** + * Query the kerning size between the glyphs of two UNICODE codepoints. + * + * \param font the font to query. + * \param previous_ch the previous codepoint. + * \param ch the current codepoint. + * \param kerning a pointer filled in with the kerning size between the two + * glyphs, in pixels, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphKerning(TTF_Font *font, Uint32 previous_ch, Uint32 ch, int *kerning); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSize(TTF_Font *font, const char *text, size_t length, int *w, int *h); + +/** + * Calculate the dimensions of a rendered string of UTF-8 text. + * + * This will report the width and height, in pixels, of the space that the + * specified string will take to fully render. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param wrap_width the maximum width or 0 to wrap on newline characters. + * \param w will be filled with width, in pixels, on return. + * \param h will be filled with height, in pixels, on return. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSizeWrapped(TTF_Font *font, const char *text, size_t length, int wrap_width, int *w, int *h); + +/** + * Calculate how much of a UTF-8 string will fit in a given width. + * + * This reports the number of characters that can be rendered before reaching + * `max_width`. + * + * This does not need to render the string to do this calculation. + * + * \param font the font to query. + * \param text text to calculate, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param max_width maximum width, in pixels, available for the string, or 0 + * for unbounded width. + * \param measured_width a pointer filled in with the width, in pixels, of the + * string that will fit, may be NULL. + * \param measured_length a pointer filled in with the length, in bytes, of + * the string that will fit, may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_MeasureString(TTF_Font *font, const char *text, size_t length, int max_width, int *measured_width, size_t *measured_length); + +/** + * Render UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Solid_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrapLength` in pixels. + * + * If wrapLength is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Shaded_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrapLength the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrapLength); + +/** + * Render a single 32-bit glyph at fast quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the colorkey, giving a transparent background. The 1 pixel + * will be set to the text color. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Shaded, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the character to render. + * \param fg the foreground color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Solid(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Shaded_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Blended, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Blended_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new 8-bit surface. + * + * This function will allocate a new 8-bit, palettized surface. The surface's + * 0 pixel will be the specified background color, while other pixels have + * varying degrees of the foreground color. This function returns the new + * surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Blended, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 8-bit, palettized surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Shaded(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + +/** + * Render UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_Blended_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_LCD. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended(TTF_Font *font, const char *text, size_t length, SDL_Color fg); + +/** + * Render word-wrapped UTF-8 text at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_LCD_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, int wrap_width); + +/** + * Render a single UNICODE codepoint at high quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, using alpha + * blending to dither the font with the given color. This function returns the + * new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_LCD. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_LCD + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font, Uint32 ch, SDL_Color fg); + +/** + * Render UTF-8 text at LCD subpixel quality to a new ARGB surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * This will not word-wrap the string; you'll get a surface with a single line + * of text, as long as the string requires. You can use + * TTF_RenderText_LCD_Wrapped() instead if you need to wrap the output to + * multiple lines. + * + * This will not wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid, + * TTF_RenderText_Shaded, and TTF_RenderText_Blended. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended + * \sa TTF_RenderText_LCD_Wrapped + * \sa TTF_RenderText_Shaded + * \sa TTF_RenderText_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg); + +/** + * Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * Text is wrapped to multiple lines on line endings and on word boundaries if + * it extends beyond `wrap_width` in pixels. + * + * If wrap_width is 0, this function will only wrap on newline characters. + * + * You can render at other quality levels with TTF_RenderText_Solid_Wrapped, + * TTF_RenderText_Shaded_Wrapped, and TTF_RenderText_Blended_Wrapped. + * + * \param font the font to render with. + * \param text text to render, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \param wrap_width the maximum width of the text surface or 0 to wrap on + * newline characters. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderText_Blended_Wrapped + * \sa TTF_RenderText_LCD + * \sa TTF_RenderText_Shaded_Wrapped + * \sa TTF_RenderText_Solid_Wrapped + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_LCD_Wrapped(TTF_Font *font, const char *text, size_t length, SDL_Color fg, SDL_Color bg, int wrap_width); + +/** + * Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB + * surface. + * + * This function will allocate a new 32-bit, ARGB surface, and render + * alpha-blended text using FreeType's LCD subpixel rendering. This function + * returns the new surface, or NULL if there was an error. + * + * The glyph is rendered without any padding or centering in the X direction, + * and aligned normally in the Y direction. + * + * You can render at other quality levels with TTF_RenderGlyph_Solid, + * TTF_RenderGlyph_Shaded, and TTF_RenderGlyph_Blended. + * + * \param font the font to render with. + * \param ch the codepoint to render. + * \param fg the foreground color for the text. + * \param bg the background color for the text. + * \returns a new 32-bit, ARGB surface, or NULL if there was an error. + * + * \threadsafety This function should be called on the thread that created the + * font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_RenderGlyph_Blended + * \sa TTF_RenderGlyph_Shaded + * \sa TTF_RenderGlyph_Solid + */ +extern SDL_DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_LCD(TTF_Font *font, Uint32 ch, SDL_Color fg, SDL_Color bg); + + +/** + * A text engine used to create text objects. + * + * This is a public interface that can be used by applications and libraries + * to perform customize rendering with text objects. See + * for details. + * + * There are three text engines provided with the library: + * + * - Drawing to an SDL_Surface, created with TTF_CreateSurfaceTextEngine() + * - Drawing with an SDL 2D renderer, created with + * TTF_CreateRendererTextEngine() + * - Drawing with the SDL GPU API, created with TTF_CreateGPUTextEngine() + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextEngine TTF_TextEngine; + +/** + * Internal data for TTF_Text + * + * \since This struct is available since SDL_ttf 3.0.0. + */ +typedef struct TTF_TextData TTF_TextData; + +/** + * Text created with TTF_CreateText() + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + * \sa TTF_GetTextProperties + * \sa TTF_DestroyText + */ +typedef struct TTF_Text +{ + char *text; /**< A copy of the UTF-8 string that this text object represents, useful for layout, debugging and retrieving substring text. This is updated when the text object is modified and will be freed automatically when the object is destroyed. */ + int num_lines; /**< The number of lines in the text, 0 if it's empty */ + + int refcount; /**< Application reference count, used when freeing surface */ + + TTF_TextData *internal; /**< Private */ + +} TTF_Text; + +/** + * Create a text engine for drawing text on SDL surfaces. + * + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroySurfaceTextEngine + * \sa TTF_DrawSurfaceText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateSurfaceTextEngine(void); + +/** + * Draw text to an SDL surface. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateSurfaceTextEngine(). + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \param surface the surface to draw on. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawSurfaceText(TTF_Text *text, int x, int y, SDL_Surface *surface); + +/** + * Destroy a text engine created for drawing text on SDL surfaces. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateSurfaceTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateSurfaceTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroySurfaceTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text on an SDL renderer. + * + * \param renderer the renderer to use for creating textures and drawing text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + * \sa TTF_CreateRendererTextEngineWithProperties + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngine(SDL_Renderer *renderer); + +/** + * Create a text engine for drawing text on an SDL renderer, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER`: the renderer to use for + * creating textures and drawing text + * - `TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the + * texture atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * renderer. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_DestroyRendererTextEngine + * \sa TTF_DrawRendererText + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateRendererTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_RENDERER_TEXT_ENGINE_RENDERER "SDL_ttf.renderer_text_engine.create.renderer" +#define TTF_PROP_RENDERER_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.renderer_text_engine.create.atlas_texture_size" + +/** + * Draw text to an SDL renderer. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateRendererTextEngine(), and will draw using the renderer passed to + * that function. + * + * \param text the text to draw. + * \param x the x coordinate in pixels, positive from the left edge towards + * the right. + * \param y the y coordinate in pixels, positive from the top edge towards the + * bottom. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DrawRendererText(TTF_Text *text, float x, float y); + +/** + * Destroy a text engine created for drawing text on an SDL renderer. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateRendererTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateRendererTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyRendererTextEngine(TTF_TextEngine *engine); + +/** + * Create a text engine for drawing text with the SDL GPU API. + * + * \param device the SDL_GPUDevice to use for creating textures and drawing + * text. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngineWithProperties + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngine(SDL_GPUDevice *device); + +/** + * Create a text engine for drawing text with the SDL GPU API, with the + * specified properties. + * + * These are the supported properties: + * + * - `TTF_PROP_GPU_TEXT_ENGINE_DEVICE`: the SDL_GPUDevice to use for creating + * textures and drawing text. + * - `TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE`: the size of the texture + * atlas + * + * \param props the properties to use. + * \returns a TTF_TextEngine object or NULL on failure; call SDL_GetError() + * for more information. + * + * \threadsafety This function should be called on the thread that created the + * device. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_DestroyGPUTextEngine + * \sa TTF_GetGPUTextDrawData + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_CreateGPUTextEngineWithProperties(SDL_PropertiesID props); + +#define TTF_PROP_GPU_TEXT_ENGINE_DEVICE "SDL_ttf.gpu_text_engine.create.device" +#define TTF_PROP_GPU_TEXT_ENGINE_ATLAS_TEXTURE_SIZE "SDL_ttf.gpu_text_engine.create.atlas_texture_size" + +/** + * Draw sequence returned by TTF_GetGPUTextDrawData + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextDrawData + */ +typedef struct TTF_GPUAtlasDrawSequence +{ + SDL_GPUTexture *atlas_texture; /**< Texture atlas that stores the glyphs */ + SDL_FPoint *xy; /**< An array of vertex positions */ + SDL_FPoint *uv; /**< An array of normalized texture coordinates for each vertex */ + int num_vertices; /**< Number of vertices */ + int *indices; /**< An array of indices into the 'vertices' arrays */ + int num_indices; /**< Number of indices */ + TTF_ImageType image_type; /**< The image type of this draw sequence */ + + struct TTF_GPUAtlasDrawSequence *next; /**< The next sequence (will be NULL in case of the last sequence) */ +} TTF_GPUAtlasDrawSequence; + +/** + * Get the geometry data needed for drawing the text. + * + * `text` must have been created using a TTF_TextEngine from + * TTF_CreateGPUTextEngine(). + * + * The positive X-axis is taken towards the right and the positive Y-axis is + * taken upwards for both the vertex and the texture coordinates, i.e, it + * follows the same convention used by the SDL_GPU API. If you want to use a + * different coordinate system you will need to transform the vertices + * yourself. + * + * If the text looks blocky use linear filtering. + * + * \param text the text to draw. + * \returns a NULL terminated linked list of TTF_GPUAtlasDrawSequence objects + * or NULL if the passed text is empty or in case of failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC TTF_GPUAtlasDrawSequence * SDLCALL TTF_GetGPUTextDrawData(TTF_Text *text); + +/** + * Destroy a text engine created for drawing text with the SDL GPU API. + * + * All text created by this engine should be destroyed before calling this + * function. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateGPUTextEngine + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyGPUTextEngine(TTF_TextEngine *engine); + +/** + * The winding order of the vertices returned by TTF_GetGPUTextDrawData + * + * \since This enum is available since SDL_ttf 3.0.0. + */ +typedef enum TTF_GPUTextEngineWinding +{ + TTF_GPU_TEXTENGINE_WINDING_INVALID = -1, + TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE, + TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE +} TTF_GPUTextEngineWinding; + +/** + * Sets the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine. + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \param winding the new winding order option. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetGPUTextEngineWinding + */ +extern SDL_DECLSPEC void SDLCALL TTF_SetGPUTextEngineWinding(TTF_TextEngine *engine, TTF_GPUTextEngineWinding winding); + +/** + * Get the winding order of the vertices returned by TTF_GetGPUTextDrawData + * for a particular GPU text engine + * + * \param engine a TTF_TextEngine object created with + * TTF_CreateGPUTextEngine(). + * \returns the winding order used by the GPU text engine or + * TTF_GPU_TEXTENGINE_WINDING_INVALID in case of error. + * + * \threadsafety This function should be called on the thread that created the + * engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetGPUTextEngineWinding + */ +extern SDL_DECLSPEC TTF_GPUTextEngineWinding SDLCALL TTF_GetGPUTextEngineWinding(const TTF_TextEngine *engine); + +/** + * Create a text object from UTF-8 text and a text engine. + * + * \param engine the text engine to use when creating the text object, may be + * NULL. + * \param font the font to render with. + * \param text the text to use, in UTF-8 encoding. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns a TTF_Text object or NULL on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * font and text engine. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DestroyText + */ +extern SDL_DECLSPEC TTF_Text * SDLCALL TTF_CreateText(TTF_TextEngine *engine, TTF_Font *font, const char *text, size_t length); + +/** + * Get the properties associated with a text object. + * + * \param text the TTF_Text to query. + * \returns a valid property ID on success or 0 on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetTextProperties(TTF_Text *text); + +/** + * Set the text engine used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param engine the text engine to use for drawing. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextEngine + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextEngine(TTF_Text *text, TTF_TextEngine *engine); + +/** + * Get the text engine used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_TextEngine used by the text on success or NULL on failure; + * call SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextEngine + */ +extern SDL_DECLSPEC TTF_TextEngine * SDLCALL TTF_GetTextEngine(TTF_Text *text); + +/** + * Set the font used by a text object. + * + * When a text object has a font, any changes to the font will automatically + * regenerate the text. If you set the font to NULL, the text will continue to + * render but changes to the font will no longer affect the text. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param font the font to use, may be NULL. + * \returns false if the text pointer is null; otherwise, true. call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextFont + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextFont(TTF_Text *text, TTF_Font *font); + +/** + * Get the font used by a text object. + * + * \param text the TTF_Text to query. + * \returns the TTF_Font used by the text on success or NULL on failure; call + * SDL_GetError() for more information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextFont + */ +extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_GetTextFont(TTF_Text *text); + +/** + * Set the direction to be used for text shaping a text object. + * + * This function only supports left-to-right text shaping if SDL_ttf was not + * built with HarfBuzz support. + * + * \param text the text to modify. + * \param direction the new direction for text to flow. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextDirection(TTF_Text *text, TTF_Direction direction); + +/** + * Get the direction to be used for text shaping a text object. + * + * This defaults to the direction of the font used by the text object. + * + * \param text the text to query. + * \returns the direction to be used for text shaping. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_Direction SDLCALL TTF_GetTextDirection(TTF_Text *text); + +/** + * Set the script to be used for text shaping a text object. + * + * This returns false if SDL_ttf isn't built with HarfBuzz support. + * + * \param text the text to modify. + * \param script an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * . + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_StringToTag + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextScript(TTF_Text *text, Uint32 script); + +/** + * Get the script used for text shaping a text object. + * + * This defaults to the script of the font used by the text object. + * + * \param text the text to query. + * \returns an + * [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html) + * or 0 if a script hasn't been set on either the text object or the + * font. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TagToString + */ +extern SDL_DECLSPEC Uint32 SDLCALL TTF_GetTextScript(TTF_Text *text); + +/** + * Set the color of a text object. + * + * The default text color is white (255, 255, 255, 255). + * + * \param text the TTF_Text to modify. + * \param r the red color value in the range of 0-255. + * \param g the green color value in the range of 0-255. + * \param b the blue color value in the range of 0-255. + * \param a the alpha value in the range of 0-255. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColor(TTF_Text *text, Uint8 r, Uint8 g, Uint8 b, Uint8 a); + +/** + * Set the color of a text object. + * + * The default text color is white (1.0f, 1.0f, 1.0f, 1.0f). + * + * \param text the TTF_Text to modify. + * \param r the red color value, normally in the range of 0-1. + * \param g the green color value, normally in the range of 0-1. + * \param b the blue color value, normally in the range of 0-1. + * \param a the alpha value in the range of 0-1. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextColorFloat(TTF_Text *text, float r, float g, float b, float a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value in the range of + * 0-255, may be NULL. + * \param g a pointer filled in with the green color value in the range of + * 0-255, may be NULL. + * \param b a pointer filled in with the blue color value in the range of + * 0-255, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-255, + * may be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColorFloat + * \sa TTF_SetTextColor + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColor(TTF_Text *text, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); + +/** + * Get the color of a text object. + * + * \param text the TTF_Text to query. + * \param r a pointer filled in with the red color value, normally in the + * range of 0-1, may be NULL. + * \param g a pointer filled in with the green color value, normally in the + * range of 0-1, may be NULL. + * \param b a pointer filled in with the blue color value, normally in the + * range of 0-1, may be NULL. + * \param a a pointer filled in with the alpha value in the range of 0-1, may + * be NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextColor + * \sa TTF_SetTextColorFloat + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextColorFloat(TTF_Text *text, float *r, float *g, float *b, float *a); + +/** + * Set the position of a text object. + * + * This can be used to position multiple text objects within a single wrapping + * text area. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param x the x offset of the upper left corner of this text in pixels. + * \param y the y offset of the upper left corner of this text in pixels. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextPosition(TTF_Text *text, int x, int y); + +/** + * Get the position of a text object. + * + * \param text the TTF_Text to query. + * \param x a pointer filled in with the x offset of the upper left corner of + * this text in pixels, may be NULL. + * \param y a pointer filled in with the y offset of the upper left corner of + * this text in pixels, may be NULL. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextPosition + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextPosition(TTF_Text *text, int *x, int *y); + +/** + * Set whether wrapping is enabled on a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param wrap_width the maximum width in pixels, 0 to wrap on newline + * characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWidth(TTF_Text *text, int wrap_width); + +/** + * Get whether wrapping is enabled on a text object. + * + * \param text the TTF_Text to query. + * \param wrap_width a pointer filled in with the maximum width in pixels or 0 + * if the text is being wrapped on newline characters. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWidth + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextWrapWidth(TTF_Text *text, int *wrap_width); + +/** + * Set whether whitespace should be visible when wrapping a text object. + * + * If the whitespace is visible, it will take up space for purposes of + * alignment and wrapping. This is good for editing, but looks better when + * centered or aligned if whitespace around line wrapping is hidden. This + * defaults false. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param visible true to show whitespace when wrapping text, false to hide + * it. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_TextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextWrapWhitespaceVisible(TTF_Text *text, bool visible); + +/** + * Return whether whitespace is shown when wrapping a text object. + * + * \param text the TTF_Text to query. + * \returns true if whitespace is shown when wrapping text, or false + * otherwise. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_SetTextWrapWhitespaceVisible + */ +extern SDL_DECLSPEC bool SDLCALL TTF_TextWrapWhitespaceVisible(TTF_Text *text); + +/** + * Set the UTF-8 text used by a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to use, may be NULL. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_SetTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Insert UTF-8 text into a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only insert + * at UTF-8 sequence boundaries. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_DeleteTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_InsertTextString(TTF_Text *text, int offset, const char *string, size_t length); + +/** + * Append UTF-8 text to a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param string the UTF-8 text to insert. + * \param length the length of the text, in bytes, or 0 for null terminated + * text. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_DeleteTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_AppendTextString(TTF_Text *text, const char *string, size_t length); + +/** + * Delete UTF-8 text from a text object. + * + * This function may cause the internal text representation to be rebuilt. + * + * \param text the TTF_Text to modify. + * \param offset the offset, in bytes, from the beginning of the string if >= + * 0, the offset from the end of the string if < 0. Note that + * this does not do UTF-8 validation, so you should only delete + * at UTF-8 sequence boundaries. + * \param length the length of text to delete, in bytes, or -1 for the + * remainder of the string. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_AppendTextString + * \sa TTF_InsertTextString + * \sa TTF_SetTextString + */ +extern SDL_DECLSPEC bool SDLCALL TTF_DeleteTextString(TTF_Text *text, int offset, int length); + +/** + * Get the size of a text object. + * + * The size of the text may change when the font or font style and size + * change. + * + * \param text the TTF_Text to query. + * \param w a pointer filled in with the width of the text, in pixels, may be + * NULL. + * \param h a pointer filled in with the height of the text, in pixels, may be + * NULL. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSize(TTF_Text *text, int *w, int *h); + +/** + * Flags for TTF_SubString + * + * \since This datatype is available since SDL_ttf 3.0.0. + * + * \sa TTF_SubString + */ +typedef Uint32 TTF_SubStringFlags; + +#define TTF_SUBSTRING_DIRECTION_MASK 0x000000FF /**< The mask for the flow direction for this substring */ +#define TTF_SUBSTRING_TEXT_START 0x00000100 /**< This substring contains the beginning of the text */ +#define TTF_SUBSTRING_LINE_START 0x00000200 /**< This substring contains the beginning of line `line_index` */ +#define TTF_SUBSTRING_LINE_END 0x00000400 /**< This substring contains the end of line `line_index` */ +#define TTF_SUBSTRING_TEXT_END 0x00000800 /**< This substring contains the end of the text */ + +/** + * The representation of a substring within text. + * + * \since This struct is available since SDL_ttf 3.0.0. + * + * \sa TTF_GetNextTextSubString + * \sa TTF_GetPreviousTextSubString + * \sa TTF_GetTextSubString + * \sa TTF_GetTextSubStringForLine + * \sa TTF_GetTextSubStringForPoint + * \sa TTF_GetTextSubStringsForRange + */ +typedef struct TTF_SubString +{ + TTF_SubStringFlags flags; /**< The flags for this substring */ + int offset; /**< The byte offset from the beginning of the text */ + int length; /**< The byte length starting at the offset */ + int line_index; /**< The index of the line that contains this substring */ + int cluster_index; /**< The internal cluster index, used for quickly iterating */ + SDL_Rect rect; /**< The rectangle, relative to the top left of the text, containing the substring */ +} TTF_SubString; + +/** + * Get the substring of a text object that surrounds a text offset. + * + * If `offset` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If + * `offset` is greater than or equal to the length of the text string, this + * will return a zero length substring at the end of the text with the + * TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubString(TTF_Text *text, int offset, TTF_SubString *substring); + +/** + * Get the substring of a text object that contains the given line. + * + * If `line` is less than 0, this will return a zero length substring at the + * beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If `line` + * is greater than or equal to `text->num_lines` this will return a zero + * length substring at the end of the text with the TTF_SUBSTRING_TEXT_END + * flag set. + * + * \param text the TTF_Text to query. + * \param line a zero-based line index, in the range [0 .. text->num_lines-1]. + * \param substring a pointer filled in with the substring containing the + * offset. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForLine(TTF_Text *text, int line, TTF_SubString *substring); + +/** + * Get the substrings of a text object that contain a range of text. + * + * \param text the TTF_Text to query. + * \param offset a byte offset into the text string. + * \param length the length of the range being queried, in bytes, or -1 for + * the remainder of the string. + * \param count a pointer filled in with the number of substrings returned, + * may be NULL. + * \returns a NULL terminated array of substring pointers or NULL on failure; + * call SDL_GetError() for more information. This is a single + * allocation that should be freed with SDL_free() when it is no + * longer needed. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC TTF_SubString ** SDLCALL TTF_GetTextSubStringsForRange(TTF_Text *text, int offset, int length, int *count); + +/** + * Get the portion of a text string that is closest to a point. + * + * This will return the closest substring of text to the given point. + * + * \param text the TTF_Text to query. + * \param x the x coordinate relative to the left side of the text, may be + * outside the bounds of the text area. + * \param y the y coordinate relative to the top side of the text, may be + * outside the bounds of the text area. + * \param substring a pointer filled in with the closest substring of text to + * the given point. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetTextSubStringForPoint(TTF_Text *text, int x, int y, TTF_SubString *substring); + +/** + * Get the previous substring in a text object + * + * If called at the start of the text, this will return a zero length + * substring with the TTF_SUBSTRING_TEXT_START flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetPreviousTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *previous); + +/** + * Get the next substring in a text object + * + * If called at the end of the text, this will return a zero length substring + * with the TTF_SUBSTRING_TEXT_END flag set. + * + * \param text the TTF_Text to query. + * \param substring the TTF_SubString to query. + * \param next a pointer filled in with the next substring. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_GetNextTextSubString(TTF_Text *text, const TTF_SubString *substring, TTF_SubString *next); + +/** + * Update the layout of a text object. + * + * This is automatically done when the layout is requested or the text is + * rendered, but you can call this if you need more control over the timing of + * when the layout and text engine representation are updated. + * + * \param text the TTF_Text to update. + * \returns true on success or false on failure; call SDL_GetError() for more + * information. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC bool SDLCALL TTF_UpdateText(TTF_Text *text); + +/** + * Destroy a text object created by a text engine. + * + * \param text the text to destroy. + * + * \threadsafety This function should be called on the thread that created the + * text. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_CreateText + */ +extern SDL_DECLSPEC void SDLCALL TTF_DestroyText(TTF_Text *text); + +/** + * Dispose of a previously-created font. + * + * Call this when done with a font. This function will free any resources + * associated with it. It is safe to call this function on NULL, for example + * on the result of a failed call to TTF_OpenFont(). + * + * The font is not valid after being passed to this function. String pointers + * from functions that return information on this font, such as + * TTF_GetFontFamilyName() and TTF_GetFontStyleName(), are no longer valid + * after this call, as well. + * + * \param font the font to dispose of. + * + * \threadsafety This function should not be called while any other thread is + * using the font. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_OpenFont + * \sa TTF_OpenFontIO + */ +extern SDL_DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font); + +/** + * Deinitialize SDL_ttf. + * + * You must call this when done with the library, to free internal resources. + * It is safe to call this when the library isn't initialized, as it will just + * return immediately. + * + * Once you have as many quit calls as you have had successful calls to + * TTF_Init, the library will actually deinitialize. + * + * Please note that this does not automatically close any fonts that are still + * open at the time of deinitialization, and it is possibly not safe to close + * them afterwards, as parts of the library will no longer be initialized to + * deal with it. A well-written program should call TTF_CloseFont() on any + * open fonts before calling this function! + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + */ +extern SDL_DECLSPEC void SDLCALL TTF_Quit(void); + +/** + * Check if SDL_ttf is initialized. + * + * This reports the number of times the library has been initialized by a call + * to TTF_Init(), without a paired deinitialization request from TTF_Quit(). + * + * In short: if it's greater than zero, the library is currently initialized + * and ready to work. If zero, it is not initialized. + * + * Despite the return value being a signed integer, this function should not + * return a negative number. + * + * \returns the current number of initialization calls, that need to + * eventually be paired with this many calls to TTF_Quit(). + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL_ttf 3.0.0. + * + * \sa TTF_Init + * \sa TTF_Quit + */ +extern SDL_DECLSPEC int SDLCALL TTF_WasInit(void); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include + +#endif /* SDL_TTF_H_ */ + diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/INSTALL.md b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/INSTALL.md new file mode 100644 index 0000000..e11b671 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/INSTALL.md @@ -0,0 +1,35 @@ + +# Using this package + +This package contains SDL_ttf built for Xcode. + +To use this package in Xcode, drag `SDL3_ttf.framework` into your project. + +# Documentation + +An API reference and additional documentation is available at: + +https://wiki.libsdl.org/SDL3_ttf + +# Discussions + +## Discord + +You can join the official Discord server at: + +https://discord.com/invite/BwpFGBWsv8 + +## Forums/mailing lists + +You can join SDL development discussions at: + +https://discourse.libsdl.org/ + +Once you sign up, you can use the forum through the website or as a mailing list from your email client. + +## Announcement list + +You can sign up for the low traffic announcement list at: + +https://www.libsdl.org/mailing-list.php + diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/Info.plist b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/Info.plist new file mode 100644 index 0000000..bd04991 Binary files /dev/null and b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/Info.plist differ diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/LICENSE.txt b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/LICENSE.txt new file mode 100644 index 0000000..52d0ed3 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/LICENSE.txt @@ -0,0 +1,17 @@ +Copyright (C) 1997-2025 Sam Lantinga + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/README.md b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/README.md new file mode 100644 index 0000000..3a6a1e9 --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/README.md @@ -0,0 +1,23 @@ + +SDL_ttf 3.0 + +This library is a wrapper around the FreeType and Harfbuzz libraries, allowing you to use TrueType fonts to render text in SDL applications. + +The latest version of this library is available from GitHub: +https://github.com/libsdl-org/SDL_ttf/releases + +Installation instructions and a quick introduction is available in +[INSTALL.md](INSTALL.md) + +This library is distributed under the terms of the zlib license, +available in [LICENSE.txt](LICENSE.txt). + +This library also uses the following libraries: +- FreeType, licensed under the [FTL](https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT) +- HarfBuzz, licensed under the [MIT license](https://github.com/harfbuzz/harfbuzz/blob/main/COPYING) +- PlutoSVG, licensed under the [MIT license](https://github.com/sammycage/plutosvg/blob/master/LICENSE) +- PlutoVG, licensed under the [MIT license](https://github.com/sammycage/plutovg/blob/master/LICENSE) + +Enjoy! + +Sam Lantinga (slouken@libsdl.org) diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/SDL3_ttf b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/SDL3_ttf new file mode 100755 index 0000000..db12819 Binary files /dev/null and b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/SDL3_ttf differ diff --git a/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/_CodeSignature/CodeResources b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/_CodeSignature/CodeResources new file mode 100644 index 0000000..baa8b5e --- /dev/null +++ b/release/frameworks/SDL3_ttf.xcframework/tvos-arm64_x86_64-simulator/SDL3_ttf.framework/_CodeSignature/CodeResources @@ -0,0 +1,179 @@ + + + + + files + + CMake/SDL3_ttfConfig.cmake + + V6UpWQTvr/puOrlm1sgAs6fktNA= + + CMake/SDL3_ttfConfigVersion.cmake + + WW2xmNHZyYr9y3/8uAylJuutcPw= + + Headers/SDL_textengine.h + + 7QAtKpC/pLIq6TK3F59Ax1hg3tc= + + Headers/SDL_ttf.h + + 90S4SFzJy1lUuMotaCRWpTbzRa4= + + INSTALL.md + + 3kA+9HE5dF7+nyypVt5YOfU+Uho= + + Info.plist + + +nBymgIjvQrMA5f3CqiBB03/KB0= + + LICENSE.txt + + dp6e8JHkl0CrYD+oe2IXZfWB/iw= + + README.md + + lm034L4zWKPElKb9O2dmehurfFQ= + + + files2 + + CMake/SDL3_ttfConfig.cmake + + hash2 + + VpwUT/D8TjpLXBguVImWqsMkqni9HXiIzx91C92Krqc= + + + CMake/SDL3_ttfConfigVersion.cmake + + hash2 + + tb1RnDTj72GQOzcXp6FPtiqW8tSD886UyUY09c1Ms/U= + + + Headers/SDL_textengine.h + + hash2 + + Uk27FTzsWoYySpKM1gkwCB/svSxscGViuMzca93gLP8= + + + Headers/SDL_ttf.h + + hash2 + + 6bsCCUp3Uc3tCp+0Xxw7Tt01+UV8bra5YN1dFjpRBL0= + + + INSTALL.md + + hash2 + + Jq9GEmdnFRmUTNnYYZZ+5mFqqrMelD86Gthhyi2kGJQ= + + + LICENSE.txt + + hash2 + + eCbsoKD35ZHzjdhE4geiAKrIGlmyDYoww6+MYoKvE+Y= + + + README.md + + hash2 + + 6aipppbEU7MEd3x9OHnKqAGyFXVYiSAL8X8lm271U00= + + + + rules + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^version.plist$ + + + rules2 + + .*\.dSYM($|/) + + weight + 11 + + ^(.*/)?\.DS_Store$ + + omit + + weight + 2000 + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^Info\.plist$ + + omit + + weight + 20 + + ^PkgInfo$ + + omit + + weight + 20 + + ^embedded\.provisionprofile$ + + weight + 20 + + ^version\.plist$ + + weight + 20 + + + + diff --git a/source/defines.h b/source/defines.h index 1ec1297..4618070 100644 --- a/source/defines.h +++ b/source/defines.h @@ -22,17 +22,17 @@ constexpr int WINDOW_DECORATION_HEIGHT = 30; // Altura estimada de decoraciones constexpr float GRAVITY_FORCE = 0.2f; // Fuerza de gravedad (píxeles/frame²) // Configuración de interfaz -constexpr Uint64 TEXT_DURATION = 2000; // Duración del texto informativo (ms) - OBSOLETO, usar NOTIFICATION_DURATION +constexpr Uint64 TEXT_DURATION = 2000; // Duración del texto informativo (ms) - OBSOLETO, usar NOTIFICATION_DURATION constexpr float THEME_TRANSITION_DURATION = 0.5f; // Duración de transiciones LERP entre temas (segundos) // Configuración de notificaciones (sistema Notifier) -constexpr int TEXT_ABSOLUTE_SIZE = 12; // Tamaño fuente base en píxeles físicos (múltiplo de 12px, tamaño nativo de la fuente) -constexpr Uint64 NOTIFICATION_DURATION = 2000; // Duración default de notificaciones (ms) -constexpr Uint64 NOTIFICATION_SLIDE_TIME = 300; // Duración animación entrada (ms) -constexpr Uint64 NOTIFICATION_FADE_TIME = 200; // Duración animación salida (ms) -constexpr float NOTIFICATION_BG_ALPHA = 0.7f; // Opacidad fondo semitransparente (0.0-1.0) -constexpr int NOTIFICATION_PADDING = 10; // Padding interno del fondo (píxeles físicos) -constexpr int NOTIFICATION_TOP_MARGIN = 20; // Margen superior desde borde pantalla (píxeles físicos) +constexpr int TEXT_ABSOLUTE_SIZE = 12; // Tamaño fuente base en píxeles físicos (múltiplo de 12px, tamaño nativo de la fuente) +constexpr Uint64 NOTIFICATION_DURATION = 2000; // Duración default de notificaciones (ms) +constexpr Uint64 NOTIFICATION_SLIDE_TIME = 300; // Duración animación entrada (ms) +constexpr Uint64 NOTIFICATION_FADE_TIME = 200; // Duración animación salida (ms) +constexpr float NOTIFICATION_BG_ALPHA = 0.7f; // Opacidad fondo semitransparente (0.0-1.0) +constexpr int NOTIFICATION_PADDING = 10; // Padding interno del fondo (píxeles físicos) +constexpr int NOTIFICATION_TOP_MARGIN = 20; // Margen superior desde borde pantalla (píxeles físicos) // Configuración de pérdida aleatoria en rebotes constexpr float BASE_BOUNCE_COEFFICIENT = 0.75f; // Coeficiente base IGUAL para todas las pelotas @@ -60,12 +60,12 @@ struct Color { // Estructura de tema de colores estático struct ThemeColors { - const char* name_en; // Nombre en inglés (para debug) - const char* name_es; // Nombre en español (para display) - int text_color_r, text_color_g, text_color_b; // Color del texto del tema - float bg_top_r, bg_top_g, bg_top_b; - float bg_bottom_r, bg_bottom_g, bg_bottom_b; - std::vector ball_colors; + const char* name_en; // Nombre en inglés (para debug) + const char* name_es; // Nombre en español (para display) + int text_color_r, text_color_g, text_color_b; // Color del texto del tema + float bg_top_r, bg_top_g, bg_top_b; + float bg_bottom_r, bg_bottom_g, bg_bottom_b; + std::vector ball_colors; }; // Estructura para keyframe de tema dinámico @@ -99,21 +99,21 @@ enum class GravityDirection { // Enum para temas de colores (seleccionables con teclado numérico y Shift+Numpad) // Todos los temas usan ahora sistema dinámico de keyframes enum class ColorTheme { - SUNSET = 0, // Naranjas, rojos, amarillos, rosas (estático: 1 keyframe) - OCEAN = 1, // Azules, turquesas, blancos (estático: 1 keyframe) - NEON = 2, // Cian, magenta, verde lima, amarillo vibrante (estático: 1 keyframe) - FOREST = 3, // Verdes, marrones, amarillos otoño (estático: 1 keyframe) - RGB = 4, // RGB puros y subdivisiones matemáticas - fondo blanco (estático: 1 keyframe) - MONOCHROME = 5, // Fondo negro degradado, sprites blancos monocromáticos (estático: 1 keyframe) - LAVENDER = 6, // Degradado violeta-azul, pelotas amarillo dorado (estático: 1 keyframe) - CRIMSON = 7, // Fondo negro-rojo, pelotas rojas uniformes (estático: 1 keyframe) - EMERALD = 8, // Fondo negro-verde, pelotas verdes uniformes (estático: 1 keyframe) - SUNRISE = 9, // Amanecer: Noche → Alba → Día (animado: 4 keyframes, 12s ciclo) - OCEAN_WAVES = 10, // Olas oceánicas: Azul oscuro ↔ Turquesa (animado: 3 keyframes, 8s ciclo) - NEON_PULSE = 11, // Pulso neón: Negro ↔ Neón vibrante (animado: 3 keyframes, 3s ping-pong) - FIRE = 12, // Fuego vivo: Brasas → Llamas → Inferno (animado: 4 keyframes, 10s ciclo) - AURORA = 13, // Aurora boreal: Verde → Violeta → Cian (animado: 4 keyframes, 14s ciclo) - VOLCANIC = 14 // Erupción volcánica: Ceniza → Erupción → Lava (animado: 4 keyframes, 12s ciclo) + SUNSET = 0, // Naranjas, rojos, amarillos, rosas (estático: 1 keyframe) + OCEAN = 1, // Azules, turquesas, blancos (estático: 1 keyframe) + NEON = 2, // Cian, magenta, verde lima, amarillo vibrante (estático: 1 keyframe) + FOREST = 3, // Verdes, marrones, amarillos otoño (estático: 1 keyframe) + RGB = 4, // RGB puros y subdivisiones matemáticas - fondo blanco (estático: 1 keyframe) + MONOCHROME = 5, // Fondo negro degradado, sprites blancos monocromáticos (estático: 1 keyframe) + LAVENDER = 6, // Degradado violeta-azul, pelotas amarillo dorado (estático: 1 keyframe) + CRIMSON = 7, // Fondo negro-rojo, pelotas rojas uniformes (estático: 1 keyframe) + EMERALD = 8, // Fondo negro-verde, pelotas verdes uniformes (estático: 1 keyframe) + SUNRISE = 9, // Amanecer: Noche → Alba → Día (animado: 4 keyframes, 12s ciclo) + OCEAN_WAVES = 10, // Olas oceánicas: Azul oscuro ↔ Turquesa (animado: 3 keyframes, 8s ciclo) + NEON_PULSE = 11, // Pulso neón: Negro ↔ Neón vibrante (animado: 3 keyframes, 3s ping-pong) + FIRE = 12, // Fuego vivo: Brasas → Llamas → Inferno (animado: 4 keyframes, 10s ciclo) + AURORA = 13, // Aurora boreal: Verde → Violeta → Cian (animado: 4 keyframes, 14s ciclo) + VOLCANIC = 14 // Erupción volcánica: Ceniza → Erupción → Lava (animado: 4 keyframes, 12s ciclo) }; // Enum para tipo de figura 3D @@ -282,19 +282,19 @@ constexpr int LOGO_JUMP_PROBABILITY_FROM_DEMO = 5; // 5% probabilidad en D constexpr int LOGO_JUMP_PROBABILITY_FROM_DEMO_LITE = 3; // 3% probabilidad en DEMO LITE (aún más raro) // Sistema de espera de flips en LOGO MODE (camino alternativo de decisión) -constexpr int LOGO_FLIP_WAIT_MIN = 1; // Mínimo de flips a esperar antes de cambiar a PHYSICS -constexpr int LOGO_FLIP_WAIT_MAX = 3; // Máximo de flips a esperar -constexpr float LOGO_FLIP_TRIGGER_MIN = 0.20f; // 20% mínimo de progreso de flip para trigger -constexpr float LOGO_FLIP_TRIGGER_MAX = 0.80f; // 80% máximo de progreso de flip para trigger -constexpr int LOGO_FLIP_WAIT_PROBABILITY = 50; // 50% probabilidad de elegir el camino "esperar flip" +constexpr int LOGO_FLIP_WAIT_MIN = 1; // Mínimo de flips a esperar antes de cambiar a PHYSICS +constexpr int LOGO_FLIP_WAIT_MAX = 3; // Máximo de flips a esperar +constexpr float LOGO_FLIP_TRIGGER_MIN = 0.20f; // 20% mínimo de progreso de flip para trigger +constexpr float LOGO_FLIP_TRIGGER_MAX = 0.80f; // 80% máximo de progreso de flip para trigger +constexpr int LOGO_FLIP_WAIT_PROBABILITY = 50; // 50% probabilidad de elegir el camino "esperar flip" // Configuración de AppLogo (logo periódico en pantalla) -constexpr float APPLOGO_DISPLAY_INTERVAL = 120.0f; // Intervalo entre apariciones del logo (segundos) -constexpr float APPLOGO_DISPLAY_DURATION = 30.0f; // Duración de visibilidad del logo (segundos) -constexpr float APPLOGO_ANIMATION_DURATION = 0.5f; // Duración de animación entrada/salida (segundos) -constexpr float APPLOGO_HEIGHT_PERCENT = 0.4f; // Altura del logo = 40% de la altura de pantalla -constexpr float APPLOGO_PADDING_PERCENT = 0.05f; // Padding desde esquina inferior-derecha = 10% -constexpr float APPLOGO_LOGO2_DELAY = 0.25f; // Retraso de Logo 2 respecto a Logo 1 (segundos) +constexpr float APPLOGO_DISPLAY_INTERVAL = 90.0f; // Intervalo entre apariciones del logo (segundos) +constexpr float APPLOGO_DISPLAY_DURATION = 30.0f; // Duración de visibilidad del logo (segundos) +constexpr float APPLOGO_ANIMATION_DURATION = 0.5f; // Duración de animación entrada/salida (segundos) +constexpr float APPLOGO_HEIGHT_PERCENT = 0.4f; // Altura del logo = 40% de la altura de pantalla +constexpr float APPLOGO_PADDING_PERCENT = 0.05f; // Padding desde esquina inferior-derecha = 10% +constexpr float APPLOGO_LOGO2_DELAY = 0.25f; // Retraso de Logo 2 respecto a Logo 1 (segundos) // Configuración de Modo BOIDS (comportamiento de enjambre) // TIME-BASED CONVERSION (frame-based → time-based): @@ -303,21 +303,21 @@ constexpr float APPLOGO_LOGO2_DELAY = 0.25f; // Retraso de Logo 2 respe // - Aceleraciones puras (SEPARATION, COHESION): ×60² = ×3600 (px/frame² → px/s²) // - Steering proporcional (ALIGNMENT): ×60 (proporcional a velocidad) // - Límite velocidad (MAX_FORCE): ×60 (px/frame → px/s) -constexpr float BOID_SEPARATION_RADIUS = 30.0f; // Radio para evitar colisiones (píxeles) -constexpr float BOID_ALIGNMENT_RADIUS = 50.0f; // Radio para alinear velocidad con vecinos -constexpr float BOID_COHESION_RADIUS = 80.0f; // Radio para moverse hacia centro del grupo -constexpr float BOID_SEPARATION_WEIGHT = 5400.0f; // Aceleración de separación (px/s²) [era 1.5 × 3600] -constexpr float BOID_ALIGNMENT_WEIGHT = 60.0f; // Steering de alineación (proporcional) [era 1.0 × 60] -constexpr float BOID_COHESION_WEIGHT = 3.6f; // Aceleración de cohesión (px/s²) [era 0.001 × 3600] -constexpr float BOID_MAX_SPEED = 150.0f; // Velocidad máxima (px/s) [era 2.5 × 60] -constexpr float BOID_MAX_FORCE = 3.0f; // Fuerza máxima de steering (px/s) [era 0.05 × 60] -constexpr float BOID_MIN_SPEED = 18.0f; // Velocidad mínima (px/s) [era 0.3 × 60] -constexpr float BOID_BOUNDARY_MARGIN = 50.0f; // Distancia a borde para activar repulsión (píxeles) -constexpr float BOID_BOUNDARY_WEIGHT = 7200.0f; // Aceleración de repulsión de bordes (px/s²) [más fuerte que separation] +constexpr float BOID_SEPARATION_RADIUS = 30.0f; // Radio para evitar colisiones (píxeles) +constexpr float BOID_ALIGNMENT_RADIUS = 50.0f; // Radio para alinear velocidad con vecinos +constexpr float BOID_COHESION_RADIUS = 80.0f; // Radio para moverse hacia centro del grupo +constexpr float BOID_SEPARATION_WEIGHT = 5400.0f; // Aceleración de separación (px/s²) [era 1.5 × 3600] +constexpr float BOID_ALIGNMENT_WEIGHT = 60.0f; // Steering de alineación (proporcional) [era 1.0 × 60] +constexpr float BOID_COHESION_WEIGHT = 3.6f; // Aceleración de cohesión (px/s²) [era 0.001 × 3600] +constexpr float BOID_MAX_SPEED = 150.0f; // Velocidad máxima (px/s) [era 2.5 × 60] +constexpr float BOID_MAX_FORCE = 3.0f; // Fuerza máxima de steering (px/s) [era 0.05 × 60] +constexpr float BOID_MIN_SPEED = 18.0f; // Velocidad mínima (px/s) [era 0.3 × 60] +constexpr float BOID_BOUNDARY_MARGIN = 50.0f; // Distancia a borde para activar repulsión (píxeles) +constexpr float BOID_BOUNDARY_WEIGHT = 7200.0f; // Aceleración de repulsión de bordes (px/s²) [más fuerte que separation] // FASE 2: Spatial Hash Grid para optimización O(n²) → O(n) constexpr float BOID_GRID_CELL_SIZE = 100.0f; // Tamaño de celda del grid (píxeles) - // Debe ser ≥ BOID_COHESION_RADIUS para funcionar correctamente + // Debe ser ≥ BOID_COHESION_RADIUS para funcionar correctamente constexpr float PI = 3.14159265358979323846f; // Constante PI