diff --git a/CLAUDE.md b/CLAUDE.md index f019ed9..b1b952b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 -> **Documentación completa**: `/mnt/cello2/arno/re/recode/teamdocs/agenda/hitos/2025-12-16_ttf_debug_session.md` -> **Fecha**: 2025-12-16 +> **Estado**: PAUSADO - Nueva librería zcatttf en desarrollo (otra conversación) +> **Documentación debug**: `docs/research/TTF_DEBUG_SESSION_2025-12-17.md` +> **Fecha**: 2025-12-16/17 ### 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 | |---------|-----------|-----------| | DroidSans | AdwaitaSans era fuente variable | ❌ Sigue corrupto | -| Y-flip | Coordenadas TTF invertidas | ❌ Sigue corrupto | -| UTF-8 decode | drawText iteraba bytes | ❌ Sigue corrupto | +| Y-flip rasterización | Coordenadas TTF invertidas | ❌ Mejoró colores, no texto | +| 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 -2. **Formato cmap diferente** - DroidSans podría usar formato no soportado -3. **Renderer no usa TTF** - Posible fallback o fuente no cargada -4. **Pipeline corrupto** - Algo entre parseo y dibujo falla +Se creó `src/render/cmap_debug.zig` para diagnosticar. **Resultado**: +- ✅ DroidSans se parsea correctamente +- ✅ cmap format 4 funciona ('A'→36, 'a'→68) +- ✅ 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) -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 +Decisión consensuada: Reimplementar TTF desde cero en librería independiente. -### Archivos clave -- `src/render/ttf.zig` - Parser TTF + rasterización (~1000 líneas) +| Campo | Valor | +|-------|-------| +| **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/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) - ✅ Rasterización bezier cuadráticas - ✅ Antialiasing 2x supersampling - ✅ 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 -var ttf = try TtfFont.initEmbedded(allocator); -defer ttf.deinit(); -ttf.setSize(14); -renderer.setTtfFont(&ttf); +// zcatttf reemplazará el código actual +const zcatttf = @import("zcatttf"); +var font = try zcatttf.Font.load(allocator, font_data); +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 | |----------|------|-------------| +| **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) | -| **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) | --- diff --git a/docs/research/TTF_DEBUG_SESSION_2025-12-17.md b/docs/research/TTF_DEBUG_SESSION_2025-12-17.md index 3fc39ef..7b38aae 100644 --- a/docs/research/TTF_DEBUG_SESSION_2025-12-17.md +++ b/docs/research/TTF_DEBUG_SESSION_2025-12-17.md @@ -1,8 +1,9 @@ # 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 > **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** -2. [x] Ejecutar tests zcatgui - **PASAN** -3. [x] Ejecutar diagnóstico cmap - **CÓDIGO BASE OK** -4. [ ] **PROBAR zsimifactu** con el fix aplicado -5. [ ] Si sigue fallando, investigar diferencias en la integración +Después del diagnóstico, se probaron más fixes: + +| Fix | Archivo | Cambio | Resultado | +|-----|---------|--------|-----------| +| 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 | |---------|--------| -| `src/render/ttf.zig` | Fix formato ABGR en líneas 951-955 | -| `src/render/cmap_debug.zig` | Herramienta de diagnóstico actualizada | +| `src/render/ttf.zig` | Fix ABGR + Y-flip + bearings (CONGELADO) | +| `src/render/cmap_debug.zig` | Herramienta de diagnóstico | | `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* -*Última actualización: 2025-12-17 - Fix ABGR aplicado, diagnóstico completo* +*Última actualización: 2025-12-17 - Decisión: Nueva librería zcatttf*