本文へスキップ
レシピ番号105

レシピ集 · 第2章 · 文字と本文

右から左へ組む右綴じのアラビア語小説

14 × 21 cmのページに組んだアラビア語小説の冒頭。ロケール'ar'で本文は右から左へ流れ、本は右綴じになり、ノンブルは١٢と印刷されます。

このページの内容
出力
Canvas · PDF
レベル
中級
Postext
Postext 1.65.0で検証済み
1.25.0以上が必要 · postext-pdf ≥ 1.25.0
ライセンス
2026年10月10日更新
コードMIT · 本文CC BY 4.0

١٠〜١١ページ · 1〜2/7

  • 英語の見本:日本語版はまだありません
  • 仕上がり140 × 210 mm
  • 1段
  • Markazi Text 13.5/22
  • Noto Kufi Arabic
  • Reem Kufi
  • 7ページ
  • レベル
  • Postext 1.57.1
  • 組版時間94 ms
  • コード161行

かんたんな説明

アラビア語で書かれた小説の最初の数ページを、アラブの出版社が刷るとおりに組んだ例です。行は右から左へ進み、本はラテン文字の読者にとっての裏表紙側から開き、ページ番号はアラビア数字で入ります。

できあがり

『حروف من رصاص』(鉛の文字)の冒頭です。カイロの路地で祖父の印刷所を再開する孫の物語で、アラブの並製本の体裁で組みます。判型14 × 21 cm、Markazi Textの13.5 ptを22 ptの行送りで、両端そろえ、字下げは右側です。抜粋は10ページ目から始まり、印刷所の扉の青で塗った部扉に、コードで描いた八芒星の格子模様と、64 ptのReem Kufiによる部の名前が入ります。章扉はその向かいの左ページにあり、章番号は言葉でالفصل الأولと書かれます。ノンブルは١٠、١١、١٢と刷られ、右ページの柱には書名、左ページの柱には章名が入ります。同じ種類の本を左から右へ組んだ例が並製本の小説です。

このレシピが答える質問

  • アラビア語の本を右から左に組み、右綴じにするには?

手短な答え

script.js · 35〜50行コード全体で見る
const page = {
  width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150, backgroundColor: col('paper'),
  // left and right are the flow's sides: in a right-to-left book left is the spine side,
  // so these margins put 20 mm at the spine and 16 mm outside on both pages of a spread.
  margins: { top: mm(23), bottom: mm(22), left: mm(20), right: mm(OUTER), mirror: true },
  // binding: 'auto' (unset) is 'right' for a right-to-left locale: page 1 is a left page.
};
const bodyText = {
  fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  // justify ends every line on both sides; the engine lengthens joined letters (kashida,
  // on by default for Arabic) after it opens the spaces a quarter. Never hyphenated.
  textAlign: 'justify', optimalLineBreaking: true,
  firstLineIndent: em(1.5), indentAfterHeading: false, // the indent is on the right
  avoidWidows: true, avoidOrphans: true, avoidRunts: true,
};

材料

種類
Markazi Text, Reem Kufi, Noto Kufi Arabic (SIL OFL 1.1)
素材
なし:画像はすべてコードで描画

作り方

#1 · ロケールひとつで3つが決まる

コードは上の手短な答えにあります。設定に書くのはlocale: 'ar'だけで、エンジンはそこから3つのことを決めます。本文は右から左へ流れ(direction: 'auto')、本は右綴じになり(page.binding: 'auto')、エンジンが書く数字はノンブルも含めてすべてアラビア・インド数字になります(numerals: 'auto')(アラビア語の本の始め方)。余白とそろえ位置にはleftとrightという語がそのまま残りますが、右から左の本ではそれぞれ流れの側を意味します。margins.leftは背の側で、字下げは右側に立ちます。両端そろえの行はまず語間を広げ、次につながった文字をタトウィール、つまりアラビア語の本のカシーダで伸ばします。本文がハイフネーションされることはありません(両端そろえとカシーダ)。

12ページ目。カシーダで広げた両端そろえの行、右側の字下げ、小口側のノンブル١٢。

#2 · 言葉で書く章番号

script.js · 54〜75行コード全体で見る
const SINK = 58; // mm: where the text starts on an opener
const centred = (y, size) => ({ anchor: { to: 'container', edge: 'top' },
  offset: { y: mm(y) }, ...(size && { size }) });
const opener = {
  enabled: true, minHeight: mm(SINK),
  slot: { elements: [
    { kind: 'image', id: 'star', resourceId: 'star', placement: centred(8, { width: mm(9) }) },
    // {number} is the level's numbering template below: الفصل الأول, الفصل الثاني…
    { kind: 'text', id: 'kicker', content: '{number}', fontFamily: LABEL, fontSize: pt(10),
      fontWeight: 600, color: col('door'), align: 'center', placement: centred(22) },
    { kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY, fontSize: pt(30),
      fontWeight: 600, lineHeight: 1.3, color: col('ink'), align: 'center', overflow: 'wrap',
      placement: centred(29, { width: 'fill' }) },
  ] },
};
const chapter = {
  level: 1, fontFamily: DISPLAY, fontWeight: 600, marginTop: pt(0), marginBottom: pt(0),
  // Each chapter opens a page, on either side of the spine.
  breakBefore: { enabled: true, parity: 'any' },
  // A masculine ordinal in words: {1:ordinal-feminine} would give الأولى, الثانية…
  numberingTemplate: 'الفصل {1:ordinal}', advancedDesign: opener,
};

見出しレベルのnumberingTemplateはالفصلと、男性形の序数で番号を書きます。2章目はMarkdownを変えずにالفصل الثانيになります。女性名詞、たとえばالليلةには{1:ordinal-feminine}がالأولى、الثانيةを出します(序数詞と基数詞)。章扉は{number}でこれを題の上に印刷します。アラビア語の章扉はふつう中央そろえなので、align: 'center'にしておけば、デザインがどちらの側から始まるかを考えずにすみます。

#3 · 柱は物理的な側にとどまる

script.js · 79〜96行コード全体で見る
// Running heads and folios keep their physical sides in a right-to-left book. The right page
// is an even page here and is read first: the book's title; the left page, the chapter's.
const label = { fontFamily: LABEL, fontSize: pt(8), color: col('muted'), pages: 'body' };
const at = (edge, x, y = 12) => ({ anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(y) } });
const folio = { ...label, fontWeight: 600, color: col('ink') };
const header = { elements: [
  { kind: 'text', id: 'r-folio', content: '{pageNumber}', parity: 'even', ...folio,
    align: 'right', placement: at('top-right', -OUTER) },
  { kind: 'text', id: 'r-title', content: '{title}', parity: 'even', ...label, align: 'right',
    placement: at('top-right', -(OUTER + 9)) },
  { kind: 'text', id: 'l-chapter', content: '{chapterTitle}', parity: 'odd', ...label,
    align: 'left', placement: at('top-left', OUTER + 9) },
  { kind: 'text', id: 'l-folio', content: '{pageNumber}', parity: 'odd', ...folio,
    align: 'left', placement: at('top-left', OUTER) },
] };
// The openers carry no head: their folio drops to the foot, centred.
const footer = { elements: [{ kind: 'text', id: 'drop-folio', content: '{pageNumber}', ...folio,
  pages: 'opener', align: 'center', placement: at('bottom', 0, -11) }] };

本文は流れに従いますが、柱とノンブルは物理的な左右を保ちます。この本では12ページ目が偶数ページかつ右ページなので、ノンブルは右上に入り、その横に書名が並びます。13ページ目は左にあり、章名を載せます。アラブの読者と同じく見開きを右から読めば、書名が先に来ます。showBookはページを鏡像に並べ、11ページ目を10ページ目の左に置くので、画面には本を開いたとおりの見開きが映ります。

#4 · コードで描く部扉

script.js · 100〜120行コード全体で見る
// # الدرب {style="plate" kicker="…" line="…"}: a heading that paints a whole page.
const onPage = (y) => ({ anchor: { to: 'page', edge: 'top' }, offset: { y: mm(y) } });
const plate = {
  id: 'plate', span: 'page', numbered: false, runningChapter: false, toc: false,
  breakBefore: { enabled: true, parity: 'any' }, // (gotcha: style-inherits-break)
  header: { elements: [] }, footer: { elements: [] },
  advancedDesign: { enabled: true, slot: { elements: [
    // The drawing carries 3 mm of bleed a side: a box of the trim would fit it by its width
    // and leave a strip of paper at the head and the foot.
    { kind: 'image', id: 'field', resourceId: 'lattice', placement: {
      anchor: { to: 'page', edge: 'top-left' }, offset: { x: mm(-3), y: mm(-3) },
      size: { width: mm(TRIM.width + 6), height: mm(TRIM.height + 6) } } },
    { kind: 'text', id: 'part', content: '{attr.kicker}', fontFamily: LABEL, fontSize: pt(11),
      fontWeight: 600, color: col('brass'), align: 'center', placement: onPage(76) },
    { kind: 'text', id: 'name', content: '{titleText}', fontFamily: DISPLAY, fontSize: pt(64),
      fontWeight: 600, lineHeight: 1.2, color: col('paper'), align: 'center',
      placement: onPage(86) },
    { kind: 'text', id: 'line', content: '{attr.line}', fontFamily: TEXT, fontSize: pt(13),
      color: col('paper'), align: 'center', placement: onPage(124) },
  ] } },
};

部扉は1レベルの見出し# الدرب {style="plate" …}で、そのスタイルが紙面全体を塗り、柱とノンブルを消します。格子模様はCodePenのサンプルの中で、45°回した2つの正方形から生成するSVGです。イスラームの幾何学文様のハータム星を、パレットの青と真鍮色で描くので、PDFにはベクターのパスとして残ります。numbered: falseで部扉は章の数に入らず、続く章扉はالفصل الأولになります。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 105 · An Arabic novel set right to left, bound on the right ═══
// https://postext.dev/en/cookbook/arabic-novel-right-bound
// Code: MIT · Text: original Arabic prose (CC BY 4.0) · Pattern: drawn in code
// Fonts: Markazi Text, Reem Kufi, Noto Kufi Arabic (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the frame; the novel is Arabic in both editions
const RECIPE = 'arabic-novel-right-bound';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// The blue of the press's door, the brass of its key, ink on a cream book paper.
// #region palette: the door's blue, the key's brass, every colour linked by id
const palette = {
  ink: '#1f1c19', // text: a warm near-black
  door: '#2b4766', // the accent: the part page's field, the openers' kickers
  brass: '#b08d4a', // the second accent: the medallion's line and the openers' star
  lattice: '#3d5d82', // the pattern's lines, a step lighter than the field
  rule: '#cbc3b5', // hairlines
  muted: '#6b645b', // running heads, folios, the colophon
  paper: '#fbf8f1', // a cream book paper
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.door })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const [TEXT, DISPLAY, LABEL] = ['Markazi Text', 'Reem Kufi', 'Noto Kufi Arabic'];
const [BODY, LEAD] = [13.5, 22]; // pt: Naskh sets small, so 13.5 pt on 1.63 × the size
const TRIM = { width: 140, height: 210 }; // mm: 14 × 21 cm, the Arab trade novel
const OUTER = 16; // mm: the outer margin, where the folios stand

// #region answer: the locale sets the direction, the binding and the digits
const page = {
  width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150, backgroundColor: col('paper'),
  // left and right are the flow's sides: in a right-to-left book left is the spine side,
  // so these margins put 20 mm at the spine and 16 mm outside on both pages of a spread.
  margins: { top: mm(23), bottom: mm(22), left: mm(20), right: mm(OUTER), mirror: true },
  // binding: 'auto' (unset) is 'right' for a right-to-left locale: page 1 is a left page.
};
const bodyText = {
  fontFamily: TEXT, fontSize: pt(BODY), lineHeight: pt(LEAD), color: col('ink'),
  boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
  // justify ends every line on both sides; the engine lengthens joined letters (kashida,
  // on by default for Arabic) after it opens the spaces a quarter. Never hyphenated.
  textAlign: 'justify', optimalLineBreaking: true,
  firstLineIndent: em(1.5), indentAfterHeading: false, // the indent is on the right

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#ヨーロッパ数字で刷る

マグリブ版は1、2、3と刷ります。locale: 'ar-MA'だけでそうなり、本全体はマグリブ版で見られます。

-  locale: 'ar', // written out, never LANG (gotcha: arabic-locale-tag)
+  locale: 'ar', numerals: 'latn',

#語間だけで両端をそろえる

本文にタトウィールを使わない出版社もあります。その場合は語間が差をすべて受け持ちます。

   textAlign: 'justify', optimalLineBreaking: true,
+  kashida: 'none',

よくあるつまずき

つまずき

アラビア語の本のタグはLANGではなく'ar'にする

レシピの版は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'です。アラビア語を引用するだけのラテン文字のページは、自分のロケールのままにします。 右から左のテキスト →

つまずき

アラビア語の書体にはarabicブロックを通じてarabicファイルが必要

FontsourceはAmiri、Noto Naskh Arabic、Scheherazade Newをサブセットごとに1ファイルとして配信し、アラビア文字はarabicファイルに入っています。loadFontsが取得するのはlatin(とlatin-ext)だけなので、画面ではアラビア文字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、空の四角が印字されます。キットのarabicブロックを挙げ、loadFontsのあとにloadArabicFonts(FONTS, markdown)を呼び(ページでアラビア文字に使うすべてのウェイトをFONTSに挙げておきます)、renderToPdfにfontProvider: arabicPdfProviderを渡してください。 アラビア語のフォント →

つまずき

右綴じの本の見開きはshowBookで表示する

右綴じの本(アラビア語、ヘブライ語、ペルシア語のテキスト、縦組みの中国語、またはpage.binding 'right')でも1ページは奇数ページですが、背の左側に来て、見開きは[3 | 2]と並びます。showPagesはどの本も左綴じとして並べます。bookブロックのshowBook(cjkブロックにも同じ関数があります)はdoc.bindingを読み、見開きを左右反転します。capture.heroでは、見開きは引き続き読む順の[偶数ページ, 奇数ページ]、つまり[2, 3]と指定します。 右綴じの本 →

つまずき

見出しスタイルはその階層の改ページを受け継ぐ

headingStylesの項目は、指定しなかったフィールドをすべて見出しの階層から受け継ぎ、breakBeforeも例外ではありません。:::pagebreakのあとのH1に付けた目次や奥付のスタイルはparity 'odd'を受け継ぎ、白ページの後ろに置かれます。こうしたスタイルにはbreakBefore: { enabled: false }を指定してください。 見出しスタイル →

  • アラビア語の本の末尾に英語やスペイン語の奥付を置くときは、そのブロックに{dir=ltr}が必要です。これがないと、ラテン文字の行が右から左の段落としてそろえられ、句読点も扱われて、ピリオドが左端に付きます。

クレジット

レシピ
Ignacio Ferro
本文
  • The opening of a novel, حروف من رصاص (Letters of Lead), written in Arabic for the recipe; its author and its people are invented · Postext Cookbook · オリジナル
フォント
Markazi Text (SIL OFL 1.1) · Reem Kufi (SIL OFL 1.1) · Noto Kufi Arabic (SIL OFL 1.1)
SandboxPDF