跳到主要内容
食谱编号150

排版食谱 · 第11章 · 漫画与连环画

斜向格间的动作页

决定剑道决赛胜负的一页:分格里写出倾斜的格间(40~55),击中的一格不加边框,拟声字ドン保留日文,下面附上小号译文。

本页内容
类型
漫画
输出
Canvas · PDF
难度
中级
Postext
已用Postext 1.65.0测试
需要≥ 1.65.0 · postext-pdf ≥ 1.65.0
许可证
更新于2026年10月31日
代码MIT · 文本CC BY 4.0

页码1–1 · 第1–2页,共2页

  • 成品尺寸128 × 182 mm
  • 2栏, 栏间距7.5 mm
  • Zen Antique 9/15
  • 2页
  • 难度
  • Postext 1.65.0
  • 排版用时181 ms
  • 150行代码

简单来说

日本漫画里的一页打斗,格子之间的空隙是斜的,让动作像要冲出去;击中时那个大大的日文拟声字原样保留,旁边加一个小小的译文。

成品一览

这是和从右往左读的示例同一部漫画里决定剑道决赛胜负的一页,两个版本并排:日文原版和本页语言的嵌字(日文页上是英文版)。一共四层:体育馆、面罩后花的眼睛、交锋、众人的反应。第三层被一条倾斜的格间切开,对手的突刺和花的反击仿佛迎面撞在一起;第四层朝反方向倾斜,让页面慢下来。花击中的那一格没有边框,它的拟声字ドン用粗黑的日文黑体,每个版本都保留,译本在下面附上小号译文。

这道食谱解答

  • 怎样让格与格之间的间距倾斜?
  • 怎样在画面上写拟声字?

简短回答

script.js · 第46–64行在完整代码中
// The page is split in content.<lang>.md: `* [40~55 | *]` runs the gutter of the third
// tier from 40 % at the top to 55 % at the bottom, so both panels lean into the strike,
// and `24 [58~64 | *]` tilts the last tier the other way. The panel that lands the blow
// is drawn with `border=none`: no frame, so its speed lines run straight to the gutter.
// ドン keeps its Japanese face in every edition (`font=` on the line);
// the translations add a small subtitle under it, the way licensed manga gloss a drawn
// sound effect instead of redrawing it.
const comics = (lang) => ({
  artDirection: 'rtl', // drawn for right-to-left reading: slants and order mirror with it
  mirrorArt: false,
  gutter: { horizontal: mm(4), vertical: mm(2.5) }, // a slanted gutter keeps its width
  panel: { borderWidth: pt(1.1), borderColor: col('ink'), background: col('paper') },
  lettering: {
    fontFamily: EDITIONS[lang].faces[0], color: col('ink'),
    fontSize: pt(['ja', 'zh'].includes(lang) ? 8.5 : 7.5),
    writingMode: lang === 'zh' ? 'vertical' : 'auto',
  },
  balloonStyles: balloons(),
});

用料

类型
Zen Antique, Dela Gothic One, Comic Neue, Bangers, Noto Sans SC, ZCOOL KuaiLe, Playpen Sans Arabic, Lalezar(SIL OFL 1.1)
素材
  • match-coach.jpg
  • match-eyes.jpg
  • match-final.jpg
  • match-lunge.jpg
  • match-stands.jpg
  • match-strike.jpg
  • The kendo final in a packed gym, two fighters between three referees (Generated With Diffusion Models, 原创)
  • Hana's eyes through her helmet grille (Generated With Diffusion Models, 原创)
  • The opponent lunging with speed lines (Generated With Diffusion Models, 原创)
  • Hana's leaping strike to the helmet (Generated With Diffusion Models, 原创)
  • Sora cheering in the stands (Generated With Diffusion Models, 原创)
  • Coach Mori nodding while the referees raise their flags (Generated With Diffusion Models, 原创)

做法

#1 · 在分格里让格间倾斜

代码见上方的简短回答。尺寸写成40~55,格子的远边就有两个位置:顶端在这一层的40 %,底端在55 %。格子仍是凸多边形,格间沿垂直于倾斜的方向保持同样宽度;从右往左读时,倾斜随顺序一起镜像,所以第一格仍在右边。这一页的分格是24 / 18 / * [40~55 | *] / 24 [58~64 | *]:两层直的铺垫,一层斜的击打,最后一层朝反方向倾斜(分格)。

#2 · 喊叫用爆炸框,拟声字可以冲出格子

script.js · 第68–76行在完整代码中
const balloons = () => [
  { id: 'speech', fill: col('paper'), stroke: col('ink'), strokeWidth: pt(0.6), roundness: 2 },
  { id: 'shout', fill: col('paper'), stroke: col('ink'), burstPoints: 18, burstDepth: 0.3 },
  { id: 'thought', fill: col('paper'), stroke: col('ink') },
  { id: 'inner', fill: col('tone'), stroke: col('tone'), strokeWidth: pt(0), italic: false },
  { id: 'caption', fill: col('paper'), stroke: col('ink'), strokeWidth: pt(0.5) },
  // white-edged on the art
  { id: 'sfx', color: col('ink'), haloColor: col('paper'), halo: pt(2.2) },
];

两名选手的喊声都是喊叫框:18个尖角,比默认的更深。拟声字没有对话框,直接写在画面上,加2.2 pt的白边,压在速度线上也看得清。击中的一格写作::panel{art=strike border=none},它的ドン带着break,可以越过倾斜的格间进入旁边一格,就像嵌字师让声音冲出画框一样(拟声字)。

#3 · 保留日文ドン,加上字幕

script.js · 第301–320行在完整代码中
const SFX = /^sfx(\{[^}\n]*\})?[ \t]*[::](.*)$/gm; // sound effects: the second face sets them
async function loadEdition(lang) {
  const text = TEXT[lang];
  const [face, sfx] = EDITIONS[lang].faces;
  const faces = { [face]: FONTS[face], [sfx]: FONTS[sfx] };
  const effects = [...text.matchAll(SFX)];
  for (const [, attrs = '', words] of effects) { // ドン keeps its face in every language
    const family = /font="([^"]+)"/.exec(attrs)?.[1];
    if (!family) continue;
    faces[family] = FONTS[family];
    await loadCjkFonts({ [family]: FONTS[family] }, words, { vertical: true });
  }
  if (['ja', 'zh'].includes(lang)) { // CJK: only the files that hold these characters
    const own = effects.filter(([, attrs = '']) => !attrs.includes('font=')).map((m) => m[2]);
    await loadCjkFonts({ [face]: FONTS[face] }, text.replace(SFX, ''), { vertical: true });
    await loadCjkFonts({ [sfx]: FONTS[sfx] }, own.join(''), { vertical: true });
  }
  if (lang === 'ar') await loadArabicFonts(faces, text);
  await loadComicFonts(faces, text); // the bold and italic the faces do not ship
}

漫画里的拟声字是画面的一部分,正版译本通常原样保留,在旁边加小号译文。脚本也这样做:每个版本都有sfx{… font="Dela Gothic One" break}: ドン这一行;横排的版本在这一行加上vertical,让ドン保持原作里的竖排,再在下面加一个更小的拟声字,比如WHAM或¡ZAS!。字体写在这一行里,所以无论版本自己的嵌字字体是什么,都只用ドン这两个字载入Dela Gothic One。

#4 · 让安全区适合斜格

script.js · 第188–297行在完整代码中
const ART = { // fractions of the picture: the same in every language
  final: {
    alt: t({ en: 'The kendo final in a packed gym: two fighters cross swords among three referees.',
      es: 'La final en un pabellón lleno: dos rivales cruzan las espadas entre tres árbitros.',
      ca: 'La final en un pavelló ple: dos rivals creuen les espases entre tres àrbitres.',
      fr: 'La finale dans un gymnase comble : deux combattants croisent le sabre entre trois '
        + 'arbitres.',
      de: 'Das Kendo-Finale in einer vollen Halle: Zwei Kämpfer kreuzen zwischen drei '
        + 'Kampfrichtern die Schwerter.',
      it: 'La finale in una palestra gremita: due atleti incrociano le spade tra tre '
        + 'arbitri.',
      pt: 'A final num ginásio lotado: dois lutadores cruzam as espadas entre três árbitros.',
      zh: '座无虚席的体育馆里的决赛:两名选手在三名裁判之间交剑。',
      ar: 'النهائي في صالة ممتلئة: متباريان يتقاطع سيفاهما بين ثلاثة حكّام.',
      ja: '満員の体育館での決勝。3人の審判の間で2人が剣先を交える。' }),
  safeArea: { x: 0.22, y: 0.44, width: 0.56, height: 0.46 },
  anchors: [{ id: 'hana', x: 0.31, y: 0.51, head: { x: 0.31, y: 0.49 },
    face: { x: 0.28, y: 0.45, width: 0.07, height: 0.1 } },
  { id: 'rival', x: 0.68, y: 0.51, head: { x: 0.68, y: 0.49 },
    face: { x: 0.65, y: 0.46, width: 0.06, height: 0.09 } },
  { id: 'shinpan', x: 0.575, y: 0.585, head: { x: 0.575, y: 0.56 },
    face: { x: 0.56, y: 0.54, width: 0.03, height: 0.06 } }] },
  eyes: {
    alt: t({ en: "Hana's eyes through the bars of her helmet grille.",
      es: 'Los ojos de Hana tras las barras de la rejilla del casco.',
      ca: 'Els ulls de la Hana darrere les barres de la reixa del casc.',
      fr: 'Les yeux de Hana derrière les barreaux de la grille de son casque.',
      de: 'Hanas Augen hinter den Gitterstäben ihres Helms.',
      it: 'Gli occhi di Hana dietro le sbarre della grata dell’elmo.',
      pt: 'Os olhos de Hana atrás das barras da grade do capacete.',
      zh: '面罩铁栏后花的眼睛。',
      ar: 'عينا هانا خلف قضبان شبكة الخوذة.',
      ja: '面金の向こうの花の目。' }),
  safeArea: { x: 0.22, y: 0.26, width: 0.57, height: 0.38 },
  anchors: [{ id: 'hana', x: 0.5, y: 0.62, head: { x: 0.5, y: 0.4 },
    face: { x: 0.2, y: 0.3, width: 0.6, height: 0.3 } }] },
  lunge: {
    alt: t({ en: 'The opponent lunges at the viewer, speed lines all round.',
      es: 'El rival se lanza hacia el lector entre líneas cinéticas.',
      ca: 'El rival es llança cap al lector entre línies cinètiques.',
      fr: 'L’adversaire se jette vers le lecteur, entouré de lignes de vitesse.',
      de: 'Der Gegner stürzt auf den Betrachter zu, ringsum Bewegungslinien.',
      it: 'L’avversario si lancia verso chi guarda, tra linee cinetiche.',
      pt: 'O adversário avança contra o leitor entre linhas de velocidade.',
      zh: '对手在速度线中朝读者猛刺过来。',
      ar: 'الخصم يندفع نحو القارئ وسط خطوط السرعة.',
      ja: '集中線の中、こちらへ突いてくる相手。' }),
  safeArea: { x: 0.03, y: 0.01, width: 0.8, height: 0.61 },
  avoid: [{ x: 0.02, y: 0.42, width: 0.23, height: 0.18 }],
  anchors: [{ id: 'rival', x: 0.7, y: 0.2, head: { x: 0.7, y: 0.14 },
    face: { x: 0.63, y: 0.02, width: 0.15, height: 0.24 } }] },
  strike: {
    alt: t({ en: "Hana leaps and strikes the top of the opponent's helmet; the sword bends.",
      es: 'Hana salta y golpea la parte alta del casco del rival; la espada se dobla.',
      ca: 'La Hana salta i colpeja la part alta del casc del rival; l’espasa es doblega.',
      fr: 'Hana bondit et frappe le sommet du casque adverse ; le sabre plie.',
      de: 'Hana springt und trifft den Gegner oben auf den Helm; das Schwert biegt sich.',
      it: 'Hana salta e colpisce la sommità dell’elmo avversario; la spada si piega.',
      pt: 'Hana salta e acerta o alto do capacete do adversário; a espada se curva.',
      zh: '花跃起击中对手面罩顶部,竹剑弯了起来。',
      ar: 'هانا تقفز وتضرب أعلى خوذة الخصم؛ ينثني السيف.',
      ja: '跳び込んで相手の面を打つ花。竹刀がしなる。' }),
  safeArea: { x: 0.36, y: 0.06, width: 0.42, height: 0.77 },
  avoid: [{ x: 0.52, y: 0.48, width: 0.13, height: 0.16 }],
  anchors: [{ id: 'hana', x: 0.43, y: 0.25, head: { x: 0.43, y: 0.18 },
    face: { x: 0.38, y: 0.07, width: 0.1, height: 0.25 } }, { id: 'sfx', x: 0.75, y: 0.25 }] },
  stands: {
    alt: t({ en: 'Sora jumps up in the stands, fists raised, shouting.',
      es: 'Sora salta en la grada con los puños en alto, gritando.',
      ca: 'En Sora salta a la graderia amb els punys enlaire, cridant.',
      fr: 'Sora bondit dans les gradins, poings levés, en criant.',
      de: 'Sora springt auf der Tribüne auf, die Fäuste erhoben, und schreit.',
      it: 'Sora salta sugli spalti con i pugni alzati, gridando.',
      pt: 'Sora pula na arquibancada de punhos erguidos, gritando.',
      zh: '空在看台上跳起来,举着拳头大喊。',
      ar: 'سورا يقفز في المدرّجات رافعًا قبضتيه وهو يصيح.',
      ja: '観客席で拳を突き上げて叫ぶ空。' }),
  safeArea: { x: 0.08, y: 0.07, width: 0.69, height: 0.44 },
  avoid: [{ x: 0.08, y: 0.06, width: 0.12, height: 0.1 },
    { x: 0.64, y: 0.35, width: 0.1, height: 0.12 }],
  anchors: [{ id: 'sora', x: 0.51, y: 0.44, head: { x: 0.5, y: 0.37 },
    face: { x: 0.4, y: 0.3, width: 0.22, height: 0.2 } }] },
  coach: {
    alt: t({ en: 'Mori, arms crossed and eyes closed; behind him the referees raise their flags.',
      es: 'Mori, de brazos cruzados y ojos cerrados; detrás, los árbitros alzan las banderas.',
      ca: 'En Mori, de braços plegats i ulls tancats; darrere, els àrbitres alcen les banderes.',
      fr: 'Mori, bras croisés et yeux fermés ; derrière lui, les arbitres lèvent leurs '
        + 'drapeaux.',
      de: 'Mori, Arme verschränkt, Augen geschlossen; hinter ihm heben die Kampfrichter '
        + 'die Fahnen.',
      it: 'Mori, braccia conserte e occhi chiusi; dietro di lui gli arbitri alzano le '
        + 'bandiere.',
      pt: 'Mori, de braços cruzados e olhos fechados; atrás, os árbitros erguem as bandeiras.',
      zh: '森老师抱着双臂、闭着眼;身后的裁判举起了旗子。',
      ar: 'موري عاقد الذراعين مغمض العينين، وخلفه يرفع الحكّام راياتهم.',
      ja: '腕を組み目を閉じる森先生。後ろで審判が旗を上げる。' }),
  safeArea: { x: 0.16, y: 0.1, width: 0.76, height: 0.53 },
  avoid: [{ x: 0.55, y: 0.18, width: 0.4, height: 0.17 }, // the referees' flags
    { x: 0.22, y: 0.47, width: 0.25, height: 0.21 }], // Mori’s folded arms: his pose
  anchors: [{ id: 'mori', x: 0.29, y: 0.31, head: { x: 0.29, y: 0.2 },
    face: { x: 0.22, y: 0.1, width: 0.14, height: 0.24 } }] },
};
const panels = () => Promise.all([
  comicPanel('final', asset('match-final.jpg'), ART.final),
  comicPanel('eyes', asset('match-eyes.jpg'), ART.eyes),
  comicPanel('lunge', asset('match-lunge.jpg'), ART.lunge),
  comicPanel('strike', asset('match-strike.jpg'), ART.strike),
  comicPanel('coach', asset('match-coach.jpg'), ART.coach),
  comicPanel('stands', asset('match-stands.jpg'), ART.stands),
]);

斜格一端比另一端宽,画面必须把整格盖满。每个安全区只裁到这一格需要的部分:面罩特写只留眼睛,欢呼的一格只留空的上半身。这样它能放进格子最宽的裁切里,引擎就不必在画面四周留白。

#5 · 把原版放在每个版本旁边

script.js · 第325–335行在完整代码中
const FACING = LANG === 'ja' ? 'en' : LANG; // Japanese readers see the English edition
const TEXT = { ja: original, [FACING]: LANG === 'ja' ? english : markdown };
await loadFonts(FONTS, Object.values(TEXT).join('\n'));
const resources = await panels();
const build = async (lang) => { // the same pictures and page; this language's lettering
  await loadEdition(lang);
  return withLoadedFonts(() => buildDocument({ markdown: TEXT[lang], resources,
    continuation: { pageIndexOffset: lang === 'ja' ? 1 : 2 } }, edition(lang)),
    { ...kitFonts(FONTS), text: TEXT[lang] });
};
const docs = [await build('ja'), await build(FACING)];

本站的每种语言都在自己的文件里为这一页嵌字,日文原版放在跨页的另一边与它相对(日文页对着英文版)。ドン在每个版本里都保留,各版本带来自己的字幕(咚、WHAM、ZAS!、PÁ!、PAF !、WUMM、SDENG!、بوم!),倾斜也不会变。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 150 · An action page with slanted gutters ═════════════════
// https://postext.dev/en/cookbook/manga-action-slants
// Code: MIT · Story: written for the recipe (CC BY 4.0) · Pictures: generated with diffusion models
// Fonts: Zen Antique, Comic Neue and six more (SIL OFL 1.1) · Needs postext ≥ 1.65.0
// The last page of a kendo final: slanted panels, a borderless strike, ドン kept in every edition.
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage, loadVerticalAlternates,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'zh'; // @lang: this edition's language; the Japanese original faces it
const RECIPE = 'manga-action-slants';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: black ink on a warm white, one screen-tone grey
const palette = {
  ink: '#151413', // panel borders, balloon outlines, the lettering
  paper: '#fdfcf9', // the page and the balloons
  tone: '#e8e6e1', // the inner-voice box, a light screen tone
  muted: '#6f6b64',
  accent: '#a8322b', // the cover red (the Folio case in recipe.json)
};
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: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion

// The engine's lettering and sound-effect faces per language (defaultComicFont and
// defaultComicSfxFont), written out so FONTS and the PDF know them.
const EDITIONS = {
  ja: { locale: 'ja', faces: ['Zen Antique', 'Dela Gothic One'] },
  en: { locale: 'en-us', faces: ['Comic Neue', 'Bangers'] },
  es: { locale: 'es', faces: ['Comic Neue', 'Bangers'] },
  ca: { locale: 'ca', faces: ['Comic Neue', 'Bangers'] },
  pt: { locale: 'pt-BR', faces: ['Comic Neue', 'Bangers'] },
  fr: { locale: 'fr', faces: ['Comic Neue', 'Bangers'] },
  de: { locale: 'de', faces: ['Comic Neue', 'Bangers'] },
  it: { locale: 'it', faces: ['Comic Neue', 'Bangers'] },
  zh: { locale: 'zh-Hans', faces: ['Noto Sans SC', 'ZCOOL KuaiLe'] },
  ar: { locale: 'ar', faces: ['Playpen Sans Arabic', 'Lalezar'] },
};

// #region answer: the slant is in the split; the impact is in the panel and the effect
// The page is split in content.<lang>.md: `* [40~55 | *]` runs the gutter of the third
// tier from 40 % at the top to 55 % at the bottom, so both panels lean into the strike,
// and `24 [58~64 | *]` tilts the last tier the other way. The panel that lands the blow

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

常见问题

易错点

日文文本标记为'ja',不要用zh-Hans或LANG

食谱的版本是en和es,但日文示例在两个版本里都是日文:`locale: LANG`会把它标记为英文或西班牙文,中文标记则会按中文规则排它(开明式标点、小假名可以出现在行首、图代替図、PDF中用中文字形)。postext 1.30起,这个标记也是文字成形所用的语言(测量、绘制和嵌入都按它进行),所以'ja'以外的标记给出的不是日文字形(中文标记给出中文字形),断行的位置也不同。写'ja':它选用日本地区(JLReq断行和标点、芝麻着重号、振假名的分布、図和表标签),并关闭断词。lint会让带假名却标记为zh或ko的文本失败。 日文禁则处理 →

易错点

中文字体通过cjk块分片加载

Fontsource把一个中文、日文或韩文字体家族按每个字重约一百个文件提供,每个文件覆盖一段字符范围。loadFonts只获取latin文件,所以屏幕上的汉字来自系统字体,测量不准;fontsourceProvider交给PDF的也是这个latin文件,汉字印出来是空框。列出kit中的cjk块,在loadFonts之后调用loadCjkFonts(FONTS, markdown)(书中用到几种CJK字体时,每种字体调用一次,并传入它所排的文字),并给renderToPdf传fontProvider: cjkPdfProvider:两者都会取用包含文中字符的那些文件。 中日韩字体 →

  • 横排版本里保留日文的拟声字,除非这一行写了vertical,否则会像版本里的其他文字一样横排。
  • 空的欢呼在日文、西班牙文和加泰罗尼亚文里比他那一小格长:交给引擎时它越过了边框,构建时警告comicBalloonOverflow。这几个版本给它加上break(sora{shout break}),让它有意向上冲出画框,伸进格间距和上面那一格,引擎不再警告。带break的对话框不会冲进页边,除非它所在的格子出血;要放到别处,就用at=固定。

致谢

文本
  • 決勝 (The Final), a one-page kendo manga written for this recipe, with its English, Spanish, Catalan, Chinese and Arabic letterings · Postext Cookbook · CC BY 4.0
图片
  • The kendo final in a packed gym, two fighters between three referees · Generated With Diffusion Models · 原创
  • Hana's eyes through her helmet grille · Generated With Diffusion Models · 原创
  • The opponent lunging with speed lines · Generated With Diffusion Models · 原创
  • Hana's leaping strike to the helmet · Generated With Diffusion Models · 原创
  • Sora cheering in the stands · Generated With Diffusion Models · 原创
  • Coach Mori nodding while the referees raise their flags · Generated With Diffusion Models · 原创
字体
Zen Antique (SIL OFL 1.1) · Dela Gothic One (SIL OFL 1.1) · Comic Neue (SIL OFL 1.1) · Bangers (SIL OFL 1.1) · Noto Sans SC (SIL OFL 1.1) · ZCOOL KuaiLe (SIL OFL 1.1) · Playpen Sans Arabic (SIL OFL 1.1) · Lalezar (SIL OFL 1.1)
沙盒PDF