跳到主要内容
食谱编号145

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

灯塔一页里的各种对话框

一页漫画用上对白、心想、耳语、大喊、无线电、旁白框、内心独白、编者注和拟声词,每一种都在脚本行的花括号里写明。

本页内容
类型
漫画
输出
Canvas · PDF
难度
中级
Postext
已用Postext 1.65.0测试
需要≥ 1.28.0 · postext-pdf ≥ 1.28.0
许可证
更新于2026年10月11日
代码MIT · 文本CC BY 4.0
  • 成品尺寸168 × 259 mm
  • 1栏
  • ZCOOL KuaiLe 9.5/13.5
  • ZCOOL QingKe HuangYou
  • 2页
  • 难度
  • Postext 1.65.0
  • 排版用时613 ms
  • 142行代码

简单来说

一页讲暴风雨夜救援的漫画,用上了所有种类的对话框,前面附一张嵌字样式表,说明每一种在脚本里怎么写。

成品一览

《珀斯科夫灯塔》第7页,一部讲灯塔暴风雨之夜的漫画,前面附上嵌字师的样式表。一艘渔船发动机熄火,守塔人用无线电指引它,玛雅抱着猫等着,第二天早上船长来道谢。这一页用上了 Postext 能画的所有对话框:对白、相连的对白、心想、耳语、大喊、无线电、叙述旁白框、内心独白、编者注、拟声词、画外音和固定位置的对话框。开本是美式漫画书的 168 × 259 mm,这一页有十种语言的版本。

这道食谱解答

  • 怎样区分想法、耳语、喊叫和无线电的对话框?
  • 怎样让对话框的尾巴指向说话的人物?
  • 怎样在画面上写拟声字?
  • 怎样用Markdown写对话框?

简短回答

script.js · 第46–71行在完整代码中
// A script line is `speaker{kind}: text`. The kinds are balloon styles: the engine ships
// speech, thought, whisper, shout, radio, caption, inner, note and sfx, and a style of the
// same id here changes only what it names. `caption`, `note` and `sfx` are reserved speakers.
const balloonStyles = [
  { id: 'speech', stroke: col('ink') }, // an oval, a curved tail to the mouth
  { id: 'thought', stroke: col('ink') }, // a cloud, bubbles to the head
  { id: 'whisper', stroke: col('ink') }, // a dashed outline, 0.9 × the type
  { id: 'shout', stroke: col('ink'), burstPoints: 16 }, // a burst, bold, 1.15 × the type
  { id: 'radio', stroke: col('ink') }, // a zig-zag outline and tail: a voice through a set
  { id: 'caption', fill: col('caption'), stroke: col('ink') }, // narration, butted to a corner
  { id: 'inner', fill: col('inner'), stroke: col('ink') }, // no tail, italic where it can be
  { id: 'note', fill: col('paper'), stroke: col('ink') }, // the editor's note, 0.8 × the type
  { id: 'sfx', fontFamily: SFX, color: col('accent'), haloColor: col('paper') }, // no balloon
];
const comics = {
  gutter: { horizontal: mm(4), vertical: mm(3) },
  panel: { borderWidth: pt(1), borderColor: col('ink'), background: col('paper') },
  lettering: { fontFamily: LETTERING, fontSize: pt(7.5), color: col('ink'), inset: mm(1) },
  balloonStyles,
  // A speaker's own style: every `skipper:` line comes through the radio unless it says not.
  cast: [{ id: 'skipper', balloonStyle: 'radio', name: t({ en: 'The skipper', es: 'El patrón',
    ca: 'El patró', zh: '船长', ar: 'الربّان', ja: '船長', pt: 'O capitão', fr: 'Le patron',
    de: 'Der Kapitän',
    it: 'Il capitano' }) }],
  runningHeads: true, // a comic page has no running head unless asked: here, its folio
};

用料

类型
Comic Neue, Bangers, Zen Antique, Dela Gothic One, ZCOOL KuaiLe, ZCOOL QingKe HuangYou, Playpen Sans Arabic, Lalezar(SIL OFL 1.1)
素材
  • bk-morning.jpg
  • bk-sea.jpg
  • bk-shout.jpg
  • bk-storm.jpg
  • bk-whisper.jpg
  • bk-window.jpg
  • Panel picture: the storm in the lamp room (Generated With Diffusion Models, 原创)
  • Panel picture: Maya and the cat under the desk (Generated With Diffusion Models, 原创)
  • Panel picture: the keeper shouting into the microphone (Generated With Diffusion Models, 原创)
  • Panel picture: the trawler in the storm (Generated With Diffusion Models, 原创)
  • Panel picture: Maya at the window (Generated With Diffusion Models, 原创)
  • Panel picture: the next morning on the rocks (Generated With Diffusion Models, 原创)

做法

#1 · 在脚本行里写明类型

代码就是上面的简短回答。脚本的一行写成 说话人{类型}: 台词,类型就是对话框样式的标识。九种内置样式涵盖常见的类型:对白是椭圆加弯尾巴,心想是云朵加小泡泡,耳语是虚线轮廓,大喊是带楔形尾巴的爆炸框,经过无线电的声音是锯齿轮廓加锯齿尾巴(对白框样式)。配置里同一标识的样式只改它写到的部分:这里改的是描边颜色、旁白框的黄色和爆炸框的 16 个尖角。caption、note 和 sfx 是保留的说话人:贴在角上的旁白框、0.8 倍字号的编者注,以及没有对话框的大字。

无线电通话:旁白框、船长指向电台的无线电对话框、守塔人的回答和编者注。

#2 · 让每条尾巴指向说话人

script.js · 第164–297行在完整代码中
// From the art manifest; fractions of each picture, the same in every language. `skipper` in
// the storm picture is the radio set, the voice's source; in the sea picture, his boat.
const ART = {
  'bk-storm': { width: 1100, height: 733, safeArea: { x: 0.05, y: 0.26, width: 0.52, height: 0.36 },
    anchors: [{ id: 'tomas', x: 0.3, y: 0.44, head: { x: 0.32, y: 0.33 },
      face: { x: 0.26, y: 0.29, width: 0.13, height: 0.21 } },
    { id: 'maya', x: 0.475, y: 0.47, head: { x: 0.48, y: 0.38 },
      face: { x: 0.43, y: 0.35, width: 0.09, height: 0.16 } },
    { id: 'skipper', x: 0.08, y: 0.52 }],
    avoid: [{ x: 0, y: 0.38, width: 0.18, height: 0.28 }],
    alt: t({ en: 'Storm at night in the lamp room: the keeper speaks into the radio microphone '
      + 'while Maya, wrapped in a blanket, listens.',
      es: 'Noche de tormenta en la sala de la linterna: el farero habla por el micrófono de la '
        + 'radio y Maya, envuelta en una manta, escucha.',
      ca: 'Nit de tempesta a la sala de la llanterna: el faroner parla pel micròfon de la ràdio i '
        + 'la Maya, embolicada amb una manta, escolta.',
      zh: '暴风雨之夜的灯室里,守塔人对着收音机的话筒说话,裹着毯子的玛雅在一旁听着。',
      ar: 'ليلة عاصفة في غرفة الفانوس: الحارس يتكلم في ميكروفون المذياع، ومايا الملتفّة ببطانية '
        + 'تصغي.',
      ja: '嵐の夜の灯室。灯台守が無線のマイクに話しかけ、毛布にくるまったマヤが耳をすます。',
      pt: 'Noite de tempestade na sala da lanterna: o faroleiro fala ao microfone do rádio e '
        + 'Maya, enrolada num cobertor, escuta.',
      fr: 'Nuit de tempête dans la chambre de la lanterne : le gardien parle dans le micro de '
        + 'la radio pendant que Maya, emmitouflée dans une couverture, écoute.',
      de: 'Sturmnacht im Laternenraum: Der Wärter spricht ins Mikrofon des Funkgeräts, während '
        + 'Maya, in eine Decke gewickelt, zuhört.',
      it: 'Notte di tempesta nella stanza della lanterna: il guardiano parla al microfono della '
        + 'radio e Maya, avvolta in una coperta, ascolta.' }) },
  'bk-whisper': { width: 1152, height: 1152,
    safeArea: { x: 0.36, y: 0.26, width: 0.44, height: 0.48 },
    anchors: [{ id: 'maya', x: 0.53, y: 0.47, head: { x: 0.52, y: 0.33 },
      face: { x: 0.41, y: 0.3, width: 0.19, height: 0.22 } },
    { id: 'biscuit', x: 0.625, y: 0.635, head: { x: 0.66, y: 0.57 },
      face: { x: 0.55, y: 0.5, width: 0.25, height: 0.22 } }],
    avoid: [],
    alt: t({ en: 'Under the desk, Maya whispers behind her hand to the frightened orange cat.',
      es: 'Bajo la mesa, Maya le susurra tapándose la boca al gato naranja asustado.',
      ca: 'Sota la taula, la Maya xiuxiueja tapant-se la boca al gat taronja espantat.',
      zh: '桌子底下,玛雅用手挡着嘴,对受惊的橘猫说悄悄话。',
      ar: 'تحت المكتب تهمس مايا من وراء يدها للقط البرتقالي الخائف.',
      ja: '机の下で、マヤが手で口をかくして、おびえたオレンジ色の猫にささやく。',
      pt: 'Debaixo da mesa, Maya cobre a boca com a mão e sussurra para o gato laranja '
        + 'assustado.',
      fr: 'Sous le bureau, Maya chuchote derrière sa main au chat roux effrayé.',
      de: 'Unter dem Schreibtisch flüstert Maya hinter vorgehaltener Hand der verängstigten '
        + 'roten Katze zu.',
      it: 'Sotto la scrivania, Maya sussurra dietro la mano al gatto rosso spaventato.' }) },
  'bk-shout': { width: 880, height: 1100, safeArea: { x: 0.22, y: 0.26, width: 0.46, height: 0.42 },
    anchors: [{ id: 'tomas', x: 0.48, y: 0.47, head: { x: 0.42, y: 0.33 },
      face: { x: 0.25, y: 0.28, width: 0.37, height: 0.32 } }],
    avoid: [{ x: 0.53, y: 0.43, width: 0.17, height: 0.27 }],
    alt: t({ en: 'Close-up of the keeper shouting into the microphone, lit from below by the '
      + 'radio dials.',
      es: 'Primer plano del farero gritando al micrófono, iluminado desde abajo por los diales de '
        + 'la radio.',
      ca: 'Primer pla del faroner cridant al micròfon, il·luminat des de baix pels dials de la '
        + 'ràdio.',
      zh: '守塔人对着话筒大喊的特写,收音机的刻度盘从下方照亮他的脸。',
      ar: 'لقطة قريبة للحارس يصرخ في الميكروفون، وأضواء لوحة المذياع تنيره من أسفل.',
      ja: 'マイクに向かって叫ぶ灯台守のアップ。無線機の目盛りの光が下から顔を照らす。',
      pt: 'Close do faroleiro gritando ao microfone, iluminado de baixo pelos mostradores do '
        + 'rádio.',
      fr: 'Gros plan sur le gardien qui crie dans le micro, éclairé par en dessous par les '
        + 'cadrans de la radio.',
      de: 'Nahaufnahme des Wärters, der ins Mikrofon schreit, von unten von den Skalen des '
        + 'Funkgeräts beleuchtet.',
      it: 'Primo piano del guardiano che grida nel microfono, illuminato dal basso dai '
        + 'quadranti della radio.' }) },
  'bk-sea': { width: 1200, height: 800, safeArea: { x: 0.1, y: 0.19, width: 0.37, height: 0.57 },
    anchors: [{ id: 'skipper', x: 0.28, y: 0.63 }, { id: 'sfx', x: 0.16, y: 0.36 }],
    avoid: [{ x: 0.13, y: 0.52, width: 0.24, height: 0.23 },
      { x: 0.85, y: 0.19, width: 0.08, height: 0.26 }],
    alt: t({ en: 'A small blue trawler heaves on storm waves at night; lightning on the left, the '
      + 'lighthouse beam on the right.',
      es: 'Un pesquero azul cabecea entre las olas de la tormenta; un rayo a la izquierda, el haz '
        + 'del faro a la derecha.',
      ca: 'Un pesquer blau capcineja entre les onades de la tempesta; un llamp a l’esquerra, el '
        + 'feix del far a la dreta.',
      zh: '夜里,一艘蓝色小渔船在暴风雨的浪头上颠簸;左边是闪电,右边是灯塔的光束。',
      ar: 'قارب صيد أزرق صغير يتقاذفه موج العاصفة ليلًا؛ برق على اليسار وشعاع المنارة على اليمين.',
      ja: '夜の嵐の波にもまれる青い小さな漁船。左に稲妻、右に灯台の光。',
      pt: 'Um pequeno barco pesqueiro azul jogado pelas ondas da tempestade à noite; um raio à '
        + 'esquerda, o facho do farol à direita.',
      fr: 'Un petit chalutier bleu tangue la nuit sur les vagues de la tempête ; un éclair à '
        + 'gauche, le faisceau du phare à droite.',
      de: 'Ein kleiner blauer Kutter schlingert nachts in den Wellen des Sturms; links ein '
        + 'Blitz, rechts der Strahl des Leuchtturms.',
      it: 'Un piccolo peschereccio blu sballottato di notte dalle onde della tempesta; un lampo a '
        + 'sinistra, il fascio del faro a destra.' }) },
  'bk-window': { width: 1000, height: 1000,
    safeArea: { x: 0.36, y: 0.27, width: 0.28, height: 0.33 },
    anchors: [{ id: 'maya', x: 0.49, y: 0.41, head: { x: 0.42, y: 0.3 },
      face: { x: 0.41, y: 0.33, width: 0.1, height: 0.13 } }],
    avoid: [{ x: 0.5, y: 0.33, width: 0.1, height: 0.17 },
      { x: 0.83, y: 0.45, width: 0.06, height: 0.08 }],
    alt: t({ en: 'Maya presses her hands and nose to the rainy window, staring out at the storm.',
      es: 'Maya pega las manos y la nariz al cristal mojado y mira la tormenta.',
      ca: 'La Maya enganxa les mans i el nas al vidre mullat i mira la tempesta.',
      zh: '玛雅把双手和鼻子贴在满是雨水的窗户上,望着外面的暴风雨。',
      ar: 'تلصق مايا يديها وأنفها بالزجاج المبلل وتحدّق في العاصفة.',
      ja: 'マヤが雨の窓に両手と鼻を押しつけ、嵐を見つめる。',
      pt: 'Maya cola as mãos e o nariz no vidro molhado e olha a tempestade.',
      fr: 'Maya colle les mains et le nez contre la vitre mouillée et regarde la tempête.',
      de: 'Maya drückt Hände und Nase gegen das regennasse Fenster und starrt hinaus in den '
        + 'Sturm.',
      it: 'Maya preme le mani e il naso contro il vetro bagnato e guarda la tempesta.' }) },
  'bk-morning': { width: 1000, height: 667,
    safeArea: { x: 0.33, y: 0.06, width: 0.42, height: 0.59 },
    anchors: [{ id: 'tomas', x: 0.565, y: 0.25, head: { x: 0.56, y: 0.15 },
      face: { x: 0.51, y: 0.13, width: 0.1, height: 0.17 } },
    { id: 'maya', x: 0.465, y: 0.29, head: { x: 0.45, y: 0.24 },
      face: { x: 0.41, y: 0.19, width: 0.09, height: 0.14 } },
    { id: 'biscuit', x: 0.685, y: 0.58, head: { x: 0.69, y: 0.55 },
      face: { x: 0.64, y: 0.51, width: 0.09, height: 0.11 } }],
    avoid: [{ x: 0.66, y: 0.08, width: 0.08, height: 0.12 },
      { x: 0.34, y: 0.14, width: 0.06, height: 0.08 }],
    alt: t({ en: 'Next morning on the sunny rocks, Maya, the keeper and the cat wave; the '
      + 'lighthouse stands behind them.',
      es: 'A la mañana siguiente, en las rocas al sol, Maya, el farero y el gato saludan; detrás '
        + 'está el faro.',
      ca: 'L’endemà al matí, a les roques al sol, la Maya, el faroner i el gat saluden; darrere '
        + 'hi ha el far.',
      zh: '第二天早上,阳光照着礁石,玛雅、守塔人和猫在挥手;灯塔立在他们身后。',
      ar: 'في الصباح التالي على الصخور المشمسة يلوّح مايا والحارس والقط، والمنارة خلفهم.',
      ja: '翌朝、日の当たる岩の上でマヤと灯台守と猫が手を振る。後ろに灯台が立つ。',
      pt: 'Na manhã seguinte, nas pedras ao sol, Maya, o faroleiro e o gato acenam; atrás deles '
        + 'está o farol.',
      fr: 'Le lendemain matin, sur les rochers au soleil, Maya, le gardien et le chat font signe '
        + 'de la main ; le phare se dresse derrière eux.',
      de: 'Am nächsten Morgen winken Maya, der Wärter und die Katze auf den sonnigen Felsen; '
        + 'hinter ihnen steht der Leuchtturm.',
      it: 'La mattina dopo, sugli scogli al sole, Maya, il guardiano e il gatto salutano con la '
        + 'mano; alle loro spalle si alza il faro.' }) },
};

每幅画面都按比例标出锚点:对白尾巴指向的嘴、心想指向的头,以及任何对话框都不能盖住的脸(说话人与锚点)。船长从没出现在画面里:在暴风雨那幅里,他的锚点是电台;在海上那幅里,是他的船。说话人不在这一格里时,tail=right(或 left、top、bottom)让尾巴伸到那一边;at="44% 22%" 把对话框的中心固定在画面的一个点上,不管怎么裁切都不变。同一个人连续两行会合成一个轮廓,只有一条尾巴。left 和 right 说的是画面的左右两侧,所以十个语言版本里,海面那一格守塔人的台词写的是同一行:tail=right,因为灯光在画面右边,页面从左往右读还是从右往左读都一样。start 和 end 则跟着页面的阅读方向走。

#3 · 给角色专属的声音

简短回答里的角色表让每一行 skipper: 都用无线电样式,脚本就不用一再写 {radio}。某一行也可以另作规定:早上那一格里,船长在船上喊话,写成 skipper{speech tail=bottom}:,是普通对话框,尾巴从格子底边伸出去。

#4 · 每个版本用自己的字体嵌字

script.js · 第35–42行在完整代码中
// The engine's default lettering and sound-effect faces, but for Chinese two ZCOOL faces drawn
// for cartoons. content.<lang>.md holds the words under the same speaker ids.
const [LETTERING, SFX] = t({
  en: ['Comic Neue', 'Bangers'], es: ['Comic Neue', 'Bangers'], ca: ['Comic Neue', 'Bangers'],
  ja: ['Zen Antique', 'Dela Gothic One'], zh: ['ZCOOL KuaiLe', 'ZCOOL QingKe HuangYou'],
  ar: ['Playpen Sans Arabic', 'Lalezar'], pt: ['Comic Neue', 'Bangers'],
  fr: ['Comic Neue', 'Bangers'], de: ['Comic Neue', 'Bangers'], it: ['Comic Neue', 'Bangers'],
});

同一页有十种语言:content.<lang>.md 只放台词。日文对话框用 Zen Antique 竖排,拟声词用 Dela Gothic One;阿拉伯文用 Playpen Sans Arabic,雷声用 Lalezar。中文版用站酷快乐体和站酷庆科黄油体。斜体和粗体只在字体有的时候才用:内心独白在英文里是斜体,在中文和日文里是正体(嵌字)。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 145 · Every kind of balloon on a lighthouse page ═════════
// https://postext.dev/en/cookbook/balloon-kinds
// Code: MIT · Text: original (CC BY 4.0) · Pictures: generated with diffusion models
// Fonts: Comic Neue, Bangers and the faces of five editions (OFL) · Needs postext ≥ 1.28.0
//
// One comic page that uses every kind of balloon the engine draws, with a letterer's style
// sheet in front of it. Each line of the script names its speaker and, when it is not plain
// speech, its kind; the shape, the tail and the type follow from the balloon style.
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage, loadVerticalAlternates,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'zh'; // @lang: 'en' | 'es' | 'ca' | 'zh' | 'ar' | 'ja' | 'pt' | 'fr' | 'de' | 'it'
const RECIPE = 'balloon-kinds';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: a storm at night, and the yellow of the captions
const palette = {
  ink: '#18202b', // panel borders, lettering and text: a blue-black
  accent: '#c2412d', // sound effects and the style sheet's labels
  caption: '#f3e3a8', // narration boxes
  inner: '#e4e8ee', // the inner voice: a cold grey-blue
  muted: '#5c6672', // folios and the imprint
  paper: '#fdfbf6',
};
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

// #region editions: six editions, each lettered in faces for its script
// The engine's default lettering and sound-effect faces, but for Chinese two ZCOOL faces drawn
// for cartoons. content.<lang>.md holds the words under the same speaker ids.
const [LETTERING, SFX] = t({
  en: ['Comic Neue', 'Bangers'], es: ['Comic Neue', 'Bangers'], ca: ['Comic Neue', 'Bangers'],
  ja: ['Zen Antique', 'Dela Gothic One'], zh: ['ZCOOL KuaiLe', 'ZCOOL QingKe HuangYou'],
  ar: ['Playpen Sans Arabic', 'Lalezar'], pt: ['Comic Neue', 'Bangers'],
  fr: ['Comic Neue', 'Bangers'], de: ['Comic Neue', 'Bangers'], it: ['Comic Neue', 'Bangers'],
});
// #endregion

// #region answer: one balloon style per kind, and a cast that gives the skipper his radio
// A script line is `speaker{kind}: text`. The kinds are balloon styles: the engine ships
// speech, thought, whisper, shout, radio, caption, inner, note and sfx, and a style of the
// same id here changes only what it names. `caption`, `note` and `sfx` are reserved speakers.

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

变化

#用波浪形对话框表示虚弱的声音

任何其他标识都会成为新样式,以对白样式为基础。

 const balloonStyles = [
+  { id: 'weak', shape: 'wavy', stroke: col('ink'), fontScale: 0.9 }, // maya{weak}: …
   { id: 'speech', stroke: col('ink') },

#用细颈连接两句

-  lettering: { fontFamily: LETTERING, fontSize: pt(7.5), color: col('ink'), inset: mm(1) },
+  lettering: { fontFamily: LETTERING, fontSize: pt(7.5), color: col('ink'), inset: mm(1),
+    joinSameSpeaker: 'connector' },

常见问题

  • 固定位置是画面上的一个点,不管怎么裁切都不变。固定得太靠边、会跑出格子的拟声词(at="16% 28%" 的“轰隆隆”)会被推回格子里,所以可能和写下的位置稍有偏差。
  • 画外的声音排在它尾巴所指的那条边旁边:船长的道谢写了 tail=bottom,所以排在早晨那一格的底部,尽管它是这一格的第一句。如果这样的一句必须先读,就让尾巴指向上边。

致谢

文本
原创文字, CC BY 4.0
图片
  • Panel picture: the storm in the lamp room · Generated With Diffusion Models · 原创
  • Panel picture: Maya and the cat under the desk · Generated With Diffusion Models · 原创
  • Panel picture: the keeper shouting into the microphone · Generated With Diffusion Models · 原创
  • Panel picture: the trawler in the storm · Generated With Diffusion Models · 原创
  • Panel picture: Maya at the window · Generated With Diffusion Models · 原创
  • Panel picture: the next morning on the rocks · Generated With Diffusion Models · 原创
字体
Comic Neue (SIL OFL 1.1) · Bangers (SIL OFL 1.1) · Zen Antique (SIL OFL 1.1) · Dela Gothic One (SIL OFL 1.1) · ZCOOL KuaiLe (SIL OFL 1.1) · ZCOOL QingKe HuangYou (SIL OFL 1.1) · Playpen Sans Arabic (SIL OFL 1.1) · Lalezar (SIL OFL 1.1)
沙盒PDF