docs: Actualizar estado TTF → zcatttf como solución

- CLAUDE.md: Bug TTF pausado, solución es nueva librería zcatttf
- TTF_DEBUG_SESSION: Documentar intentos adicionales y decisión final
- Proyectos relacionados: añadir zcatttf, zsimifactu, zcatp2p
- ttf.zig marcado como CONGELADO hasta integrar zcatttf

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
reugenio 2025-12-16 22:19:36 +01:00
parent 0cdd44b8a0
commit 7a67a3b1ea
2 changed files with 98 additions and 43 deletions

View file

@ -129,63 +129,82 @@ GPU/CPU interpola → bordes suaves sin multisampling
--- ---
## ⚠️ BUG CRÍTICO: TTF Rendering Corrupto (NO RESUELTO) ## ⚠️ BUG TTF: Rendering Corrupto → SOLUCIÓN: zcatttf
> **Prioridad**: ALTA > **Estado**: PAUSADO - Nueva librería zcatttf en desarrollo (otra conversación)
> **Documentación completa**: `/mnt/cello2/arno/re/recode/teamdocs/agenda/hitos/2025-12-16_ttf_debug_session.md` > **Documentación debug**: `docs/research/TTF_DEBUG_SESSION_2025-12-17.md`
> **Fecha**: 2025-12-16 > **Fecha**: 2025-12-16/17
### El Problema ### El Problema
El texto TTF se renderiza como **garabatos ilegibles** en zsimifactu. TODO el texto está corrupto, incluyendo ASCII básico (A-Z, a-z, 0-9), no solo caracteres acentuados. El texto TTF se renderiza como **garabatos ilegibles** en zsimifactu. TODO el texto está corrupto, incluyendo ASCII básico (A-Z, a-z, 0-9).
### Lo que se intentó (NO funcionó) ### Lo que se intentó (Sesiones 16-17 Dic)
| Intento | Hipótesis | Resultado | | Intento | Hipótesis | Resultado |
|---------|-----------|-----------| |---------|-----------|-----------|
| DroidSans | AdwaitaSans era fuente variable | ❌ Sigue corrupto | | DroidSans | AdwaitaSans era fuente variable | ❌ Sigue corrupto |
| Y-flip | Coordenadas TTF invertidas | ❌ Sigue corrupto | | Y-flip rasterización | Coordenadas TTF invertidas | ❌ Mejoró colores, no texto |
| UTF-8 decode | drawText iteraba bytes | ❌ Sigue corrupto | | UTF-8 decode | drawText iteraba bytes | ❌ No era el problema |
| Fix ABGR (líneas 951-955) | Framebuffer usa ABGR, no RGBA | ⚠️ Colores OK, texto aún mal |
| bearing_x = 0 | Offset incorrecto | ⚠️ Mejoró, pero "eco" |
| bearing_y = y_max | Baseline incorrecto | ⚠️ NO VERIFICADO |
### Hipótesis actuales (NO verificadas) ### Diagnóstico cmap_debug
1. **Tabla cmap mal parseada para DroidSans** - Los tests de glyph indices ('A'=36) fueron con AdwaitaSans Se creó `src/render/cmap_debug.zig` para diagnosticar. **Resultado**:
2. **Formato cmap diferente** - DroidSans podría usar formato no soportado - ✅ DroidSans se parsea correctamente
3. **Renderer no usa TTF** - Posible fallback o fuente no cargada - ✅ cmap format 4 funciona ('A'→36, 'a'→68)
4. **Pipeline corrupto** - Algo entre parseo y dibujo falla - ✅ ASCII Art de 'A' es legible en test aislado
- ❌ La integración con zcatgui sigue corrupta
### ⚠️ INSTRUCCIONES PARA PRÓXIMA SESIÓN **Conclusión**: El código base TTF funciona. El bug está en la integración.
**IMPORTANTE: NO hacer cambios sin antes verificar:** ### Solución: Nueva librería zcatttf
1. Que DroidSans se carga realmente (`font_data.len` ≈ 187KB) Decisión consensuada: Reimplementar TTF desde cero en librería independiente.
2. Glyph indices de DroidSans: `getGlyphIndex('A')`, `getGlyphIndex('a')`
3. Formato cmap que usa DroidSans (format 4? 12? otro?)
4. Probar fuente del sistema vs embebida
5. Test aislado: renderizar 'A' a ASCII art
### Archivos clave | Campo | Valor |
- `src/render/ttf.zig` - Parser TTF + rasterización (~1000 líneas) |-------|-------|
| **Proyecto** | `/mnt/cello2/arno/re/recode/zig/zcatttf/` |
| **Algoritmo** | Áreas trapezoidales (como stb_truetype) |
| **Estado** | EN DESARROLLO (otra conversación Claude) |
| **Integración** | zcatgui usará zcatttf como dependencia |
**Documentación zcatttf**:
- `teamdocs/agenda/hitos/2025-12-16_zcatttf_plan_implementacion.md`
- `teamdocs/agenda/hitos/2025-12-16_estudio_dvui_stb_truetype.md`
### Mientras tanto
- zsimifactu usa **bitmap fonts** (funciona)
- El código TTF en `src/render/ttf.zig` está **congelado** hasta integrar zcatttf
### Archivos clave (NO MODIFICAR)
- `src/render/ttf.zig` - Parser TTF + rasterización (CONGELADO)
- `src/render/embedded_font.zig` - Fuente embebida - `src/render/embedded_font.zig` - Fuente embebida
- `src/render/fonts/DroidSans.ttf` - Fuente actual (187KB) - `src/render/cmap_debug.zig` - Herramienta diagnóstico
--- ---
## Fuentes TTF: Implementación Técnica ## Fuentes TTF: Estado Técnico
### Estado actual (v0.16.2) ### Estado actual (v0.16.2) - CONGELADO
- ✅ Parsing TTF (glyf, cmap format 4 y 12) - ✅ Parsing TTF (glyf, cmap format 4 y 12)
- ✅ Rasterización bezier cuadráticas - ✅ Rasterización bezier cuadráticas
- ✅ Antialiasing 2x supersampling - ✅ Antialiasing 2x supersampling
- ✅ Fuente embebida (DroidSans) - ✅ Fuente embebida (DroidSans)
- ❌ **BUG: Rendering corrupto** (ver arriba) - ❌ **BUG: Rendering corrupto en integración** (ver arriba)
- 🔄 **ESPERANDO**: Librería zcatttf
### Uso (cuando funcione) ### Uso futuro (cuando zcatttf esté listo)
```zig ```zig
var ttf = try TtfFont.initEmbedded(allocator); // zcatttf reemplazará el código actual
defer ttf.deinit(); const zcatttf = @import("zcatttf");
ttf.setSize(14); var font = try zcatttf.Font.load(allocator, font_data);
renderer.setTtfFont(&ttf); defer font.deinit();
font.setSize(14);
const bitmap = try font.rasterizeGlyph(font.getGlyphIndex('A'));
``` ```
--- ---
@ -917,8 +936,11 @@ state.focused = has_focus;
| Proyecto | Ruta | Descripción | | Proyecto | Ruta | Descripción |
|----------|------|-------------| |----------|------|-------------|
| **zcatttf** | `/mnt/cello2/arno/re/recode/zig/zcatttf/` | ⭐ Librería TTF (reemplazará ttf.zig) - EN DESARROLLO |
| **zsimifactu** | `/mnt/cello2/arno/re/recode/zig/zsimifactu/` | App de facturación Zig (consumidor principal) |
| **zcatui** | `/mnt/cello2/arno/re/recode/zig/zcatui/` | TUI library (proyecto hermano) | | **zcatui** | `/mnt/cello2/arno/re/recode/zig/zcatui/` | TUI library (proyecto hermano) |
| **simifactu** | `/mnt/cello2/arno/re/recode/go/simifactu/` | App de referencia (Fyne) | | **zcatp2p** | `/mnt/cello2/arno/re/recode/zig/zcatp2p/` | Librería P2P (v1.0.0 completa) |
| **simifactu** | `/mnt/cello2/arno/re/recode/go/simifactu/` | App de referencia (Fyne/Go) |
--- ---

View file

@ -1,8 +1,9 @@
# Sesión de Debugging TTF - 17 Diciembre 2025 # Sesión de Debugging TTF - 17 Diciembre 2025
> **Estado**: EN PROGRESO > **Estado**: PAUSADO → Nueva librería zcatttf en desarrollo
> **Problema**: Texto TTF corrupto (garabatos + colores raros) en zsimifactu > **Problema**: Texto TTF corrupto (garabatos + colores raros) en zsimifactu
> **Proyectos afectados**: zcatgui, zsimifactu > **Proyectos afectados**: zcatgui, zsimifactu
> **Resolución**: Reimplementar TTF desde cero en zcatttf (otra conversación)
--- ---
@ -206,25 +207,57 @@ El único bug identificado es el **formato ABGR** que ya fue corregido.
--- ---
## 6. PRÓXIMOS PASOS ## 6. INTENTOS ADICIONALES (Sesión 17 Dic tarde)
1. [x] Aplicar fix Bug 1 (formato ABGR) - **HECHO** Después del diagnóstico, se probaron más fixes:
2. [x] Ejecutar tests zcatgui - **PASAN**
3. [x] Ejecutar diagnóstico cmap - **CÓDIGO BASE OK** | Fix | Archivo | Cambio | Resultado |
4. [ ] **PROBAR zsimifactu** con el fix aplicado |-----|---------|--------|-----------|
5. [ ] Si sigue fallando, investigar diferencias en la integración | Y-flip bitmap | ttf.zig:142 | `data[(height-1-py)*width+px]` | ⚠️ Orientación OK, pero "eco" |
| bearing_x = 0 | ttf.zig:150 | Normalizar a (0,0) | ⚠️ Mejoró, sigue corrupto |
| bearing_y = y_max | ttf.zig:151 | Distancia al baseline | ❓ NO VERIFICADO |
**Problema persistente**: Cada fix mejoraba algo pero introducía nuevos artefactos.
El usuario detuvo los intentos por frustración con el ciclo de prueba-error.
--- ---
## 7. ARCHIVOS MODIFICADOS ## 7. DECISIÓN FINAL: Nueva librería zcatttf
**Consenso alcanzado**: En lugar de seguir parcheando código que no entendemos completamente,
reimplementar TTF desde cero usando el algoritmo de áreas trapezoidales (como stb_truetype).
### Justificación
1. El código base funciona en tests aislados pero falla en integración
2. El algoritmo actual (supersampling) tiene bugs difíciles de rastrear
3. stb_truetype usa un algoritmo más eficiente y mejor documentado
4. Una librería independiente es más testeable
### Nueva librería
- **Proyecto**: `/mnt/cello2/arno/re/recode/zig/zcatttf/`
- **Algoritmo**: Áreas trapezoidales (no supersampling)
- **Estado**: EN DESARROLLO (otra conversación Claude)
- **Plan**: `teamdocs/agenda/hitos/2025-12-16_zcatttf_plan_implementacion.md`
---
## 8. ARCHIVOS MODIFICADOS
| Archivo | Cambio | | Archivo | Cambio |
|---------|--------| |---------|--------|
| `src/render/ttf.zig` | Fix formato ABGR en líneas 951-955 | | `src/render/ttf.zig` | Fix ABGR + Y-flip + bearings (CONGELADO) |
| `src/render/cmap_debug.zig` | Herramienta de diagnóstico actualizada | | `src/render/cmap_debug.zig` | Herramienta de diagnóstico |
| `build.zig` | Añadido target `cmap-debug` | | `build.zig` | Añadido target `cmap-debug` |
--- ---
## 9. ESTADO ACTUAL
- **ttf.zig**: CONGELADO - No modificar hasta integrar zcatttf
- **zsimifactu**: Usa bitmap fonts (funciona)
- **zcatttf**: En desarrollo por otra conversación
---
*Documento creado: 2025-12-17* *Documento creado: 2025-12-17*
*Última actualización: 2025-12-17 - Fix ABGR aplicado, diagnóstico completo* *Última actualización: 2025-12-17 - Decisión: Nueva librería zcatttf*