Saltar al contingut principal
Recepta número 60

Receptari · Capítol 2 · Text i tipografia

Cartilla de lectura amb síl·labes en xips

Una unitat de cartilla dedicada a la ema, amb cada síl·laba en un xip del color de la seva vocal i sis paraules en una taula, cadascuna sota la seva aquarel·la.

En aquesta pàgina
  • Mostra en castellà: encara no hi ha edició en català
  • Format 210 × 260 mm
  • 1 columna
  • Andika 11/15
  • DynaPuff
  • Playpen Sans
  • 3 pàgines
  • Nivell
  • Postext 1.57.1
  • Compost en 60 ms
  • 180 línies de codi

En poques paraules

Tres pàgines d'una cartilla per aprendre a llegir, dedicades a la lletra M. Cada síl·laba va en una etiqueta del color de la seva vocal i cada paraula de la quadrícula porta el seu dibuix.

Què compondràs

La unitat 7 de Letra a letra, una cartilla de lectura inventada: tres pàgines dedicades a la ema. L'obertura compon una Mm de DynaPuff a 190 pt sobre una franja crema, al costat de dues coses amb un nom que comença per ema en castellà, una papallona (mariposa) i una poma (manzana). Les síl·labes de la unitat van en xips del color de la seva vocal: vermell la a, taronja la e, turquesa la i, blau la o i morat la u. Les que porten ema van emplenades i les altres, només amb el contorn, de manera que el nen veu quina meitat de mesa és d'aquesta unitat. La pàgina 38 reuneix sis paraules amb la seva aquarel·la en una taula de cantonades arrodonides i tres pautes per repassar. Les aquarel·les es van generar amb models de difusió; la franja, les icones i les pautes estan dibuixades en codi. La 39 porta quatre frases a 24 pt, un requadre de síl·labes per pintar i una nota per a la família.

L'edició anglesa no és una traducció, sinó una altra unitat: la 12 de Letter by Letter, dedicada a la mateixa lletra. El castellà s'ensenya a llegir per síl·labes obertes (ma, me, mi, mo, mu), que en anglès no són paraules, i les cartilles angleses treballen so a so. Per això la unitat anglesa parteix paraules curtes en els seus sons, {m·a·p}, i les agrupa en famílies que rimen (-at, -an, -ug, -op). Totes dues unitats surten del mateix codi: els mateixos estils de xip, la mateixa funció syllables(), la mateixa taula, les mateixes pautes i els mateixos requadres.

Aquesta recepta respon a

  • Com faig xips en línia: tecles, etiquetes, bancs de paraules per a exercicis?
  • Com poso imatges o icones dins de les cel·les d'una taula?
  • Com afegeixo espai vertical entre dos blocs, si les línies en blanc no fan res?
  • Com faig una fitxa d'exercicis: línies per omplir, caixes de resposta, bancs de paraules, llistes de comprovació?

La resposta curta

script.js · línies 27–48al codi complet
// A word's syllables are chips with nothing between them, so their boxes touch and the white
// border draws the seam. Across a word space a chip keeps at least `gap`: 0.5 em sets the
// words of a 24 pt row 4.2 mm apart, where the space alone leaves 2.3 mm. Inside a sentence
// the '-frase' twins keep no gap, so the word space alone parts a chip from the word before.
// A 24 pt chip, padding and border included, is 10.4 mm tall (gotcha: chip-overlap).
const syllable = { fontFamily: TEXT, bold: true, borderWidth: pt(1), borderColor: col('paper'),
  paddingX: em(0.26), paddingY: em(0.05), gap: em(0.5) };
const chipStyles = [
  ...'aeiou'.split('').flatMap((v) => [ // one pair per vowel
    { ...syllable, id: v, background: col(v), color: col('paper') }, // a syllable with m
    { ...syllable, id: `${v}-borde`, background: col('paper'), color: col(v), borderColor: col(v) },
  ]).flatMap((style) => [style, { ...style, id: `${style.id}-frase`, gap: em(0) }]),
  { ...syllable, id: 'pinta', bold: false, background: col('paper'), color: col('ink'),
    borderColor: col('ink'), borderWidth: pt(0.8) }, // an outline for the child to colour in
];
const vowel = (s) => s.normalize('NFD').toLowerCase().match(/[aeiou]/)[0]; // 'mú' → 'u'
const chipOf = (s, v, end) => `:chip[${s}]{style="${v}${/m/i.test(s) ? '' : '-borde'}${end}"}`;
// {mi·mo·sa} → :chip[mi]{style="i"}:chip[mo]{style="o"}:chip[sa]{style="a-borde"}, and a word
// written after another word, as in 'me {mi·ma}.', takes the '-frase' twins. A piece with no
// vowel, the m and the p of the English {m·a·p}, takes the vowel of its word.
const syllables = (text) => text.replace(/(\p{L} )?\{([\p{L}·]+)\}/gu, (_, before = '', word) =>
  before + word.split('·').map((s) => chipOf(s, vowel(s + word), before && '-frase')).join(''));

Ingredients

Tipografia
Andika, DynaPuff, Playpen Sans (SIL OFL 1.1)
Recursos
  • man-640.jpg
  • mano-640.jpg
  • manzana-480.jpg
  • mapa-640.jpg
  • mariposa-660.jpg
  • mat-640.jpg
  • mesa-640.jpg
  • mimosa-640.jpg
  • mono-640.jpg
  • moon-480.jpg
  • mop-640.jpg
  • mud-640.jpg
  • mug-640.jpg
  • muneca-640.jpg
  • A watercolour of the butterfly on the opener (Generated With Diffusion Models, original)
  • A watercolour of the apple on the opener (Generated With Diffusion Models, original)
  • A watercolour of the hand in the picture grid (Generated With Diffusion Models, original)
  • A watercolour of the map in the picture grid of both units (Generated With Diffusion Models, original)
  • A watercolour of the table in the picture grid (Generated With Diffusion Models, original)
  • A watercolour of the mimosa sprig in the picture grid (Generated With Diffusion Models, original)
  • A watercolour of the monkey: in the picture grid of the Spanish unit and on the opener of the English one (Generated With Diffusion Models, original)
  • A watercolour of the doll in the picture grid (Generated With Diffusion Models, original)
  • A watercolour of the moon on the opener of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the mat in the picture grid of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the man in the picture grid of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the mug in the picture grid of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the mop in the picture grid of the English unit (Generated With Diffusion Models, original)
  • A watercolour of the mud in the picture grid of the English unit (Generated With Diffusion Models, original)
  • The cream band, the activity icons and the tracing rows, drawn in code in the page’s palette (Ignacio Ferro, MIT)

Elaboració

#1 · Un estil de xip per vocal i una funció que escriu els xips

La resposta curta treu els 21 estils de xip d'un mateix objecte, syllable. N'hi ha un d'emplenat per vocal per a les síl·labes amb ema, un altre amb contorn per vocal per a les altres, un bessó -frase de cadascun d'aquests deu i pinta, el contorn en tinta que el nen pinta. La funció syllables() converteix {mi·mo·sa} en tres :chip[…] sense res entre ells, de manera que les síl·labes d'una paraula es toquen i la vora blanca marca la junta. Cada xip pren el color de la seva vocal, i una peça sense vocal, com la m i la p del {m·a·p} de la unitat anglesa, pren la de la seva paraula. On hi ha un espai entre paraules, el xip guarda com a mínim el seu gap: amb 0,5 em, les paraules d'una fila de 24 pt queden a 4,2 mm, i l'espai tot sol en deixaria 2,3 mm. Dins d'una frase, aquest gap gairebé duplicaria l'espai davant de la paraula nova; per això, quan la paraula va darrere d'una altra, porta els bessons -frase, amb gap 0, i l'espai es queda en 2,3 mm.

#2 · Un interlineat que deixa lloc als xips

script.js · línies 144–154al codi complet
  // A 24 pt chip is 10.4 mm tall: at 30 pt (10.6 mm) leading the chips of two sentences would
  // stand 0.1 mm apart, so every line the child reads has 45 pt, and the syllables 60 pt.
  paragraphStyles: [
    { id: 'consigna', fontFamily: LABEL, fontSize: pt(10), lineHeight: pt(GRID),
      color: col('muted') }, // the instruction under each activity
    { id: 'fila', fontSize: pt(34), lineHeight: pt(4 * GRID), textAlign: 'center' },
    { id: 'palabras', fontSize: pt(24), lineHeight: pt(3 * GRID), textAlign: 'center' },
    { id: 'lectura', fontSize: pt(24), lineHeight: pt(3 * GRID) },
    { id: 'colofon', fontSize: pt(7.5), lineHeight: pt(10), // Andika: Playpen has no italic
      color: col('muted'), marginTop: pt(GRID) },
  ],

El farciment vertical i la vora d'un xip es pinten fora de la seva línia i no sumen interlineat, així que un xip més alt que l'interlineat xoca amb els xips de la línia de sota. Un xip de síl·laba a 24 pt fa 10,4 mm d'alçada; amb 30 pt d'interlineat (10,6 mm), els xips de dues frases quedarien a 0,1 mm. Per això les línies que llegeix el nen porten 45 pt i les files de síl·labes 60 pt, tres i quatre línies de la retícula de base de 15 pt en què van les consignes.

#3 · Una aquarel·la a cada cel·la

script.js · línies 96–109al codi complet
const PICTURE_WORDS = t({ en: ['m·a·p', 'm·a·t', 'm·a·n', 'm·u·g', 'm·o·p', 'm·u·d'],
  es: ['ma·no', 'ma·pa', 'me·sa', 'mi·mo·sa', 'mo·no', 'mu·ñe·ca'] });
const tableStyles = [{ id: 'dibujos', borderRadius: mm(5), // the frame and its fills, rounded
  headerBackgroundEnabled: false, // a header row added later would print grey (#f0f0f0)
  bodyBackgroundEnabled: true, bodyBackground: col('cream'), // cream tiles…
  rules: 'grid', borderColor: col('paper'), borderWidth: pt(4), // …parted by white rules
  bodyFontSize: pt(20), cellPadding: mm(3) }]; // the words' chips are 20 pt
const cells = (row) => PICTURE_WORDS.slice(row * 3, row * 3 + 3)
  .map((word) => ({ content: syllables(`{${word}}`), align: 'center' }));
let grid = { columnWidths: [1, 1, 1], rows: [cells(0), cells(1)] };
PICTURE_WORDS.forEach((word, k) => { // the picture above the word, 0.72 of the cell's width
  const resourceId = word.replaceAll('·', '').replace('ñ', 'n');
  grid = setCellImage(grid, { row: Math.floor(k / 3), col: k % 3 }, { resourceId, width: 0.72 });
});

setCellImage posa una imatge damunt del text d'una cel·la amb una fracció de la seva amplada interior, aquí 0,72 (36,5 mm), i la fila creix perquè hi càpiga. Cada aquarel·la és un JPEG pintat sobre blanc i multiplicat pel crema de les rajoles, de manera que s'assenta a la rajola sense requadre. Sota cada aquarel·la va la paraula en xips de síl·labes, que una cel·la admet com qualsevol paràgraf. L'estil de taula dibujos arrodoneix el marc i els seus emplenaments a 5 mm i separa les rajoles crema amb filets blancs de 4 pt.

#4 · Una línia d'espai abans del requadre

script.js · línies 157–169al codi complet
  calloutStyles: [
    { id: 'colorea', background: col('cream'), borderRadius: mm(4),
      marginTop: pt(0), // the :::space before the box is the whole gap above it
      padding: { top: mm(4), right: mm(5), bottom: mm(5), left: mm(5) },
      titleStyle: { fontFamily: LABEL, fontSize: pt(15), fontWeight: 700, color: col('ink') },
      body: { fontFamily: LABEL, fontSize: pt(10), lineHeight: pt(GRID), color: col('muted') } },
    { id: 'familia', backgroundEnabled: false,
      stripe: { enabled: true, side: 'top', width: pt(2.5), color: col('rule') },
      padding: { top: mm(3), right: mm(0), bottom: mm(0), left: mm(0) },
      titleStyle: { fontFamily: LABEL, fontSize: pt(8.5), fontWeight: 700, color: col('ink'),
        ...tag },
      body: { fontSize: pt(10.5), lineHeight: pt(GRID) } },
  ],

Entre l'última frase i el requadre per pintar, el Markdown porta :::space{lines=1}, una línia de 15 pt (5,3 mm). El marginTop del requadre és 0, així que aquesta línia és tot l'espai; sense ella, el requadre començaria just on acaba la línia de l'última frase. Un :::space que obre un requadre es descarta, de manera que el requadre comença amb el seu enunciat i els xips de la mostra de colors, i el seu propi :::space va darrere, entre la mostra i la tasca de pintar.

#5 · L'obertura de la lletra

script.js · línies 60–79al codi complet
const THINGS = t({ en: ['monkey', 'moon'], es: ['mariposa', 'manzana'] }); // ids and labels
const BAND = 104; // mm: the depth of the band's drawing; its wave dips to 101.9 mm
// The opener reserves seventeen grid lines, the first grid line past the foot of the band's
// image, so the first activity title stands on the grid like the others: two lines under
// the band, its instruction right under it.
const opener = { enabled: true, minHeight: pt(17 * GRID),
  slot: { elements: [
    picture('band', 'banda', at(0, 0, { width: mm(210), height: mm(BAND) })),
    words('unit', '{attr.unit}', LABEL, 9, 700, 'paper', at(SIDE, 12.5), { ...tag,
      box: { backgroundColor: col('ink'), borderRadius: mm(3),
        padding: { top: mm(1.2), right: mm(2.8), bottom: mm(1.2), left: mm(2.8) } } }),
    words('kicker', '{attr.kicker}', LABEL, 8.5, 600, 'muted', // level with the pill's text
      { anchor: { to: '#unit', edge: 'right-of' }, offset: { x: mm(4), y: mm(1.4) } }, tag),
    words('letter', '{titleText}', DISPLAY, 190, 700, 'ink', at(SIDE - 3, 19), { lineHeight: 1 }),
    words('name', '{attr.name}', LABEL, 20, 600, 'ink', at(SIDE + 1, 76)),
    picture('first', THINGS[0], at(146, 12, { width: mm(40) })),
    picture('second', THINGS[1], at(151, 53, { width: mm(30) })),
    ...[45.5, 84.5].map((y, k) => words(THINGS[k], THINGS[k], LABEL, 10, 600, 'muted',
      at(146, y, { width: mm(40) }), { align: 'center' })), // its name under each picture
  ] } };

La Mm és el text del títol ({titleText}), i el número de la unitat, la sèrie i el nom de la lletra són atributs d'aquesta mateixa línia. La franja, la papallona i la poma són imatges. La franja fa 104 mm d'alçada, i l'obertura reserva la pàgina fins a la primera línia de la retícula sota el seu peu, així que el títol de la primera activitat comença a 118,5 mm, sobre la retícula i 16,6 mm per sota del punt més baix de l'ona (101,9 mm).

#6 · Icones al costat dels títols d'activitat

script.js · línies 83–92al codi complet
const ICON = 9; // mm
const H2 = { level: 2, marginBottom: pt(0), // two grid lines per title, and two above it
  lineHeight: pt(2 * GRID), marginTop: pt(2 * GRID) };
const activity = (id, icon) => ({ id, advancedDesign: { enabled: true, slot: { elements: [
  picture('icon', icon, { anchor: { to: 'container', edge: 'top-left' },
    size: { width: mm(ICON), height: mm(ICON) } }),
  words('title', '{titleText}', LABEL, 15, 700, 'ink', { anchor: { to: '#icon',
    edge: 'right-of' }, offset: { x: mm(3) }, size: { width: mm(140), height: mm(ICON) } },
  { verticalAlign: 'middle' }), // centred on the icon
] } } });

Cada títol d'activitat indica el seu estil, com a ## Lee las frases {style="lee"}, i l'estil dibuixa una icona amb el títol centrat al costat. Continuen sent títols de nivell 2, així que l'espai el fixa el nivell H2: dues línies de la retícula de base de lineHeight per al títol i dues més de marginTop a sobre.

La recepta completa

Sandbox
// ═══ Postext Cookbook · Nº 060 · Early reader with syllable chips ════════════════
// https://postext.dev/en/cookbook/reading-primer-syllables
// Code: MIT · Text: original (CC BY 4.0) · Pictures: diffusion models · Icons: drawn in code
// Fonts: Andika, DynaPuff, Playpen Sans (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage, setCellImage,
} from 'https://esm.sh/postext';

const LANG = 'es'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'reading-primer-syllables';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#242832', paper: '#ffffff', muted: '#5f6470', // text; instructions
  cream: '#f6f0e3', rule: '#d3c9b6', // the band, the tiles and the pictures' ground; guides
  // The vowel code: a syllable takes its vowel's colour. White on these fills measures
  // 3.2–4.9:1, above WCAG's 3:1 for large text: the vowel chips are bold, 20 pt or more.
  a: '#d9482b', e: '#dd740c', i: '#1f9a8f', o: '#3f6fd8', u: '#9152cf' };
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults are linked to 'main-color': point it at the ink.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.ink })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, DISPLAY, LABEL] = ['Andika', 'DynaPuff', 'Playpen Sans']; // Andika: one-storey a
const [TOP, SIDE, GRID] = [18, 20, 15]; // mm, mm, pt: every activity starts on the 15 pt grid

// #region answer: one chip style per vowel, and {ma·má} in the text written out as chips
// A word's syllables are chips with nothing between them, so their boxes touch and the white
// border draws the seam. Across a word space a chip keeps at least `gap`: 0.5 em sets the
// words of a 24 pt row 4.2 mm apart, where the space alone leaves 2.3 mm. Inside a sentence
// the '-frase' twins keep no gap, so the word space alone parts a chip from the word before.
// A 24 pt chip, padding and border included, is 10.4 mm tall (gotcha: chip-overlap).
const syllable = { fontFamily: TEXT, bold: true, borderWidth: pt(1), borderColor: col('paper'),
  paddingX: em(0.26), paddingY: em(0.05), gap: em(0.5) };
const chipStyles = [
  ...'aeiou'.split('').flatMap((v) => [ // one pair per vowel
    { ...syllable, id: v, background: col(v), color: col('paper') }, // a syllable with m
    { ...syllable, id: `${v}-borde`, background: col('paper'), color: col(v), borderColor: col(v) },
  ]).flatMap((style) => [style, { ...style, id: `${style.id}-frase`, gap: em(0) }]),
  { ...syllable, id: 'pinta', bold: false, background: col('paper'), color: col('ink'),
    borderColor: col('ink'), borderWidth: pt(0.8) }, // an outline for the child to colour in
];
const vowel = (s) => s.normalize('NFD').toLowerCase().match(/[aeiou]/)[0]; // 'mú' → 'u'
const chipOf = (s, v, end) => `:chip[${s}]{style="${v}${/m/i.test(s) ? '' : '-borde'}${end}"}`;
// {mi·mo·sa} → :chip[mi]{style="i"}:chip[mo]{style="o"}:chip[sa]{style="a-borde"}, and a word
// written after another word, as in 'me {mi·ma}.', takes the '-frase' twins. A piece with no
// vowel, the m and the p of the English {m·a·p}, takes the vowel of its word.
const syllables = (text) => text.replace(/(\p{L} )?\{([\p{L}·]+)\}/gu, (_, before = '', word) =>
  before + word.split('·').map((s) => chipOf(s, vowel(s + word), before && '-frase')).join(''));

L'script.js compost funciona tal com és: enganxa'l com a script de mòdul en qualsevol pàgina o obre la recepta a CodePen. Carpeta de la recepta a GitHub ↗ (s'obre en una pestanya nova)

Variants

#Converteix les síl·labes en píndoles

Un radi més gran que la meitat de l'alçada del xip es retalla a aquesta meitat, de manera que un valor gran dibuixa extrems rodons. Una síl·laba d'una sola lletra surt gairebé rodona, i les juntes dins d'una paraula es converteixen en osques.

-  paddingX: em(0.26), paddingY: em(0.05), gap: em(0.5) };
+  paddingX: em(0.26), paddingY: em(0.05), gap: em(0.5), borderRadius: em(1) };

Errors freqüents

Error freqüent

Els xips més alts que l'interlineat toquen la línia següent

Un xip amb una caixa més alta que l'interlineat toca els xips de la línia següent (l'avís chipOverlap). Redueix-ne el farciment vertical, la vora o el cos, o obre l'interlineat. Chips en línia →

Error freqüent

:::space es descarta al principi d'un requadre o columna

:::space es descarta al principi d'una columna, d'un grup :::columns, d'un requadre sense títol que té més contingut i de la continuació d'un requadre partit. Des de postext 1.5 un requadre fet només de :::space fa l'alçada que demana l'espai (una caixa de resposta, lloc per escriure), i l'espai que va just sota el títol d'un requadre fa baixar el cos aquesta mateixa alçada. Per obrir amb espai un requadre sense títol, dona-li un títol o una primera línia i afegeix-hi després l'espai. Espai vertical explícit →

Comprovació del Sandbox · chipOverlap

Els xips toquen la línia següent

Per què. La caixa d'un estil de xip és més alta que l'interlineat, de manera que els xips de línies seguides es toquen.

Solució. Redueix el farciment vertical, el contorn o el cos del xip, o augmenta l'interlineat. Documentació →

Crèdits

Text
Text original, CC BY 4.0
Imatges
  • A watercolour of the butterfly on the opener · Generated With Diffusion Models · original
  • A watercolour of the apple on the opener · Generated With Diffusion Models · original
  • A watercolour of the hand in the picture grid · Generated With Diffusion Models · original
  • A watercolour of the map in the picture grid of both units · Generated With Diffusion Models · original
  • A watercolour of the table in the picture grid · Generated With Diffusion Models · original
  • A watercolour of the mimosa sprig in the picture grid · Generated With Diffusion Models · original
  • A watercolour of the monkey: in the picture grid of the Spanish unit and on the opener of the English one · Generated With Diffusion Models · original
  • A watercolour of the doll in the picture grid · Generated With Diffusion Models · original
  • A watercolour of the moon on the opener of the English unit · Generated With Diffusion Models · original
  • A watercolour of the mat in the picture grid of the English unit · Generated With Diffusion Models · original
  • A watercolour of the man in the picture grid of the English unit · Generated With Diffusion Models · original
  • A watercolour of the mug in the picture grid of the English unit · Generated With Diffusion Models · original
  • A watercolour of the mop in the picture grid of the English unit · Generated With Diffusion Models · original
  • A watercolour of the mud in the picture grid of the English unit · Generated With Diffusion Models · original
  • The cream band, the activity icons and the tracing rows, drawn in code in the page’s palette · Ignacio Ferro · MIT
Fonts
Andika (SIL OFL 1.1) · DynaPuff (SIL OFL 1.1) · Playpen Sans (SIL OFL 1.1)
Sandbox