باختصار
صفحة عربية وصفحة يابانية جنبًا إلى جنب، على كل منهما التصحيحات الأربعة نفسها: تظليل، وكلمة مشطوبة، وكلمة مستبدَلة، وملاحظة. تحت كل صفحة قائمة تذكر عدد قطع كل علامة واتجاهها.
ما الذي ستنضده
صفحتان جنبًا إلى جنب، كل منهما في عارض صفحات: صفحة عربية عن ورشة مجلِّد كتب، منضَّدة من اليمين إلى اليسار بخط Noto Naskh Arabic، وصفحة يابانية بقطع الجيب عن مصلح ساعات، بأعمدة عمودية بخط Noto Serif JP. على كل منهما العلامات الأربع نفسها التي تتركها أداة مراجعة: تظليل، وحذف، واستبدال، وملاحظة مرقّمة. في الصفحة العربية يُقرأ نص الاستبدال من اليمين إلى اليسار فوق الكلمات المشطوبة؛ وفي الصفحة اليابانية ينزل خط الشطب في منتصف العمود ويقف نص الاستبدال منتصبًا بجانبه. تحت كل صفحة قائمة تذكر قطع كل علامة واتجاه أولاها.
تجيب هذه الوصفة عن
- كيف أضع علامات على النص في الصفحات المكتوبة من اليمين إلى اليسار والصفحات العمودية؟
الجواب المختصر
// layoutAnnotations follows the page's lines: a strike crosses a vertical column down its
// middle, a replacement's text reads right to left on the Arabic page and stands upright on
// the Japanese one, and a note's flag goes to the nearer margin, the foot of a vertical page.
const show = (id, doc, marks, fontFamily) => {
const shapes = layoutAnnotations(doc, marks, { fontFamily, paper: palette.paper });
createViewer(document.getElementById(id), {
document: doc, zoom: 'fit-page', gap: 16, selectable: false, labels: labels.viewer,
// A layer paints on the page in sheet px, the unit the shapes are in.
layers: [{ id: 'marks', paint: (ctx, { pageIndex }) =>
paintAnnotations(ctx, shapes, { pageIndex }) }],
});
};
show('arabic', arabicDoc, arabicMarks, NASKH);
show('japanese', japaneseDoc, japaneseMarks, MINCHO);
المكونات
- الميزات
- علامات التعليقهندسة النص (النطاقات والنقاط)عارض الصفحات (postext-viewer)النص من اليمين إلى اليسارالعربية لغةً للمستندالخطوط العربيةالنص العموديالخطوط الصينية واليابانية والكوريةالخطوط قبل الإخراجلون الورقلوحة ألوان دلالية
- الخطوط
- Noto Naskh Arabic, Noto Serif JP (SIL OFL 1.1)
- الأصول
- لا شيء: كل صورة مرسومة بالشيفرة
طريقة التحضير
#1 · أعطِ كل صفحة اتجاه كتابتها
// 'ja' with 'vertical-rl' sets each line top to bottom and the lines from right to left; 'ar'
// sets the text right to left. Nothing in the marks' code changes with either.
const config = { // the Japanese page
locale: 'ja', // written out, never LANG (gotcha: ja-locale-tag)
colorPalette, header: none, footer: none,
page: { sizePreset: 'custom', width: mm(105), height: mm(148), dpi: 200, // 文庫判
backgroundColor: col('paper'),
margins: { top: mm(15), bottom: mm(12), left: mm(11), right: mm(11) } },
layout: { layoutType: 'single', writingMode: 'vertical-rl' },
bodyText: { fontFamily: MINCHO, fontSize: pt(9.5), lineHeight: pt(16.5), ...ink,
textAlign: 'justify', firstLineIndent: em(1), indentAfterHeading: true },
headings: { fontFamily: MINCHO, fontWeight: 600, color: col('vermilion'), levels: [
{ level: 1, fontSize: pt(13), lineSpan: 3, indent: em(2) }, // 3行取り, two characters down
] },
};
const arabic = { ...config, // the Arabic page: its own language, trim, face and mode
locale: 'ar', // written out, never LANG (gotcha: arabic-locale-tag)
page: { ...config.page, width: mm(120), height: mm(170), dpi: 150,
margins: { top: mm(18), bottom: mm(18), left: mm(16), right: mm(16) } },
layout: { layoutType: 'single' },
bodyText: { fontFamily: NASKH, fontSize: pt(12.5), lineHeight: pt(21), ...ink,
textAlign: 'justify', firstLineIndent: em(1.5), indentAfterHeading: false,
avoidWidows: true, avoidOrphans: true },
headings: { fontFamily: NASKH, fontWeight: 700, color: col('accent'), levels: [
{ level: 1, fontSize: pt(18), lineHeight: pt(28), marginTop: pt(0), marginBottom: pt(14) },
] },
};
الصفحة اليابانية هي الإعداد نفسه، ومعها writingMode: 'vertical-rl'؛ والعربية تبسطه وتغيّر اللغة والقطع والخط. يجعل locale: 'ar' النص يجري من اليمين إلى اليسار. ولا تسأل شيفرة العلامات بعد ذلك أبدًا على أي صفحة ترسم.
#2 · اكتب العلامات بالطريقة نفسها للصفحتين
// A mark is a range of the Markdown. `find` gives the range of a phrase that occurs once.
const find = (text, words) => ({ start: text.indexOf(words),
end: text.indexOf(words) + words.length });
const marksOn = (text, [lit, cut, [was, now], noted]) => [
{ id: 'h', kind: 'highlight', range: find(text, lit) },
{ id: 's', kind: 'strike', range: find(text, cut) },
{ id: 'r', kind: 'replace', range: find(text, was), text: now },
{ id: 'n', kind: 'note', range: find(text, noted), label: '1' },
];
const arabicMarks = marksOn(arabicText,
['أربعين سنة', 'صغيرة', ['خشب الجوز', 'خشب الزان'], 'بورق ياباني رقيق']);
const japaneseMarks = marksOn(markdown, ['七十八歳', '一つずつ', ['丸一日', '二日'], '洗浄液']);
العلامة نطاق من نص Markdown، فتخرج القائمتان العربية واليابانية من الدالة نفسها، بأربع عبارات لكل منهما. نص الاستبدال بلغة الصفحة، والخطوط تحمّل حروفه أيضًا، وإلا عرضه المتصفح بخط احتياطي.
#3 · ضع العلامات وارسمها فوق كل صفحة
الشيفرة هي الجواب المختصر أعلاه. تضع layoutAnnotations كل علامة بحسب أسطر الصفحة نفسها: في الصفحة العمودية يقطع الشطب العمود من منتصفه، والتظليل الذي ينقسم عند نهاية عمود يعطي قطعتين، وتذهب راية الملاحظة إلى أسفل الصفحة. يرسم العارض الصفحة، وتتلقى طبقته سياقًا بوحدات px الورقة، وهي وحدة الأشكال، فترسمها paintAnnotations كما هي. تصف وثائق علامات التعليق كل الأنواع.
#4 · اقرأ اتجاه سير النص
// A quad runs in the line's own order, quad[0] to quad[1]: leftwards on the Arabic page,
// downwards on the Japanese one. A range broken across two lines or columns gives two pieces.
const way = ([a, b]) => (Math.abs(b.x - a.x) > Math.abs(b.y - a.y)
? (b.x < a.x ? '←' : '→') : (b.y > a.y ? '↓' : '↑'));
const list = (id, doc, text, marks) => document.getElementById(id).replaceChildren(
...marks.map((m) => {
const pieces = rangeRects(doc, m.range);
const [li, words] = [document.createElement('li'), document.createElement('bdi')];
words.textContent = text.slice(m.range.start, m.range.end); // its own direction
li.append(`${labels.kinds[m.id]} · `, words, ` · ${pieces.length} `
+ `${labels.pieces[pieces.length === 1 ? 0 : 1]} ${way(pieces[0].quad)}`);
return li;
}));
list('arabic-pieces', arabicDoc, arabicText, arabicMarks);
list('japanese-pieces', japaneseDoc, markdown, japaneseMarks);
تعطي rangeRects قطعة لكل مقطع من السطر، ويحفظ quad الخاص بها ترتيب السطر: من quad[0] إلى quad[1] يتجه يسارًا في الصفحة العربية وإلى أسفل في اليابانية. والموقع الذي يرسم خط تسطير خاصًّا به أو دبوس تعليق يأخذ الاتجاه من هنا، بدل أن يخمّنه من اللغة.
الوصفة كاملة
// ═══ Postext Cookbook · Nº 222 · The same marks on right-to-left and vertical pages ═════
// https://postext.dev/en/cookbook/marks-on-rtl-and-vertical-pages
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Noto Naskh Arabic, Noto Serif JP (SIL OFL 1.1) · Needs postext ≥ 1.103.0
//
// An Arabic page set right to left and a Japanese page set in vertical columns, each in
// postext-viewer, each with the same four marks: a highlight, a deletion, a replacement and a
// note. The host writes the marks the same way for both, as ranges of the Markdown; the
// engine turns them to follow each page's lines, and a list under each page says how.
import {
buildDocument, withLoadedFonts, renderPageToCanvas, loadVerticalAlternates, rangeRects,
} from 'https://esm.sh/postext';
import { layoutAnnotations, paintAnnotations } from 'https://esm.sh/postext/annotate';
import { createViewer } from 'https://esm.sh/postext-viewer';
const LANG = 'en'; // @lang: the language of the labels; both pages are the same in each edition
const RECIPE = 'marks-on-rtl-and-vertical-pages';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink on a warm paper, one accent per page, every colour linked by id
const palette = {
ink: '#1e1b18', // text
accent: '#2b4766', // the Arabic title's blue
vermilion: '#a8392b', // 朱: the Japanese title
paper: '#fbf8f1', // a cream book paper
};
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' } },
];
// #endregion
const [NASKH, MINCHO] = ['Noto Naskh Arabic', 'Noto Serif JP'];
const ink = { color: col('ink'), boldColor: col('ink'), italicColor: col('ink'),
referenceColor: col('ink') };
const none = { elements: [] }; // one page each: no running heads
// #region pages: writingMode turns the Japanese lines; the locale sets the Arabic direction
// 'ja' with 'vertical-rl' sets each line top to bottom and the lines from right to left; 'ar'
// sets the text right to left. Nothing in the marks' code changes with either.
const config = { // the Japanese page
locale: 'ja', // written out, never LANG (gotcha: ja-locale-tag)
colorPalette, header: none, footer: none,
page: { sizePreset: 'custom', width: mm(105), height: mm(148), dpi: 200, // 文庫判
backgroundColor: col('paper'),
margins: { top: mm(15), bottom: mm(12), left: mm(11), right: mm(11) } },
layout: { layoutType: 'single', writingMode: 'vertical-rl' },
bodyText: { fontFamily: MINCHO, fontSize: pt(9.5), lineHeight: pt(16.5), ...ink,
<main id="pages">
<section id="pair">
<figure>
<figcaption id="arabic-label"></figcaption>
<div id="arabic" class="sheet"></div>
<ul id="arabic-pieces" class="pieces"></ul>
</figure>
<figure>
<figcaption id="japanese-label"></figcaption>
<div id="japanese" class="sheet"></div>
<ul id="japanese-pieces" class="pieces"></ul>
</figure>
</section>
</main>
/* Two viewers side by side, each fitted to its one page, with the host's list under it.
A viewer fills its container, so each container gets a height. */
#pair {
display: flex; flex-wrap: wrap; gap: 24px; justify-content: center; align-content: start;
width: min(880px, 100%); min-height: min(660px, 75vw); /* the card's 4:3 */
}
#pair figure { margin: 0; flex: 1 1 380px; display: grid; gap: 10px; align-content: start; }
#pair figcaption {
font: 600 12px/1.2 system-ui, sans-serif; letter-spacing: .12em; text-transform: uppercase;
color: #b9bcc4; text-align: center;
}
.sheet { height: 520px; border-radius: 6px; overflow: hidden; }
.sheet .postext-viewer {
--pv-background: #16181d;
--pv-page-shadow: 0 1px 2px rgb(0 0 0 / .5), 0 14px 32px -14px rgb(0 0 0 / .8);
--pv-focus: #d8a21a;
}
.pieces {
margin: 0; padding: 0; list-style: none; display: grid; gap: 2px;
font: 13px/1.45 system-ui, sans-serif; color: #d9dbe0; text-align: center;
font-variant-numeric: tabular-nums;
}
يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)
تنويعات
#دع العارض يضع العلامات
يقوم الخيار annotations في العارض بالوضع والرسم نفسيهما، ويسمّي كذلك كل علامة لقارئات الشاشة ويُبلغ عنها في annotationclick.
- const shapes = layoutAnnotations(doc, marks, { fontFamily, paper: palette.paper });
createViewer(document.getElementById(id), {
document: doc, zoom: 'fit-page', gap: 16, selectable: false, labels: labels.viewer,
- // A layer paints on the page in sheet px, the unit the shapes are in.
- layers: [{ id: 'marks', paint: (ctx, { pageIndex }) =>
- paintAnnotations(ctx, shapes, { pageIndex }) }],
+ annotations: marks, marks: { fontFamily, paper: palette.paper }, // named for readers too
});#انضد رواية عمودية كاملة
رواية جيب يابانية بالكتابة العمودية، مع الفوريغانا تنضد كتابًا يابانيًا على الصفحة نفسها، مع الروبي وشبكة الحروف والترويسات على طول الهامش الخارجي.
أخطاء شائعة
خطأ شائع
اوسم الكتاب العربي بـ 'ar'، لا بـ LANG
نسختا الوصفة هما en وes، لكن المثال العربي عربي في كلتيهما: `locale: LANG` سيجعله من اليسار إلى اليمين، ويجلّده على اليسار، ويرقّم صفحاته 1 2 3، ويسمّي أشكاله Figure أو Figura. ومنذ postext 1.30 صار الوسم أيضًا اللغة التي يُشكَّل بها النص (يُقاس ويُرسم ويُضمَّن بها)، فتحت وسم إنجليزي أو إسباني لا يرسم خط مثل Markazi Text الأشكال العربية لعلامتَي التنصيص « » وللنقطة، وتنكسر الأسطر في مواضع أخرى. اكتب الوسم بنفسك: 'ar' (الأرقام العربية المشرقية، عُرف المشرق)، أو منطقة مثل 'ar-EG' أو 'ar-SA'، أو 'ar-MA' أو 'ar-DZ' أو 'ar-TN' لنسخة مغاربية بالأرقام الأوروبية. أما الصفحة اللاتينية التي تقتبس العربية فقط فتحتفظ بلغتها. النص من اليمين إلى اليسار →
خطأ شائع
اوسم النص الياباني بـ 'ja'، لا بـ zh-Hans ولا بـ LANG
نسختا الوصفة هما en وes، لكن المثال الياباني ياباني في كلتيهما: `locale: LANG` سيسمه بالإنجليزية أو الإسبانية، والوسم الصيني سينضّده بالقواعد الصينية (ترقيم Kaiming، وكانا صغيرة يجوز أن تبدأ بها الأسطر، و图 بدل 図، وأشكال صينية للحروف في PDF). ومنذ postext 1.30 صار الوسم أيضًا اللغة التي يُشكَّل بها النص (يُقاس ويُرسم ويُضمَّن بها)، فكل وسم غير 'ja' يعطي أشكالًا للحروف غير اليابانية (الصينية منها مع وسم صيني) وكسرًا آخر للأسطر. اكتب 'ja': يختار منطقة اليابان (كسر الأسطر والترقيم وفق JLReq، ونقاط السمسم، وتوزيع الفوريغانا، وتسميتي 図 و表) ويوقف تقسيم الكلمات. ويُفشل الفحصُ نصًّا فيه كانا موسومًا بـ zh أو ko. كسر الأسطر الياباني (kinsoku) →
خطأ شائع
الخطوط العربية تحتاج إلى ملفها arabic، عبر الكتلة arabic
يقدّم Fontsource الخطوط Amiri وNoto Naskh Arabic وScheherazade New في ملف لكل مجموعة فرعية، والحروف العربية في ملف arabic. لا يجلب loadFonts إلا latin (وlatin-ext)، فيأتي النص العربي على الشاشة من خط النظام ويُقاس خطأً، ويسلّم fontsourceProvider ملف latin ذاك إلى PDF، فيطبع مربعات فارغة. اذكر كتلة الأدوات arabic، واستدعِ loadArabicFonts(FONTS, markdown) بعد loadFonts، مع ذكر كل وزن تضع به الصفحاتُ نصًا عربيًا في FONTS، وأعطِ renderToPdf القيمة fontProvider: arabicPdfProvider. الخطوط العربية →
خطأ شائع
الخطوط الصينية تُحمَّل شرائح، عبر الكتلة cjk
يقدّم Fontsource العائلة الصينية أو اليابانية أو الكورية في نحو مئة ملف لكل وزن، يغطي كل منها نطاقًا من الحروف. لا يجلب loadFonts إلا ملف latin، فتأتي حروف الهان على الشاشة من خط النظام وتُقاس خطأً، ويسلّم fontsourceProvider ملف latin ذاك إلى PDF، فيطبعها مربعات فارغة. اذكر كتلة الأدوات cjk، واستدعِ loadCjkFonts(FONTS, markdown) بعد loadFonts (مرة لكل صوت، مع النص الذي يضعه، حين يستخدم الكتاب عدة خطوط CJK)، وأعطِ renderToPdf القيمة fontProvider: cjkPdfProvider: كلاهما يأخذ الملفات التي تحتوي حروف النص. الخطوط الصينية واليابانية والكورية →
الحقوق
- الوصفة
- Ignacio Ferro
- النص
- نص أصلي, CC BY 4.0
- الخطوط
- Noto Naskh Arabic (SIL OFL 1.1) · Noto Serif JP (SIL OFL 1.1)
- الشيفرة
- MIT، مثل Postext
حرّر هذا الشرح ↗ (يفتح في تبويب جديد)مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)



