باختصار
أربع صفحات من معجم صيني قديم. تُظهر الزاوية العليا لكل صفحة أول مدخل فيها وآخره، فيجد القارئ الكلمة وهو يقلّب الصفحات.
ما الذي ستنضده
أربع صفحات من وسط طبعة قرائية لمعجم كانغشي (康熙字典، سنة 1716)، أُعيد ترتيبها بحسب البينيين من 天 tiān إلى 庭 tíng. يقف كل مدخل بخط Song Black أحمر وفوقه نطقه بالبينيين؛ وتليه في فقرة واحدة قراءات كتب القوافي (反切) والمعاني، والمعاني مرقّمة ① ② بالأحمر نفسه. مقاس الصفحة 大32开، أي 140 × 203 مم، فيها عمودان بعرض 17 حرفًا بحجم 小五 (9 نقاط) على شبكة من 31 سطرًا، وكل عمود ممتلئ حتى سطره الأخير. وفي الزاوية الخارجية لكل صفحة تذكر الترويسة أول مدخل وآخر مدخل فيها، فالقارئ الذي يبحث عن 蜩 يقصد الصفحة التي ترويستها 腆—髫. وقارِنه بمعجم بالحروف اللاتينية هو The Sailor’s Word-Book.
تجيب هذه الوصفة عن
- كيف أطبع أول مدخل وآخر مدخل في كل صفحة في ترويسة قاموس؟
- كيف أضيف البينيين فوق الحروف الصينية؟
- كيف أُدخل الحروف الصينية في ملف PDF من دون مربعات فارغة؟
الجواب المختصر
// Each headword is a level-2 heading, '## {天|tiān}'. {firstMark.h2} prints the text of the
// first one that starts on the page, without its reading, and {lastMark.h2} the last; a
// page on which none starts repeats the one in force. They stand at the outer corner, the
// folio outside them, over a hairline as wide as the type area.
const HEAD_Y = 11; // mm from the top edge to the top of the guide words
const [GUIDE, FOLIO] = [10.5, 8]; // pt
const head = (id, content, parity, x, size, extra) => ({ kind: 'text', id, content, parity,
fontFamily: HEI, fontWeight: 700, fontSize: pt(size), lineHeight: 1, color: col('ink'),
// A design line puts its baseline 0.8 of its height down: the folio drops to share it.
placement: { anchor: { to: 'page', edge: parity === 'even' ? 'top-left' : 'top-right' },
offset: { x: mm(parity === 'even' ? x : -x), y: mm(HEAD_Y + 0.8 * (GUIDE - size) * PT) } },
...extra });
const folio = { color: col('muted') };
const guideWords = [
head('verso-folio', '{pageNumber}', 'even', SIDE, FOLIO, folio),
head('verso-guide', '{firstMark.h2}—{lastMark.h2}', 'even', SIDE + 8, GUIDE),
head('recto-guide', '{firstMark.h2}—{lastMark.h2}', 'odd', SIDE + 8, GUIDE),
head('recto-folio', '{pageNumber}', 'odd', SIDE, FOLIO, folio),
{ kind: 'rule', id: 'hairline', direction: 'horizontal', thickness: pt(0.5), color: col('ink'),
placement: { anchor: { to: 'page', edge: 'top-left' },
offset: { x: mm(SIDE), y: mm(HEAD_Y + 5.5) }, size: { width: mm(AREA.width) } } },
];
المكونات
- الميزات
- كلمات الدليل في الترويساتقراءات ruby: pinyin وzhuyinشبكة المحارفعمود واحد أو عمودانالخط الفاصل بين الأعمدةموازنة الأعمدةالخطوط الصينية واليابانية والكوريةتقسيم الأسطر في النص الصينيعروض علامات الترقيم الصينيةالضبط بالتباعد بين المحارفالترويسات وأرقام الصفحاتأشرطة النزف وألسنة الإبهامتثبيت عناصر التصميمالغامق والمائل وألوانهماأنماط الفقراتهوامش متناظرةلوحة ألوان دلاليةالتصدير إلى PDF
- الخطوط
- Noto Serif TC, Noto Sans TC, LXGW WenKai TC (SIL OFL 1.1)
- الأصول
- لا شيء: كل صورة مرسومة بالشيفرة
طريقة التحضير
#1 · كلمات إرشادية من المداخل
الشيفرة هي الجواب المختصر أعلاه. كل مدخل عنوان من المستوى 2، ويطبع {firstMark.h2} و{lastMark.h2} نص أول عنوان وآخر عنوان من المستوى 2 يبدآن على الصفحة (العناصر النصية). والعلامة هي حروف العنوان: ## {天|tiān} يُعلِّم 天، ويبقى النطق فوق المدخل. والمدخل الذي يمتد من صفحة إلى التالية لا يُحسب إلا حيث يقف عنوانه: الصفحة 635 تبدأ بنهاية 殄 وترويستها 腆—髫. أما المستوى 1 فمحفوظ للحروف: لا يبدأ أي حرف في هذه الصفحات الأربع، لكن عنوان الحرف لا يُحسب كلمة إرشادية.
#2 · البينيين فوق المداخل
// A heading with no design of its own keeps its reading: '## {天|tiān}' sets tiān over 天.
// Two grid lines hold the headword and a 7.5 pt reading, so every entry stays on the grid.
// A Latin reading stands clear of its base by its descenders: the g of tīng stays off 汀.
const cjk = {
grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
// The regular Song, not the heading's Black: a reading takes the face of its base.
ruby: { fontFamily: SONG, fontSize: em(0.5), color: col('cinnabar') },
};
const headword = { level: 2, fontSize: pt(15), lineHeight: pt(2 * LEAD), marginTop: pt(0),
marginBottom: pt(0) };
{天|tiān} هو الشكل المختصر لـ:ruby[天]{rt="tiān"}، قراءة واحدة فوق حرف واحد (علامات الصينية والروبي والواريتشو). والعنوان الذي لا تصميم خاصًّا له ينضّد قراءته؛ أما العنوان ذو التصميم فسيطبع 天 وحده. وتأخذ القراءة شكل خط العنوان نفسه، Black، ما لم تحدّد cjk.ruby.fontFamily خطًّا آخر، ولذلك حُدّد خط Song العادي. ونصف 15 نقطة هو 7.5 نقاط، ويترك سطر العنوان البالغ 30 نقطة مكانًا لها فوق المدخل، فيشغل العنوان سطرين من الشبكة ويبقى النص تحته على أسطر 15 نقطة في العمودين كليهما. وتُرفع قراءة البينيين بمقدار عمق النوازل في خطها وزيادة 0.04 em، فينتهي حرف g في tīng على بعد 0.6 نقطة فوق مربع الـem للحرف 汀.
#3 · فقرة واحدة لكل مدخل
// As the Kangxi Dictionary sets an entry: the rhyme-book readings (反切), then the senses
// run in, each after its number. '**②**' marks a number, and the text prints its bold in
// cinnabar: the only bold on these pages. A circled number is a Chinese character to the
// composer: no line ends on one, away from the sense it opens, and no space follows it.
const bodyText = { fontFamily: SONG, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
boldColor: col('cinnabar'), italicColor: col('ink'), referenceColor: col('ink'),
textAlign: 'justify', firstLineIndent: pt(0) }; // no indent: the headword opens the entry
يسرد معجم كانغشي المدخل متصلًا: قراءات كتب القوافي، ثم كل معنى تسبقه 又. وهنا صارت 又 أرقامًا في دوائر، مكتوبة على هيئة **②**، ويطبعها boldColor بلون الزنجفر الذي للمداخل؛ ولا عريض غيرها في النص. والمعنى الذي يقرؤه كانغشي قراءة أخرى يحتفظ بقراءته، كما في 跳 ② مع 徒刀切. وينضّد المنضّد الأرقام من ① إلى ⑳ على أنها حروف صينية: فلا ينتهي سطر برقم يبدأ معناه في السطر التالي، ولا تدخل المسافة بين الحروف الصينية واللاتينية بين الرقم ونصه، فتُكتب الأرقام كما هي. وموازنة الأعمدة معطّلة (headings.balancing.enabled: false)، فلا يفتح أي عمود فراغًا فوق مداخله، ويتلو كل مدخل سابقه على المسافة نفسها.
#4 · علامة الإبهام للحرف T
const INITIALS = 'ABCDEFGHJKLMNOPQRSTWXYZ'; // no pinyin syllable starts with I, U or V
const STEP = AREA.height / INITIALS.length; // mm: 7.13, the 23 tabs fill the type area's height
const tab = (parity) => {
const edge = parity === 'odd' ? 'top-right' : 'top-left'; // the fore-edge
const at = (x, width) => ({ anchor: { to: 'page', edge },
offset: { x: mm(parity === 'odd' ? x : -x), y: mm(TOP + INITIALS.indexOf('T') * STEP + 0.3) },
size: { width: mm(width), height: mm(STEP - 0.6) } });
// 6 mm inside the trim and 3 mm past it: the page cuts the tab square at the fore-edge
// (a print file with cutLines prints the 3 mm in its bleed); the letter on the 6 mm.
return [
{ kind: 'box', id: `tab-${parity}`, parity, placement: at(3, 9),
style: { backgroundColor: col('cinnabar'), borderRadius: mm(1.2) } },
{ kind: 'text', id: `tab-letter-${parity}`, parity, content: 'T', fontFamily: HEI,
fontWeight: 700, fontSize: pt(9), lineHeight: 1, color: col('paper'), align: 'center',
verticalAlign: 'middle', placement: at(0, 6) },
];
};
تبدأ مقاطع البينيين بـ23 حرفًا من الحروف الستة والعشرين (لا شيء يبدأ بـI أو U أو V)، فيُقسم ارتفاع منطقة الطباعة إلى 23 خطوة من 7.13 مم، ويأخذ T الخطوة التاسعة عشرة. عرض العلامة 9 مم وتبدأ على بعد 3 مم خارج حدّ القص، فتقصّها الصفحة مربعةً عند الحافة الأمامية ولا يظهر التدوير إلا في زاويتيها الداخليتين؛ وملف الطباعة الذي فيه page.cutLines سيُبقي هذه المليمترات الثلاثة في منطقة نزفه. ويُوسَّط الحرف على المليمترات الستة التي داخل الصفحة. والصفحات الأربع كلها في حرف T، فتبقى العلامة على الارتفاع نفسه؛ أما the Sailor’s Word-Book فينقلها على الحافة نزولًا من حرف إلى الذي يليه.
#5 · كل وجه يحمّل حروفه
// Fontsource cuts a Chinese face into about a hundred files (gotcha: cjk-fonts-slices).
// The regular Song sets the whole sample; each other voice gets only its own text.
const all = (re) => [...markdown.matchAll(re)].map((m) => m[1]).join('');
const heads = all(/^## \{(.+?)\|/gm);
await loadFonts(FONTS, markdown);
await loadCjkFonts({ [SONG]: ['400'] }, markdown);
await loadCjkFonts({ [SONG]: ['700'] }, all(/\*\*(.+?)\*\*/g));
await loadCjkFonts({ [SONG]: ['900'] }, heads);
await loadCjkFonts({ [HEI]: ['700'] }, `${heads}—0123456789T`);
await loadCjkFonts({ [KAI]: ['400'] }, all(/style="colophon-zh"\}\n(.+)\n/g));
يقطّع Fontsource كل وجه صيني إلى نحو مئة ملف بحسب نطاقات الحروف، ويحمّل loadCjkFonts الملفات التي تضم النص المعطى له. يأخذ خط Song العادي النموذج كله، ومنه النص الإنجليزي في بيانات الطبع. ويأخذ Black المداخل الثلاثين، والوزن العريض أرقام المعاني، وHei المداخل وأرقام الترويسات، وKai الجملة الصينية في بيانات الطبع. ويضمّن cjkPdfProvider الملفات نفسها في ملف PDF، كلًّا منها مقلّصًا إلى الحروف التي تستعملها صفحاته.
الوصفة كاملة
// ═══ Postext Cookbook · Nº 086 · A Chinese dictionary page with guide words ═════════
// https://postext.dev/en/cookbook/chinese-dictionary-page
// Code: MIT · Text: 康熙字典 (1716), Wikisource transcription, CC BY-SA 4.0 · Pinyin: CC BY 4.0
// Fonts: Noto Serif TC, Noto Sans TC, LXGW WenKai TC (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import { buildDocument, withLoadedFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'chinese-dictionary-page';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: black and one cinnabar, the second ink of a two-colour dictionary
const palette = {
ink: '#1f1b17', // text, guide words
cinnabar: '#a52f28', // headwords, their readings, sense numbers, the thumb tab
rule: '#bab2a4', // the column rule
muted: '#5c554d', // folios, colophon
paper: '#fbf8f2', // the page, and the letter reversed out of the tab
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at the cinnabar.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.cinnabar })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [SONG, HEI, KAI] = ['Noto Serif TC', 'Noto Sans TC', 'LXGW WenKai TC'];
const PT = 25.4 / 72; // mm in a point
const [BODY, LEAD] = [9, 15]; // pt: 小五 on a 15 pt line, the grid both columns share
const [CHARS, LINES] = [17, 31]; // characters to a column's line, lines to a column
const TRIM = { width: 140, height: 203 }; // mm: 大32开
const MIN = { top: 20, bottom: 16, side: 12 }; // mm: minimums the grid grows to centre the area
// The type area the grid sets (two columns and a 2-em gutter) and the margins it leaves.
const AREA = { width: (2 * CHARS + 2) * BODY * PT, height: LINES * LEAD * PT }; // 114.3 × 164
const SIDE = (TRIM.width - AREA.width) / 2; // 12.85 mm
const TOP = MIN.top + (TRIM.height - MIN.top - MIN.bottom - AREA.height) / 2; // 21.5 mm
// #region answer: the first and the last headword of each page in its running head
// Each headword is a level-2 heading, '## {天|tiān}'. {firstMark.h2} prints the text of the
// first one that starts on the page, without its reading, and {lastMark.h2} the last; a
// page on which none starts repeats the one in force. They stand at the outer corner, the
// folio outside them, over a hairline as wide as the type area.
const HEAD_Y = 11; // mm from the top edge to the top of the guide words
const [GUIDE, FOLIO] = [10.5, 8]; // pt
const head = (id, content, parity, x, size, extra) => ({ kind: 'text', id, content, parity,
fontFamily: HEI, fontWeight: 700, fontSize: pt(size), lineHeight: 1, color: col('ink'),
// A design line puts its baseline 0.8 of its height down: the folio drops to share it.
placement: { anchor: { to: 'page', edge: parity === 'even' ? 'top-left' : 'top-right' },
offset: { x: mm(parity === 'even' ? x : -x), y: mm(HEAD_Y + 0.8 * (GUIDE - size) * PT) } },
...extra });
يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)
تنويعات
#أول مدخل على الصفحة الزوجية وآخر مدخل على الفردية
تطبع بعض المعاجم كلمة إرشادية واحدة لكل صفحة، الأولى في أعلى الصفحة الزوجية والأخيرة في أعلى الفردية، فتُقرأ الصفحتان المتقابلتان 天 … 髫.
- head('verso-guide', '{firstMark.h2}—{lastMark.h2}', 'even', SIDE + 8, GUIDE),
- head('recto-guide', '{firstMark.h2}—{lastMark.h2}', 'odd', SIDE + 8, GUIDE),
+ head('verso-guide', '{firstMark.h2}', 'even', SIDE + 8, GUIDE),
+ head('recto-guide', '{lastMark.h2}', 'odd', SIDE + 8, GUIDE),#البينيين بـɑ وɡ
تنضّد المعاجم الصينية البينيين بوجه فيه a وg بطابق واحد. سمِّ Andika للقراءات وأضفه إلى FONTS ('Andika': ['400']، مع حقوق رخصة OFL الخاصة به).
- ruby: { fontFamily: SONG, fontSize: em(0.5), color: col('cinnabar') },
+ ruby: { fontFamily: 'Andika', fontSize: em(0.5), color: col('cinnabar') },#مداخل بحجم النص
ينضّد المعجم المختصر المدخل بالعريض في أول فقرته. ضع المداخل في :::paragraphs{style="entry"}، وابدأ كلًّا منها بـ**{天|tiān}**، واطبع {firstMark.entry}: الفقرة التي تبدأ بمقطع عريض تُعلِّم الصفحة به.
أخطاء شائعة
خطأ شائع
القراءات تُطبع في النص، لا في التصاميم ولا في التعليقات ولا في الخلايا
تُرسَم قراءات ruby في الفقرات والعناوين وبنود القوائم والاقتباسات والإطارات. أما عنصر نص التصميم (افتتاحية، ترويسة، شارة)، والتعليق، والحاشية السفلية، وخلية الجدول، فتطبع الحروف الأساسية دون قراءاتها. العنوان الذي يحتاج إلى pinyin الخاص به عنوانٌ بلا تصميم خاص به: ارسم ما يحيط به (شريط، رقم الدرس) بتصميم العنوان الذي قبله، الذي تُرسَم عناصره ذات reserve: false تحت نص افتتاحية span: 'page'. قراءات ruby: pinyin وzhuyin →
خطأ شائع
الخطوط الصينية تُحمَّل شرائح، عبر الكتلة cjk
يقدّم Fontsource العائلة الصينية أو اليابانية أو الكورية في نحو مئة ملف لكل وزن، يغطي كل منها نطاقًا من الحروف. لا يجلب loadFonts إلا ملف latin، فتأتي حروف الهان على الشاشة من خط النظام وتُقاس خطأً، ويسلّم fontsourceProvider ملف latin ذاك إلى PDF، فيطبعها مربعات فارغة. اذكر كتلة الأدوات cjk، واستدعِ loadCjkFonts(FONTS, markdown) بعد loadFonts (مرة لكل صوت، مع النص الذي يضعه، حين يستخدم الكتاب عدة خطوط CJK)، وأعطِ renderToPdf القيمة fontProvider: cjkPdfProvider: كلاهما يأخذ الملفات التي تحتوي حروف النص. الخطوط الصينية واليابانية والكورية →
خطأ شائع
اوسم المستند بـ zh-Hans أو zh-Hant، لا بـ LANG
نسختا الوصفة هما en وes، لكن المثال الصيني صيني في كلتيهما: `locale: LANG` سيسمه بالإنجليزية أو الإسبانية، فيقسّم كلماته اللاتينية بالواصلة، ويسمّي أشكاله Figure أو Figura، ويعطي PDF لغة خاطئة. ومنذ postext 1.30 صار الوسم أيضًا اللغة التي يُشكَّل بها النص (يُقاس ويُرسم ويُضمَّن بها)، فتحت وسم إنجليزي أو إسباني يصفّ الخط الصيني أرقامه وعلامات الترقيم التي يشترك فيها مع النص اللاتيني بأشكال أخرى، وتنكسر الأسطر في مواضع أخرى. اكتب الوسم بنفسك: 'zh-Hans' (أعراف البر الرئيسي: كسر الأسطر وفق GB، وترقيم Kaiming) أو 'zh-Hant' (تايوان: ترقيم بعرض كامل متمركز)؛ و'zh-HK' لهونغ كونغ. أما 'zh' المجرّد فيُقرأ صينية مبسطة على أعراف البر الرئيسي. أما المثال الياباني فيُوسم بـ 'ja' (gotcha ja-locale-tag). تقسيم الأسطر في النص الصيني →
- إذا فُعّلت موازنة الأعمدة، فإن العمود الذي لا يتسع للمدخل التالي مع سطرين من نصه تحته (
bodyText.widowMinLines) ينتهي مبكرًا، وتذهب الأسطر الفائضة فوق المداخل، سطرًا واحدًا لكل منها على الأكثر: فيقف مدخل على بعد سطر من سابقه، ولا يقف التالي كذلك. وإذا عُطّلت، انتهى هذا العمود قصيرًا.
الحقوق
- الوصفة
- Ignacio Ferro
- النص
- Thirty entries of the Kangxi Dictionary (康熙字典, 1716), 天 to 庭, each cut to a few senses: what is kept stands in the source’s order and under its attribution, a sense with a reading of its own keeps it, and of the ancient forms (古文) only 銕 is set, the others being outside the fonts. Variant forms are written in today’s standard Traditional characters and the punctuation is revised in places. From the zh.wikisource transcription, which gives the Siku Quanshu Huiyao copy (四庫全書薈要本) as its source and notes some of Wang Yinzhi’s corrections of 1831 (字典考證); 29 pages by radical and stroke count, revisions read on 29 September 2026: 大部 2535754, 水部/八畫 2542298, 田部 2543683, 心部/六畫 2537571, 土部/十畫 2535684, 門部/十畫 2553837, 心部/四畫 2537569, 歹部/五畫 2541608, 肉部/八畫 2549900, 人部/六畫 416510, 手部/六畫 2538445, 辵部/五畫 2553283, 木部/七畫 2540094, 虫部/八畫 2551174, 言部/八畫 2551690, 髟部/五畫 2556393, 穴部/六畫 2546633, 目部/六畫 2544863, 足部/六畫 2552906, 米部/十九畫 2548884, 巾部/五畫 2536199, 貝部/五畫 2552278, 金部/十三畫 2553630, 食部/九畫 2556072, 水部/二畫 2541898, 耳部/十六畫 2549782, 广部/二十二畫 2536291, 亠部/七畫 409671, 广部/七畫 2536277 · Zhang Yushu, Chen Tingjing and others (1716); transcription by Wikisource editors · CC BY-SA 4.0
- The pinyin readings, the sense numbers, the order of the entries and the colophon · Postext Cookbook · CC BY 4.0
- الخطوط
- Noto Serif TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1)
- الشيفرة
- MIT، مثل Postext
حرّر هذا الشرح ↗ (يفتح في تبويب جديد)مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)


