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

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

عيّنة خطوط تُحمَّل كل خطوطها قبل الإخراج

عيّنة خطوط من أربع صفحات تُبنى مرة قبل الأوان عمدًا لتكون دليلًا، ثم تُبنى بعد تحميل كل خط تطلبه الإعدادات والنص.

في هذه الصفحة
المُخرَج
Canvas
المستوى
متوسط
Postext
اختُبرت مع Postext 1.65.0
تتطلب ≥ 1.25.0
الترخيص
حُدّثت في 10 أكتوبر 2026
الشيفرة MIT · النص CC BY 4.0
  • نموذج باللغة الإنجليزية: لا توجد طبعة عربية بعد
  • مقاس القص 180 × 240 مم
  • عمود واحد
  • Ysabeau Office 11/15.5
  • IBM Plex Mono
  • Noto Serif Display
  • 4 صفحات
  • المستوى
  • Postext 1.57.1
  • أُخرجت في 4 ms
  • أسطر الشيفرة: 188

باختصار

كتيّب من أربع صفحات يعرض ثلاثة خطوط. يبيّن لماذا يجب أن يكتمل تحميل الخطوط كلها قبل تخطيط الصفحات، وإلا انكسرت الأسطر في غير مواضعها.

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

House Specimen Nº 3، من دار Pellow Lane Press المتخيَّلة، عيّنة خطوط من أربع صفحات لثلاثة خطوط. على الغلاف مساحة بلون اللازورد الفائق فيها Ag أبيض بخط Noto Serif Display المائل بحجم 240 نقطة، وسطران بخط ثابت العرض يذكران الخطوط الثلاثة؛ ويقع العنوان تحت تلك المساحة. وتعرض الصفحة 2 خط Ysabeau Office في شلال من 7 إلى 14 نقطة، ثم تنضّد جملًا جامعة لحروف الإسبانية والبولندية والتشيكية تحتاج حروفها ż وř وů إلى ملف خط ثانٍ. والصفحة 3 صفحة التدقيق: جدول بخط IBM Plex Mono يملؤه المثال، بالخطوط العشرة التي يعرّفها الكتيّب، والستة التي نُضّدت بها صفحاته، والملفات التي جلبها المتصفح لكل منها. وتنضّد الصفحة 4 الفقرة الأولى من الصفحة 1 مرتين، من بناء مبكر ومن البناء الأخير. جرى البناء المبكر قبل أن يكون في المتصفح أي ملف خط، فانتهت أسطره في مواضع أخرى وتجاوز بعضها عرض السطر.

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

  • لماذا تتغير مواضع كسر الأسطر عندي، أو تتداخل الكلمات في ملف PDF، وكيف أحمّل الخطوط تحميلًا صحيحًا؟
  • كيف أستعمل خطوط علامتي التجارية أو خطوطًا مرخّصة في الإخراج وأضمّنها في ملف PDF؟
  • كيف أعرف ما الخطأ في مستندي (تحذيرات، فيض، إخراج لا يستقر)؟

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

script.js · الأسطر 314–331في الشيفرة الكاملة
// buildDocumentWithFonts starts with prepareFonts: it reads the config and the text for every
// face they ask for (text, headings, chips, table, captions, opener, running heads), in each
// weight and slant, and loads them for the characters the document sets. The page declares its
// files (declareFaces), so they load through document.fonts; a face nothing declares would be
// asked of a resolve(family, weight, style) option. Then it builds, reads the faces the pages
// are set in, loads any that the config did not name and builds again.
let report; // { loaded, missing, synthesized }: lists of { family, weight, style }
const build = () => buildDocumentWithFonts(content(), config(),
  { onFonts: (found) => { report = found; } }); // what the last look at the pages found

kitStatus('Loading fonts…'); // the kit's bar: it also reports any error thrown below
const early = buildDocument(content(), config()); // on purpose: the page has no font yet (page 4)
declareFaces(FONTS);
const fitted = await build(); // every face loaded before a line is measured
audit = auditOf(fitted, report); // page 3's table
drawProof(early, fitted); // page 4's picture
const doc = await build(); // nothing left to load: the same pages, table and picture filled in
showPages(doc, { title: 'Load every font before layout' });

المكونات

الخطوط
Ysabeau Office, Noto Serif Display, IBM Plex Mono (SIL OFL 1.1)
الأصول
لا شيء: كل صورة مرسومة بالشيفرة

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

#1 · عرّف كل ملف من غير أن تجلبه

script.js · الأسطر 268–287في الشيفرة الكاملة
const SUBSETS = { // the characters each file covers, copied from the family's @font-face CSS
  latin: 'U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,'
    + 'U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD',
  'latin-ext': 'U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,'
    + 'U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,'
    + 'U+A720-A7FF' };
const FILES = new Map(); // FontFace → the subset its file covers, for the audit
function declareFaces(fonts) { // Fontsource's static files stand in for your own /fonts/ folder
  for (const { family, weight, style } of facesOf(fonts)) {
    const id = family.toLowerCase().replaceAll(' ', '-');
    for (const [subset, unicodeRange] of Object.entries(SUBSETS)) {
      const file = `${id}@5/files/${id}-${subset}-${weight}-${style}.woff2`;
      // Adding a face fetches nothing: the file downloads when a load or a line needs it.
      const face = new FontFace(family, `url(https://cdn.jsdelivr.net/npm/@fontsource/${file})`,
        { weight: `${weight}`, style, unicodeRange });
      FILES.set(face, subset);
      document.fonts.add(face);
    }
  }
}

كائن FontFace ملف واحد، مثل قاعدة @font-face، فالخط الذي له ملف latin وملف latin-ext يُعرَّف بكائنين FontFace يشتركان في العائلة والوزن والنمط ويختلفان في unicodeRange، المنسوخ من CSS العائلة. وإضافتهما إلى document.fonts لا تنزّل شيئًا: يجلب المتصفح الملف حين يحتاج نداءُ load() أو سطرٌ من النص إلى حروفه. يحمّل Postext الخطوط التي تعرّفها الصفحة عبر document.fonts؛ أما الخط الذي لم يعرّفه أحد فيطلب ملفاته من الخيار resolve، وبهذه الطريقة تتلقى الوصفات الأخرى ملفات Fontsource من العُدّة. وcustomFonts في الإعدادات لا تفعل سوى وصف ملفات حزمة .postext، فالصفحة المبنية من Markdown تعرّف خطوطها بنفسها أو تقدّم resolve.

#2 · حمّل الخطوط ثم ابنِ

الشيفرة هي الجواب المختصر أعلاه. تبدأ buildDocumentWithFonts بـprepareFonts، التي تقرأ من الإعدادات والنص كل خط يطلبانه، بكل وزن ونمط، وتحمّله متخذةً حروف المستند نفسه عيّنةً، فتصل ملفات latin-ext مع الجمل الجامعة البولندية والتشيكية (تحميل الخطوط قبل الإخراج). ثم تبني، وتقرأ الخطوط التي نُضّدت بها الصفحات، وتحمّل ما لم تسمّه الإعدادات منها، وتبني من جديد. ويتلقى onFonts تقرير هذه المراجعة الأخيرة: الخطوط المحمَّلة (loaded)، والناقصة (missing)، والتي كان المتصفح سيزوّرها من وزن أو نمط آخر (synthesized). يبني المثال ثلاث مرات لأن الكتيّب يطبع دليله بنفسه: مرة قبل الأوان، ومرة بالخطوط، ومرة أخيرة بعد ملء الجدول والصورة.

#3 · ابنِ التدقيق من التقرير

script.js · الأسطر 291–309في الشيفرة الكاملة
const SET = { loaded: 'yes', synthesized: 'faked', missing: 'in a fallback' }; // the report
const nameOf = (f) => `${f.family.replaceAll('"', '')} ${f.weight} ${f.style}`; // or a FontFace
function auditOf(doc, report) {
  const found = Object.keys(SET).flatMap((kind) => report[kind].map((f) => [nameOf(f), kind]));
  const inPages = new Map(found);
  const loaded = [...FILES].filter(([face]) => face.status === 'loaded');
  const faces = new Map([...facesOf(FONTS), ...Object.keys(SET).flatMap((kind) => report[kind])]
    .map((f) => [nameOf(f), f])); // the declared faces, then any the pages set without a file
  const rows = [...faces].map(([name, f], i, all) => [
    i && all[i - 1][1].family === f.family ? '' : f.family, // each family named once
    `${f.weight}${f.style === 'italic' ? ' italic' : ''}`, SET[inPages.get(name)] ?? 'no',
    loaded.filter(([face]) => nameOf(face) === name).map(([, subset]) => subset).join(' · ')
      || 'none'].map((cell) => ({ content: cell })));
  // What else to read in a finished layout: its content warnings, its passes, its warnings.
  return { rows, note: `${report.loaded.length} of ${rows.length} faces set in the pages · `
    + `${loaded.length} of ${FILES.size} files fetched · fontFallback warnings: `
    + `${fallbacksIn(doc) || 'none'} · ${doc.converged ? '' : 'not '}converged · layout warnings: `
    + `${doc.warnings?.length || 'none'}` };
}

ينطلق الجدول من الخطوط التي يعرّفها FONTS ويضيف ما يذكره التقرير عن كل منها: هل نضّدت به الصفحات شيئًا، أم زوّره المتصفح، أم خرج بخط احتياطي. ويسرد العمود الأخير الملفات التي بلغ كائن FontFace الخاص بها الحالة loaded. جُلب ستة عشر ملفًا من العشرين: يحمّل Postext الخطوط الأربعة لعائلة النص، لأن ** و* قد تطلبانها في أي فقرة، أما مائلا الخط ثابت العرض، اللذان لا يذكرهما أي إعداد، فلم يُنزَّلا قط. وتقرأ الملاحظة ثلاثة أشياء أخرى من المستند المكتمل: contentWarnings، حيث يظهر الخط المقيس بخط احتياطي باسم fontFallback؛ وconverged، وقيمته true حين تستقر تمريرات الإخراج؛ وwarnings. افحص الثلاثة قبل أن تعرض صفحة أو تصدّرها.

#4 · احتفظ ببناء مبكر دليلًا

script.js · الأسطر 126–174في الشيفرة الكاملة
const STRIP = { lines: 8, overrun: 10 }; // page 1's first paragraph; mm shown past the measure
const PROOF = { // px: two strips a lead apart, cut at 300 dpi
  width: Math.round(((MEASURE + STRIP.overrun) / 25.4) * 2 * DPI),
  height: Math.round((((2 * STRIP.lines + 1) * LEAD) / 72) * 2 * DPI) };
const proof = { moved: 0, total: 0, faces: 0 }; // lines the early build broke elsewhere, of all
const fallbacksIn = (doc) => // a build lists each face its font set could not give
  (doc.contentWarnings ?? []).filter((w) => w.kind === 'fontFallback').length;
const proofFigure = () => ({ id: 'proof', typeId: 'figure', kind: 'bitmap', createdAt: 0,
  updatedAt: 0, placement: here,
  bitmap: { fileId: 'proof.png', format: 'png', width: PROOF.width, height: PROOF.height },
  caption: 'The first paragraph of page 1 as the early build set it, measured before the fonts '
    + 'had arrived (above), and as the last build set it (below). The early build broke '
    + `${proof.moved} of its ${proof.total} lines of text elsewhere, and its own warnings name `
    + `${proof.faces} faces set in a fallback. The rule marks the measure.`,
  altText: `Two strips of the same ${STRIP.lines} lines of text. In the upper strip the lines `
    + 'break in other places and some run past a vertical rule; in the lower one every line '
    + 'stops short of it.' });
function drawProof(first, last) {
  const linesOf = (doc) => doc.blocks.filter((b) => b.type === 'paragraph')
    .map((b) => b.lines.map((l) => l.text));
  const [before, after] = [first, last].map(linesOf);
  proof.total = before.flat().length;
  proof.faces = fallbacksIn(first);
  proof.moved = before.flatMap((lines, i) => lines.filter((t, j) => t !== after[i]?.[j])).length;
  const canvas = Object.assign(document.createElement('canvas'), PROOF);
  const ctx = canvas.getContext('2d');
  const strip = (PROOF.height * STRIP.lines) / (2 * STRIP.lines + 1);
  const edge = Math.round((PROOF.width * MEASURE) / (MEASURE + STRIP.overrun));
  // The renderer clips each column 2 pt past its edge, which would cut the early build's lines
  // at the measure: paint a copy of page 1 whose column reaches across the whole strip.
  const wide = (column) => ({ ...column,
    bbox: { ...column.bbox, width: column.bbox.width + (STRIP.overrun / 25.4) * DPI } });
  [first, last].forEach((doc, i) => {
    const page = document.createElement('canvas');
    renderPageToCanvas({ ...doc.pages[0], columns: doc.pages[0].columns.map(wide) }, doc, page,
      { scale: 2 }); // 300 dpi
    const { x, y } = doc.pages[0].columns[0].blocks.find((b) => b.type === 'paragraph').bbox;
    ctx.drawImage(page, 2 * x, 2 * y, PROOF.width, strip,
      0, i * (PROOF.height - strip), PROOF.width, strip);
  });
  ctx.fillStyle = `${palette.ultramarine}1f`; // a pale wash over the margin past the measure
  ctx.fillRect(edge, 0, PROOF.width - edge, PROOF.height);
  ctx.fillStyle = palette.ultramarine; // a hairline at the measure, and each strip's name
  ctx.fillRect(edge, 0, 2, PROOF.height);
  ctx.font = `700 ${(7 / 72) * 2 * DPI}px "IBM Plex Mono"`; // 7 pt, loaded by now
  ['early', 'last'].forEach((name, i) => // on the last line of each strip
    ctx.fillText(name, edge + 12, (i ? PROOF.height : strip) - 16));
  registerResourceImage('proof.png', canvas);
}

ينادي المثال buildDocument مرة واحدة قبل أن يعرّف أي خط، فيقيس ذلك البناء كل كلمة بالخط الاحتياطي في المتصفح. وبعد وصول الخطوط الحقيقية يرسمه المثال مرة أخرى ويقارنه سطرًا بسطر بالبناء الأخير؛ ومن هذه المقارنة يأتي عدد الأسطر الذي في التعليق، أما عدد الخطوط فمن تحذيرات fontFallback في البناء المبكر نفسه. السطر غير المضبوط المقيس بخط احتياطي أضيق يتجاوز عرض السطر إلى أن يقصّ مقطعُ العمود، الذي يمتد نقطتين بعد حافته، حروفَه الأخيرة؛ لذلك يرسم المثال الصفحة 1 بعمود موسَّع ليُظهر التجاوز كله. ويرسم Canvas وpostext-pdf كل مقطع من سطر مضبوط أو مختلط الأنماط حيث قاسه الإخراج، فالخط الحقيقي الأعرض من الاحتياطي يُطبع فوق الكلمة التالية، وتتراكب كلمات ملف PDF بُني قبل وصول خطوطه. ولا ينتقل شيء من البناء المبكر إلى الذي يليه: تجد prepareFonts الخطوط الجديدة في document.fonts وتُسقط العروض المقيسة في عائلاتها، فلا حاجة إلى نداء clearMeasurementCache().

#5 · شلال على إيقاع النص

script.js · الأسطر 30–44في الشيفرة الكاملة
const bodyText = () => ({
  fontFamily: TEXT, fontSize: pt(11), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  textAlign: 'left', firstLineIndent: pt(0), paragraphSpacing: true }); // ragged and spaced
// Every waterfall size and pangram is two leads (31 pt) deep, on the text's 15.5 pt rhythm.
const line = (size) => ({ fontSize: pt(size), lineHeight: pt(2 * LEAD) });
const paragraphStyles = () => [
  ...[7, 8, 9, 10, 11, 12, 14].map((size) => ({ id: `s${size}`, ...line(size) })),
  { id: 'pangram', ...line(13) },
  { id: 'colophon', fontSize: pt(7), lineHeight: pt(10), fontFamily: MONO, color: col('muted') }];
// Size labels: boxless mono chips. A Plex Mono letter is 0.6 em wide, so a one-digit label gets
// half a letter each side and the samples start on one edge.
const tag = { fontFamily: MONO, fontSize: pt(7), color: col('ultramarine'),
  backgroundEnabled: false, borderWidth: pt(0), paddingX: pt(0), gap: mm(2.5) };
const chipStyles = () => [{ id: 'size', ...tag }, { id: 'size-1', ...tag, paddingX: em(0.3) }];

ينضّد خط Ysabeau Office النص بحجم 11 نقطة على 15.5 نقطة، بسطر فارغ بين الفقرات بدل الإزاحة. النص غير مضبوط، فتحتفظ كل مسافة بين كلمتين بعرضها الطبيعي. والعريض والمائل والإحالات تُنضَّد بالحبر؛ ولو تُركت لأخذت اللون الرئيسي. وكل حجم في الشلال وكل جملة جامعة نمط فقرة بعمق سطرين (31 نقطة)، فتحتفظ الصفحة بإيقاع النص البالغ 15.5 نقطة. وتسميات الأحجام شارات بخط ثابت العرض، وتأخذ الأحجام ذات الرقم الواحد حشوة بنصف حرف من كل جانب، فتبدأ كل عيّنة عند الحافة نفسها.

#6 · ثلاثة خطوط على غلاف واحد

script.js · الأسطر 48–74في الشيفرة الكاملة
const Y = { kicker: 14, glyphs: 17, label: FIELD - 12, title: FIELD + 10, // mm from the top edge
  end: FIELD + 42 }; // where the opener ends: under the title, the lead and a line of air
const ITALIC_FOOT = 5; // mm: the italic A's foot reaches this far left of the glyphs' origin
const at = (x, y, width) => ({ anchor: { to: 'page', edge: 'top-left' },
  offset: { x: mm(x), y: mm(y) }, ...(width && { size: { width: mm(width) } }) });
const text = (id, content, style, placement) => ({ kind: 'text', id, content, align: 'left',
  overflow: 'wrap', ...style, placement }); // a running head wraps too, never '…'
const cover = () => ({ level: 1, fontSize: pt(30), italic: true, // headings.levels[0]
  breakBefore: { enabled: true, parity: 'odd' }, // the cover is a recto
  span: 'page', // the heading is set across the page; its field hangs from the bleed
  advancedDesign: { enabled: true, minHeight: mm(Y.end - MARGIN.top), // from the top margin
    slot: { elements: [
      { kind: 'box', id: 'field', style: { backgroundColor: col('ultramarine') }, placement: {
        anchor: { to: 'bleed', edge: 'top-left' }, size: { width: 'fill', height: mm(FIELD) } } },
      text('kicker', '{attr.kicker}', { ...label, fontWeight: 700, color: col('paper') },
        at(MARGIN.inner, Y.kicker)),
      text('glyphs', '{attr.glyphs}', { ...display, fontSize: pt(240), lineHeight: 1,
        color: col('paper') }, at(MARGIN.inner + ITALIC_FOOT, Y.glyphs)),
      text('label', '{attr.label}', { ...label, color: col('mist') }, at(MARGIN.inner, Y.label)),
      text('faces', '{attr.faces}', { ...label, color: col('mist') },
        { anchor: { to: '#label', edge: 'below' }, offset: { y: mm(1.2) } }),
      text('title', '{titleText}', { ...display, fontSize: pt(30), lineHeight: 1.05,
        color: col('ink') }, at(MARGIN.inner, Y.title, PAGE.width - 2 * MARGIN.inner)),
      text('lead', '{attr.lead}', { fontFamily: TEXT, italic: true, fontSize: pt(12),
        lineHeight: 1.35, color: col('ink') }, { anchor: { to: '#title', edge: 'below' },
        offset: { y: mm(3) }, size: { width: mm(MEASURE) } }),
    ] } } });

الغلاف هو تصميم مستوى H1: حروف السمة glyphs في العنوان بخط العرض بحجم 240 نقطة، وتحتها سطران بخط ثابت العرض يذكران ذلك الخط وخطي النص والتسميات، كما في ورقة عيّنات مسبك حروف. يمدّ span: 'page' العنوان على عرض الصفحة، وتُربط المساحة بالزاوية العليا اليسرى من النزف، فتمتد خارج الحافة العليا. ويُحتسب minHeight من الهامش الأعلى ويحجز المساحة حتى Y.end، أي 42 مم تحت المساحة الملونة؛ ومن دونه يبدأ النص أعلى بسطر، ملتصقًا تحت المقدمة.

الوصفة كاملة

Sandbox
// ═══ Postext Cookbook · Nº 026 · Type specimen with every font loaded before layout ═════════
// https://postext.dev/en/cookbook/fonts-before-layout
// Code: MIT · Text: original (CC BY 4.0) · Picture: cut from the pen's own early and last builds
// Fonts: Ysabeau Office, Noto Serif Display, IBM Plex Mono (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import { buildDocument, buildDocumentWithFonts, renderPageToCanvas, defaultResourceTypes,
  registerResourceImage } from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'fonts-before-layout';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const PAGE = { width: 180, height: 240 }; // mm
const MARGIN = { top: 22, bottom: 24, inner: 20, outer: 48 }; // mm: inner is the spine side
const MEASURE = PAGE.width - MARGIN.inner - MARGIN.outer; // 112 mm: about 70 letters at 11 pt
const FIELD = 122; // mm from the top edge: the ultramarine field of the opener
const LEAD = 15.5; // pt: the body leading and the step of every vertical space
const DPI = 150; // the page's resolution: the proof on page 4 is cut at twice this
const [TEXT, DISPLAY, MONO] = ['Ysabeau Office', 'Noto Serif Display', 'IBM Plex Mono'];
const palette = { ink: '#16161a', ultramarine: '#3246d3', mist: '#c9d0f6', // mist: 4.6:1 on
  rule: '#cfc9bd', muted: '#6b6a70', paper: '#ffffff' }; // ultramarine, for labels on the field
// Every colour is linked to its palette entry; main-color catches any default left unstated.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = () => Object.entries({ ...palette, 'main-color': palette.ultramarine })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const label = { fontFamily: MONO, fontSize: pt(7.5), letterSpacing: pt(1.2),
  textTransform: 'uppercase' };
const display = { fontFamily: DISPLAY, fontWeight: 900, italic: true };

// #region type: the text face at 11 on 15.5 pt, and a waterfall of it on two leads a line
const bodyText = () => ({
  fontFamily: TEXT, fontSize: pt(11), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  textAlign: 'left', firstLineIndent: pt(0), paragraphSpacing: true }); // ragged and spaced
// Every waterfall size and pangram is two leads (31 pt) deep, on the text's 15.5 pt rhythm.
const line = (size) => ({ fontSize: pt(size), lineHeight: pt(2 * LEAD) });
const paragraphStyles = () => [
  ...[7, 8, 9, 10, 11, 12, 14].map((size) => ({ id: `s${size}`, ...line(size) })),
  { id: 'pangram', ...line(13) },
  { id: 'colophon', fontSize: pt(7), lineHeight: pt(10), fontFamily: MONO, color: col('muted') }];
// Size labels: boxless mono chips. A Plex Mono letter is 0.6 em wide, so a one-digit label gets
// half a letter each side and the samples start on one edge.
const tag = { fontFamily: MONO, fontSize: pt(7), color: col('ultramarine'),
  backgroundEnabled: false, borderWidth: pt(0), paddingX: pt(0), gap: mm(2.5) };
const chipStyles = () => [{ id: 'size', ...tag }, { id: 'size-1', ...tag, paddingX: em(0.3) }];
// #endregion

// #region opener: the H1 as a bleed field, the display face at 240 pt, labels naming the faces
const Y = { kicker: 14, glyphs: 17, label: FIELD - 12, title: FIELD + 10, // mm from the top edge

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

تنويعات

#قدّم الملفات عبر resolve

kitFonts(FONTS) في وصفة من نص Markdown إلى صفحة مصمّمة لا تعرّف شيئًا: يطلب Postext من resolve ملفات كل خط ويضيفها بنفسه إلى document.fonts.

#انسَ خطًا

احذف الوزن العريض من IBM Plex Mono، الذي ينضّد العنوان التمهيدي ورأس الجدول وتسميات التعليقات: يثخّن المتصفح الوزن العادي، ويضع الجدول على الخط علامة faked، وتعدّ الملاحظة تحذير fontFallback واحدًا يذكر IBM Plex Mono 700 بالسبب synthesized.

-  'IBM Plex Mono': ['400', '400i', '700', '700i'], // labels, chips, the table, captions
+  'IBM Plex Mono': ['400', '400i', '700i'], // labels, chips, the table, captions

#ضمّن الخطوط نفسها في PDF

تضمّن renderToPdf البايتات التي يعيدها fontProvider لكل خط، والمزوّد في وصفة ملف PDF حقيقي بالخطوط نفسها مضمَّنة يقدّم ملفات latin من Fontsource، وهي تتوقف عند Latin-1: لحروف هذا الكتيّب ż وł وř وů، اجعله يعيد ملف الخط الكامل لكل خط من مجلدك.

أخطاء شائعة

خطأ شائع

ملفات Fontsource تغطي الحروف لا الرموز

تضمّن العُدّة ملف latin من Fontsource لكل خط، ومعه ملف latin-ext للحروف č وł و†، وملف greek للحروف α وχ (في عائلة تضمه: لا يضمه Lora ولا Gelasio)، حين يستعملها النص، على الشاشة وفي PDF. أما رموز مثل → و≈ و✓ و★ فليست في أي من هذه الملفات فتغيب عن PDF: ارسمها، أو اكتبها رياضيات، أو اختر خطًا تضمها ملفاته. الخطوط المضمَّنة في PDF →

تحذير الإخراج · fontFallback

خط بديل في الإخراج

السبب. شكلُ خطٍّ نُضِّد به النص لم يكن في مجموعة الخطوط حين أُخرج المستند (`reason: 'missing'`)، أو ليس للعائلة ملف لذلك الوزن أو الميل فيرسمه المتصفح من شكل آخر (`'synthesized'`)، فقيست فواصل الأسطر بخط غير الذي يضمّنه ملف PDF.

الحل. حمّل الخطوط قبل البناء الأول: `prepareFonts(content, config, { resolve })`، أو ابنِ بـ`buildDocumentWithFonts` التي تحمّل كذلك أي شكل خط استعملته الصفحات ثم تعيد البناء. وفي حالة `synthesized` حمّل ذلك الوزن أو الميل، أو اختر وزنًا تملكه العائلة. التوثيق →

فحص Sandbox · missingFont

خط مفقود

السبب. عائلة خط مذكورة في الإعدادات لم تُحمَّل قط في المتصفح، فقيس النص ورُسم بخط بديل من النظام.

الحل. صحّح اسم العائلة (عائلة واحدة، لا قائمة خطوط CSS) وحمّل كل أشكال الخط قبل أول بناء؛ وفي مثال CodePen أدرجها في FONTS. التوثيق →

فحص Sandbox · missingFontVariant

شكل خط مفقود

السبب. عائلة خط مخصصة ليس لها ملف لوزن أو نمط يستعمله المستند، كالمائل أو العريض.

الحل. ارفع شكل الخط المفقود أو عرّفه، أو كفّ عن استعمال ذلك الوزن أو النمط. التوثيق →

  • إن حمّلت خطًّا بنفسك، فإن document.fonts.load(font) من غير نص عيّنة لا تحمّل إلا الملف الذي يغطي المسافة، أي ملف latin، فيعود ż وř إلى خط من خطوط النظام. أما prepareFonts فتمرّر حروف المستند نفسه.
  • تقصّ renderPageToCanvas وpostext-pdf كل عمود بعد حافته بنقطتين، فيفقد السطر المقيس بخط احتياطي أضيق حروفه الأخيرة. والبناء الذي قاسه يذكر الخط في doc.contentWarnings باسم fontFallback: اقرأ تلك القائمة قبل أن تعرض صفحة أو تصدّرها.

الحقوق

الوصفة
Ignacio Ferro
النص
نص أصلي, CC BY 4.0
الخطوط
Ysabeau Office (SIL OFL 1.1) · Noto Serif Display (SIL OFL 1.1) · IBM Plex Mono (SIL OFL 1.1)
الشيفرة
MIT، مثل Postext
Sandbox