انتقل إلى المحتوى الرئيسي
الوصفة رقم 200

دليل الوصفات · الفصل 10 · الإخراج والدمج

مربّعات نص الغلاف مثبّتة ومتسلسلة

قصتان لبو في كتاب ذي غلاف ورقي، غلافه منضّد في ستة مربّعات نص معلّق بعضها ببعض: عنوان يطول مربّعه مع النص، وملخّص يكمل في مربّع ثانٍ.

في هذه الصفحة
المُخرَج
Canvas · PDF
المستوى
متقدم
Postext
اختُبرت مع Postext 1.93.0
تتطلب ≥ 1.93.0 · postext-pdf ≥ 1.93.0
الترخيص
حُدّثت في 23 نوفمبر 2026
الشيفرة MIT · النص CC BY 4.0

ص 1 · 22 من 22

  • نموذج باللغة الإنجليزية: لا توجد طبعة عربية بعد
  • مقاس القص 125 × 195 مم
  • عمود واحد
  • EB Garamond 11/14.6
  • Cinzel
  • 22 صفحة
  • المستوى
  • Postext 1.93.0
  • أُخرجت في 79 ms
  • أسطر الشيفرة: 241

باختصار

كتاب صغير فيه قصتان لإدغار آلان بو، ومعه فرخ غلافه. كل نص على الغلاف يوضع تحت نص آخر أو فوقه أو بجانبه، فإذا طال العنوان نزل ما تحته، ويكمل نص الغلاف الخلفي تحت اقتباس.

ما الذي ستنضده

قصتان لإدغار آلان بو، «قناع الموت الأحمر» و«الصورة البيضاوية» (الطبعة الإنجليزية بالنص الأصلي، والإسبانية بترجمة كارلوس أوليفيرا الصادرة عام 1884)، في كتاب ذي غلاف ورقي مقاسه 125 × 195 مم، ومعه فرخ غلافه. لا يحمل أي نص على الغلاف إحداثيات: كل نص مربّع معلّق بشيء آخر. على الغلاف الأمامي يتدلّى العنوان من أعلى اللوحة، ويتدلّى العنوان الفرعي من العنوان، ويقف اسم المؤلف على أسفلها. يحتاج العنوان إلى سطرين في الطبعتين، فيطول مربّعه وينزل العنوان الفرعي معه. وعلى الغلاف الخلفي يملأ الملخّص مربّعًا ارتفاعه 50 مم، وتكمل الأسطر التي لا تتسع لها في مربّع ثانٍ تحت اقتباس من القصة. وفوق الصفحات ترسم الوصفة الفرخ مرتين: كما يُطبع، ثم مع إطار حول كل مربّع وعلامة على التسلسل.

تجيب هذه الوصفة عن

  • كيف أضع نصوص الغلاف بعضها نسبةً إلى بعض، فيدفع العنوانُ الأطول ما تحته إلى الأسفل ويستمر الملخّص في مربّع ثانٍ؟

الجواب المختصر

script.js · الأسطر 29–54في الشيفرة الكاملة
// A box anchored to a zone stands on that point of the zone's safe area; a box anchored to
// another box hangs below it, above it or beside it. With an anchor, `rect` gives only the
// size. The title may grow to 40 mm before its type shrinks, and the blurb sends the lines
// it cannot hold to the box under the quotation.
const size = (width, height) => ({ x: 0, y: 0, width, height });
const textBoxes = [
  // Front: the title from the top of the panel, the subtitle hung under it, the author
  // standing on the foot. Only the title's box grows; the subtitle follows it down.
  { name: 'title', rect: size(100, 14), anchor: { to: 'front', edge: 'top', y: 8 },
    maxHeight: 40 },
  { name: 'subtitle', rect: size(100, 9), anchor: { to: 'title', edge: 'below', y: 2 } },
  { name: 'author', rect: size(100, 8), anchor: { to: 'front', edge: 'bottom', y: -6 } },
  // Back: the blurb, a quotation under it, and the rest of the blurb under the quotation.
  // What the blurb's 50 mm cannot hold goes on in `blurb-end`, cut between lines.
  { name: 'blurb', rect: size(94, 50), anchor: { to: 'back', edge: 'top', y: 6 },
    next: 'blurb-end' },
  { name: 'quote', rect: size(94, 24), anchor: { to: 'blurb', edge: 'below', y: 5 },
    verticalAlign: 'middle' },
  { name: 'blurb-end', rect: size(94, 46), anchor: { to: 'quote', edge: 'below', y: 5 } },
];
const cover = {
  background: col('night'),
  elements: [{ id: 'art', kind: 'image', zone: 'front', x: 0, y: -3, width: 128, height: 201,
    resourceId: 'masque', fit: 'cover' }],
  textBoxes,
};

المكونات

الخطوط
EB Garamond, Cinzel (SIL OFL 1.1)
الأصول
  • masque-1024.jpg
  • The cover painting: a masked ball in a file of coloured rooms under a Gothic vault, with an ebony clock and a figure in a grave-shroud, in oils (Generated With Diffusion Models, أصلي)

طريقة التحضير

#1 · كل مربّع معلّق بلوحة أو بمربّع آخر

الشيفرة هي الجواب المختصر أعلاه. يسمّي anchor لوحة من الفرخ أو مربّع نص آخر، ونقطة. على اللوحة تكون النقطة واحدة من النقاط التسع لمنطقتها الآمنة، ويضع المربّع نقطته المقابلة عليها: edge: 'top' يوسّط العنوان على الغلاف الأمامي ويضع حافته العليا على حافة المنطقة الآمنة العليا، وedge: 'bottom' يضع أسفل مربّع المؤلف على أسفل اللوحة. وعلى المربّع يمكن أن تكون النقطة أيضًا below أو above أو right-of أو left-of. وx وy يزيحان المربّع عن تلك النقطة بالمليمتر. ومع التثبيت لا يعطي rect إلا المقاس، فتبقى المربّعات في أماكنها إذا ثخن الكعب أو تغيّر قطع الكتاب.

#2 · يطول العنوان فينزل العنوان الفرعي

script.js · الأسطر 68–84في الشيفرة الكاملة
const style = (id, fontFamily, size, lead, color, extra) => ({ id, fontFamily, fontSize: pt(size),
  lineHeight: pt(lead), color, italicColor: color, firstLineIndent: mm(0), textAlign: 'left',
  hyphenation: false, ...extra });
const mid = { textAlign: 'center' };
const caps = (tracking) => ({ fontWeight: 600, letterSpacing: pt(tracking) });
const coverStyles = [
  style('cover-title', 'Cinzel', 30, 33, col('bone'), { ...mid, fontWeight: 500 }),
  style('cover-subtitle', 'EB Garamond', 14, 18, col('gold'), { ...mid, italic: true }),
  style('cover-author', 'Cinzel', 10, 13, col('bone'), { ...mid, ...caps(2.2) }),
  style('cover-spine', 'Cinzel', 7, 8, col('bone'), { ...mid, ...caps(1.1) }),
  style('cover-blurb', 'EB Garamond', 10.5, 14.5, col('bone'), { textAlign: 'justify',
    hyphenation: true, firstLineIndent: mm(4) }),
  style('cover-blurb-first', 'EB Garamond', 10.5, 14.5, col('bone'), { textAlign: 'justify',
    hyphenation: true }),
  style('cover-quote', 'EB Garamond', 15, 19, col('gold'), { ...mid, italic: true }),
  style('cover-note', 'Cinzel', 7.5, 11, col('gold'), { ...caps(1.4), marginTop: pt(8) }),
];

العنوان منضّد بخط Cinzel بحجم 30 نقطة وتباعد أسطر 33. ارتفاع مربّعه 14 مم، أي سطر واحد. يحتاج «The Masque of the Red Death» و«La máscara de la muerte» إلى سطرين، فيطول المربّع مع النص حتى 40 مم هي maxHeight، ولا يصغر الحرف إلا بعد تجاوزها. والعنوان الفرعي مثبّت below العنوان على بعد 2 مم، فينزل بقدر السطر الثاني. أما المؤلف فمثبّت إلى أسفل اللوحة ولا يتحرك.

#3 · يكمل الملخّص في مربّع آخر

يحمل مربّع الملخّص next: 'blurb-end'. ما لا يتسع له يُقطع بين سطرين ويكمل في ذلك المربّع، وليس له إطار خاص في ملف Markdown الخاص بالغلاف. يتدلّى الاقتباس من الملخّص، وblurb-end من الاقتباس، فتبقى المسافات بين الثلاثة كما هي إذا زاد ارتفاع المربّع الأول. ولا يصغر نص السلسلة، كله دفعة واحدة، إلا إذا ضاق المربّع الثاني أيضًا، وحدّه الافتراضي 90 % (fit.minScale). والسطر المنضّد بالحروف الكبيرة الصغيرة الذهبية هو آخر فقرة في إطار الملخّص، ولذلك يختم النص في المربّع الثاني:

:::frame{slot="front"}
:::
 
:::frame{slot="blurb"}
:::paragraphs{style="cover-blurb-first"}
While a plague empties his country, Prince Prospero shuts himself up …
:::
 
:::paragraphs{style="cover-note"}
From the Raven Edition of Poe's works
:::
:::

الإطار front الفارغ يمنع buildCover من وضع العنوان والعنوان الفرعي واسم المؤلف من البيانات الوصفية للكتاب على الغلاف الأمامي: فالمربّعات هي التي تضعها هنا.

#4 · كتاب ذو غلاف ورقي يُحسب كعبه من الصفحات

script.js · الأسطر 58–64في الشيفرة الكاملة
const production = {
  bindings: [{ id: 'pur', name: 'PUR perfect binding', style: 'perfect', signature: 16,
    measures: { bleed: 3, spineAllowance: 0.5 } }],
  versions: [{ id: 'paperback', name: t({ en: 'Paperback', es: 'Rústica' }), binding: 'pur',
    isbn: '978-84-0000-200-8', spineText: { minSpine: 4.5 } }],
};
const folio = { paper: { type: 'bookWove', grammage: 120, bulk: 2.2, shade: '#f8f3e8' } };

تجليد PUR بالغراء في ملازم من 16 صفحة، على ورق كتب وزنه 120 غ/م² وانتفاخه 2.2. في الكتاب 21 صفحة، تصير 32 بعد التجليد، فيبلغ الكعب نحو 4.7 مم، وهو دون الـ6 مم التي يُكتب على الكعب ابتداءً منها افتراضيًا؛ لذلك تضبط النسخة spineText.minSpine على 4.5، ويحمل الكعب العنوان واسم المؤلف. الردمك رقم للعرض لا يخص أي كتاب.

#5 · متن الكتاب

script.js · الأسطر 88–128في الشيفرة الكاملة
const [W, H, TOP, FOOT, INNER, OUTER, LEAD] = [125, 195, 21, 23, 18, 16, 14.6]; // mm, pt
const at = (to, edge, x, y, box) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) },
  ...(box && { size: box }) });
const text = (id, content, look, place) => ({ kind: 'text', id, content, align: 'center',
  overflow: 'wrap', placement: place, ...look });
const face = (fontFamily, size, color, x) => ({ fontFamily, fontSize: pt(size), color, ...x });
const label = (size, color = col('muted')) => face('Cinzel', size, color, caps(size / 6));
const titling = (size, extra) => face('Cinzel', size, col('ink'), { fontWeight: 500, ...extra });
const none = { header: { elements: [] }, footer: { elements: [] }, numbered: false, toc: false };
const design = (minHeight, elements) => ({ enabled: true, minHeight: mm(minHeight),
  slot: { elements } });
const page = (parity) => ({ breakBefore: { enabled: true, parity } });
const rule = (id, y, to = 'page') => ({ kind: 'rule', id, direction: 'horizontal',
  thickness: pt(0.6), color: col('accent'), placement: at(to, 'top', 0, y, { width: mm(12) }) });
const wide = { width: mm(84) };
const headingStyles = [
  { ...none, id: 'half-title', advancedDesign: design(60, [
    text('t', '{title}', titling(12), at('page', 'top', 0, 62, wide))]) },
  // The title runs to two lines at 22 pt in both editions; the subtitle sits under them.
  { ...none, ...page('odd'), id: 'title-page', advancedDesign: design(H - TOP - FOOT, [
    text('t', '{title}', titling(22, { lineHeight: pt(27) }), at('page', 'top', 0, 44, wide)),
    text('s', '{subtitle}', face('EB Garamond', 13, col('ink'), { italic: true }),
      at('page', 'top', 0, 67)),
    rule('r', 77),
    text('a', '{author}', label(8.5, col('accent')), at('page', 'top', 0, 82)),
    text('c', '{attr.credit}', face('EB Garamond', 10, col('muted'), { italic: true }),
      at('page', 'top', 0, 118, { width: mm(76) })),
    text('i', '{attr.imprint}', label(7.5), at('page', 'bottom', 0, -26)),
  ]) },
  { ...none, ...page('even'), id: 'rights',
    advancedDesign: design(90, [rule('r', 84, 'container')]) },
  // Each tale opens on a recto, sunk 50 mm, its title on one line of Cinzel over a short rule.
  { ...page('odd'), id: 'tale', toc: false, header: { elements: [] }, advancedDesign: design(50, [
    text('t', '{titleText}', titling(13.5, { letterSpacing: pt(0.6) }),
      at('container', 'top', 0, 24, { width: mm(W - INNER - OUTER) })),
    rule('r', 40, 'container')]) },
  { ...none, ...page('odd'), id: 'colophon', advancedDesign: design(70, [
    rule('r', 62, 'container')]) },
];
const head = (id, content, parity) => text(id, content, { ...label(6.6), parity, pages: 'body' },
  at('page', 'top', 0, 11));

صفحة العنوان المختصر، فصفحة العنوان، فصفحة الحقوق، ثم تبدأ كل قصة على صفحة فردية منخفضة 50 مم، تحت عنوانها بخط Cinzel وخط أحمر قصير. تحمل الترويسات اسم المؤلف في الصفحة الزوجية وعنوان القصة في الفردية، وتختم صفحة البيانات الختامية الكتاب على آخر صفحة فردية.

#6 · الفرخ يُبنى من الصفحات المنضدة

script.js · الأسطر 293–301في الشيفرة الكاملة
const built = buildCover({ config, version: 'paperback', pages: book.pages, markdown: coverText,
  metadata: book.metadata, resources });
if (!('config' in built)) throw new Error(built.issues.map((i) => i.kind).join(', '));
// The barcode's digits name OCR-B, which no font server has: the label face sets them.
for (const [id, bytes] of Object.entries(built.files)) {
  await loadSvg(id, new TextDecoder().decode(bytes)
    .replace(/font-family="[^"]*"/g, 'font-family="Cinzel"'));
}
const sheet = await buildDocumentWithFonts(built.content, built.config, kitFonts(FONTS));

تأخذ buildCover الصفحات والبيانات الوصفية وملف Markdown الخاص بالغلاف، وتعيد مستندًا من صفحة واحدة هي الفرخ. وتصير مربّعات النص إطارات في تلك الصفحة، تُنضّد كما تُنضّد إطارات الصفحة المركّبة. أرقام الرمز الشريطي تطلب خط OCR-B، ولا يوفره أي خادم خطوط، فتنضدها الوصفة بخط Cinzel.

#7 · أين استقر كل مربّع

script.js · الأسطر 308–365في الشيفرة الكاملة
// Each text box comes back as a frame of the sheet's composed page, with the rect it was
// given after anchoring and growing, and `continuesTo` when its text goes on elsewhere.
const leaf = sheet.pages[0];
const scale = 1100 / leaf.width;
const names = new Set(textBoxes.map((b) => b.name));
const frames = (leaf.composed?.frames ?? []).filter((f) => names.has(f.name));
const views = document.createElement('section');
views.id = 'box-views';
views.style.cssText = 'display: grid; gap: 18px; '
  + 'grid-template-columns: repeat(auto-fit, minmax(300px, 600px)); justify-content: center; '
  + 'padding: 24px 16px; color: #ddd; font: 14px sans-serif';
for (const [mode, name] of [['flat', t({ en: 'As it prints', es: 'Como se imprime' })],
  ['boxes', t({ en: 'The text boxes', es: 'Las cajas de texto' })]]) {
  const [figure, canvas, caption] = ['figure', 'canvas', 'figcaption']
    .map((tag) => document.createElement(tag));
  figure.style.cssText = 'margin: 0; min-width: 0';
  canvas.setAttribute('role', 'img');
  canvas.setAttribute('aria-label', `${t({ en: 'The cover sheet', es: 'El pliego' })}: ${name}`);
  renderPageToCanvas(leaf, sheet, canvas, { scale });
  if (mode === 'boxes') {
    // Each box outlined and named; a chain drawn from the foot of a box to its next.
    const ctx = canvas.getContext('2d');
    ctx.setTransform(scale, 0, 0, scale, 0, 0);
    ctx.lineWidth = 2 / scale;
    ctx.font = `${13 / scale}px sans-serif`;
    for (const f of frames) {
      const { x, y, width, height } = f.rect;
      ctx.strokeStyle = ctx.fillStyle = '#f2c14e';
      ctx.setLineDash([8 / scale, 5 / scale]);
      ctx.strokeRect(x, y, width, height);
      ctx.setLineDash([]);
      // The name on a dark tab over the box's top-left corner, clear of the text.
      const tab = ctx.measureText(f.name).width + 10 / scale;
      ctx.fillStyle = '#141117';
      ctx.fillRect(x, y - 18 / scale, tab, 18 / scale);
      ctx.fillStyle = '#f2c14e';
      ctx.fillText(f.name, x + 5 / scale, y - 5 / scale);
      const next = frames.find((g) => g.id === f.continuesTo);
      if (next) {
        ctx.strokeStyle = '#ff7a59';
        // Out of the box's foot, down its right side, into the top of the next.
        const side = Math.max(x + width, next.rect.x + next.rect.width) + 14 / scale;
        ctx.beginPath();
        ctx.moveTo(x + width - 20 / scale, y + height);
        ctx.lineTo(side, y + height);
        ctx.lineTo(side, next.rect.y);
        ctx.lineTo(next.rect.x + next.rect.width - 20 / scale, next.rect.y);
        ctx.stroke();
      }
    }
  }
  // After the render, which sizes the canvas in CSS pixels: the column sets its width.
  canvas.style.cssText = 'display: block; width: 100%; height: auto';
  caption.textContent = name;
  figure.append(canvas, caption);
  views.append(figure);
}
document.getElementById('pages').before(views);

تعود صفحة الفرخ وإطاراتها في page.composed.frames، لكل منها المستطيل الذي أعطاه إياه التنضيد بعد التثبيت والإطالة، وcontinuesTo إذا كان نصه يكمل في إطار آخر. يحيط العرض الثاني المربّعات الستة بإطار فوق الفرخ، ويرسم التسلسل من أسفل الملخّص إلى أعلى blurb-end.

الوصفة كاملة

Sandbox
// ═══ Postext Cookbook · Nº 200 · Cover text boxes anchored, chained and grown ══════════════
// https://postext.dev/en/cookbook/cover-text-boxes-anchored
// Code: MIT · Text: E. A. Poe, tr. C. Olivera (public domain) · Art: diffusion models
// Fonts: EB Garamond, Cinzel (SIL OFL 1.1) · Needs postext ≥ 1.93.0
//
// Two of Poe's tales as a small paperback, and its cover sheet set from six text boxes.
// None of them has coordinates: each hangs from a panel of the sheet or from another box,
// so a title that runs to two lines takes the subtitle down with it, and the blurb on the
// back runs on under a quotation into a second box.
import { buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, inlineSvgFonts }
  from 'https://esm.sh/postext';
import { buildCover } from 'https://esm.sh/postext/production';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'cover-text-boxes-anchored';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// The pages' four colours, then the cover's: a night ground, bone type, a dull gold.
const palette = { ink: '#231f1c', accent: '#8e2219', muted: '#6a625a', paper: '#faf6ee',
  night: '#141117', bone: '#ece3cf', gold: '#c9a66b' };
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  { id: 'main-color', name: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];

// #region answer: six text boxes placed against the panels and against each other
// A box anchored to a zone stands on that point of the zone's safe area; a box anchored to
// another box hangs below it, above it or beside it. With an anchor, `rect` gives only the
// size. The title may grow to 40 mm before its type shrinks, and the blurb sends the lines
// it cannot hold to the box under the quotation.
const size = (width, height) => ({ x: 0, y: 0, width, height });
const textBoxes = [
  // Front: the title from the top of the panel, the subtitle hung under it, the author
  // standing on the foot. Only the title's box grows; the subtitle follows it down.
  { name: 'title', rect: size(100, 14), anchor: { to: 'front', edge: 'top', y: 8 },
    maxHeight: 40 },
  { name: 'subtitle', rect: size(100, 9), anchor: { to: 'title', edge: 'below', y: 2 } },
  { name: 'author', rect: size(100, 8), anchor: { to: 'front', edge: 'bottom', y: -6 } },
  // Back: the blurb, a quotation under it, and the rest of the blurb under the quotation.
  // What the blurb's 50 mm cannot hold goes on in `blurb-end`, cut between lines.
  { name: 'blurb', rect: size(94, 50), anchor: { to: 'back', edge: 'top', y: 6 },
    next: 'blurb-end' },
  { name: 'quote', rect: size(94, 24), anchor: { to: 'blurb', edge: 'below', y: 5 },
    verticalAlign: 'middle' },
  { name: 'blurb-end', rect: size(94, 46), anchor: { to: 'quote', edge: 'below', y: 5 } },
];

يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)

تنويعات

#علّق اسم المؤلف تحت العنوان الفرعي

عندئذ يتبع المؤلفُ العنوانَ إلى الأسفل أيضًا، بدل أن يبقى على أسفل اللوحة.

-  { name: 'author', rect: size(100, 8), anchor: { to: 'front', edge: 'bottom', y: -6 } },
+  { name: 'author', rect: size(100, 8), anchor: { to: 'subtitle', edge: 'below', y: 6 } },

#صغّر العنوان الطويل إلى سطر واحد

من غير maxHeight يبقى مربّع العنوان على ارتفاعه 14 مم، ويصغّر التنضيد العنوان حتى يتسع له: هنا في سطر واحد، بنحو ثلثي حجمه.

   { name: 'title', rect: size(100, 14), anchor: { to: 'front', edge: 'top', y: 8 },
-    maxHeight: 40 },
+    fit: { minScale: 0.6 } },

أخطاء شائعة

  • المربّع الذي يسمّيه next مربّع آخر يأخذ النص الذي يمرّره إليه ذلك المربّع. لا تعطه إطارًا خاصًا في ملف Markdown الخاص بالغلاف، واختم إطار المربّع الأول بما ينبغي أن يختم النص، كالملاحظة هنا.
  • التثبيت الذي لا يسمّي شيئًا، أو يسمّي المربّع نفسه، أو يغلق حلقة، يُبلَّغ عنه، ويبقى المربّع على rect الخاص به. أعطِ كل مربّع مثبّت rect بمقاس حقيقي.
  • لا تنطبق maxHeight على المربّع المدار (rotate)، فهو يحتفظ بمقاس rect الخاص به.

الحقوق

الوصفة
Ignacio Ferro
النص
  • The Masque of the Red Death and The Oval Portrait, from The Works of Edgar Allan Poe (Raven Edition, 1903), Project Gutenberg eBooks #2148 and #2147 · Edgar Allan Poe · ملك عام
  • La máscara de la muerte and El retrato oval, translated by Carlos Olivera, from Novelas y cuentos (Garnier Hermanos, Paris, 1884), as transcribed on Wikisource, spelling and punctuation modernised · Carlos Olivera · ملك عام
الصور
  • The cover painting: a masked ball in a file of coloured rooms under a Gothic vault, with an ebony clock and a figure in a grave-shroud, in oils · Generated With Diffusion Models · أصلي
الخطوط
EB Garamond (SIL OFL 1.1) · Cinzel (SIL OFL 1.1)
الشيفرة
MIT، مثل Postext
SandboxPDF